iOS - Full OAuth

Under the full OAuth, SDK handles the entire OAuth process, requiring your app to only establish the necessary connections between the SDK and iOS.

Prerequisites

OAuth authentication

Clover uses OAuth to authenticate the users of your app to Clover servers. Use the steps in this topic to:

  • Create a Clover app and install it on your test merchant to enable OAuth. The Clover app has an associated App ID and App Secret that Clover transfers to the iOS app to give it permission to perform OAuth.
  • Use Associated Domains in the iOS app and an apple-app-site-association file on a server you control to enable OAuth callbacks from Clover login servers to your app.

Steps

  1. Add a token change callback using theCloverPaymentSDK.shared.addOnTokenChangeCallback.
  2. Initialize the SDK by calling CloverPaymentSDK.shared.setup and passing in your configuration object. Include a CloverPaymentSDK.FullOAuth object in the configuration for full OAuth support.
  3. CloverPaymentSDK attempts to recover a valid token stored securely in the Keychain. If a valid token is found, it completes initialization and calls your success callback registered in step 2.
  4. If no valid token is found, CloverPaymentSDK initiates OAuth login using the device's default browser. This opens the login page in your configured environment for the user to log in. Identifying information from your configuration is passed to ensure your app can log in for the merchant and employee.
  5. Upon successful login, a code is provided via a callback to your registered associated domain. This returns to your app using the scene delegate or another appropriate path. Refer to Apple documentation for options. Pass the full URL containing the code back to your handler using CloverPaymentSDK.shared.receivedOAuthCodeOrToken.
  6. CloverPaymentSDK exchanges the code for a token, stores the token in the Keychain for the next launch, and then calls your token change callback registered in step 1. In your callback, call CloverPaymentSDK.shared.setup to retry initialization with the valid token.

iOS - Full OAuth flow

iOS - Full OAuth flow


When you use full OAuth

The following are the advantages and disadvantages when you use full OAuth:

Advantages

  • The SDK manages refresh tokens to ensure you always have a usable token.
  • The SDK opens an external browser with the Clover login page.

Disadvantages

  • Monitor incoming URLs in your Scene Delegate and pass them to the SDK. After a successful login, the URL contains the code used to obtain the auth token.
  • Branding the login screen is not possible.
  • The app exits to the default browser for login and then returns using the redirect URL and your app links definition.