iOS - Partial OAuth

Use Partial OAuth to perform the OAuth login flow in your app while allowing the SDK to manage refresh tokens.

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

First launch

  1. In your app, implement the OAuth Login Flow by following the flows defined at Clover OAuth Documentation.
    1. Use the Low Trust Apps flow defined at OAuth Flow for Low Trust Apps (PKCE). This flow is specifically for mobile apps where the app secret cannot be kept secret due to the nature of distributed app binaries.
      Note: Use the CloverPaymentSDK.OAuthCodeChallenge object to facilitate the PKCE flow by generating the verifier and challenge objects for use in the flow.
    2. Obtain the Code response and pass that information to the SDK.
  2. Initialize the SDK by calling CloverPaymentSDK.shared.setup and passing in your configuration object. Include a CloverPaymentSDK.PartialOAuth object in the configuration. In the PartialOAuth object, include the Code received from the OAuth Login flow and the Challenge information used with the PKCE flow.
  3. CloverPaymentSDK exchanges the code for a token, stores the token in Keychain for the next launch, and then calls your token change callback registered in step 1.

Subsequent launches

Initialize the SDK by calling CloverPaymentSDK.shared.setup and passing in your configuration object. Include a CloverPaymentSDK.PartialOAuth object in the configuration. In the PartialOAuth object, set the code to nil to signal to the SDK to use the previously stored token.

iOS - Partial OAuth

iOS - Partial OAuth

When you use partial OAuth

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

Advantages

  • The SDK manages refresh tokens, ensuring you always have a usable token.
  • You can present the Clover login screen directly in your app using your preferred UI design.
  • You can implement the OAuth login flow without exiting the app.

Disadvantages

  • You must write your web view implementation to execute the OAuth login flow.
  • You must monitor and intercept the code response from the OAuth login flow in your app.
  • The implementation in your code will be more complex than the Full OAuth flow.