OAuth2AuthenticationStep

open class OAuth2AuthenticationStep : OnboardingStep

OAuth 2.0 onboarding step.

Used in the onboarding / restoring flow, this step is responsible to configure the app’s URLSession to be able to communicate with OAuth 2.0 protected resources. Creates and registers the OAuth2Observer to the SAPURLSession, then sends a validation request which will trigger an authentication flow.

Customization

During the onboarding flow, if there is a splash screen which shows a text, that text can be changed/localized. The presented webView will also have localizable components, but the localization of downloaded data depends on the server and is not customizable from the created client application.

func customOauth2AuthStep() -> OnboardingStep {
   let oauth2Bundle = Bundle(for: OAuth2AuthenticationStep.self)

   let localizedInfoScreenText = NSLocalizedString("Oauth2InfoScreenText", tableName: "Example Table name", bundle: oauth2Bundle, value: "Validating OAuth2 credentials", comment: "")
   let localizedCancelButtonText = NSLocalizedString("CancelButtonText", tableName: "Example Table name", bundle: oauth2Bundle, value: "Cancel", comment: "")

   let presenter = FioriWKWebViewPresenter()
   presenter.webViewControllerConfigurationHandler = { webView in
       webView.cancelButton?.title = localizedCancelButtonText

       return webView
   }

   let step = OAuth2AuthenticationStep(presenter: presenter)
   step.infoScreenText = localizedInfoScreenText

   return step
}
  • This function resets the modifications of the OAuth2AuthenticationStep in the SAPURLSession.

    Declaration

    Swift

    open func reset(sapURLSession: SAPURLSession, completionHandler: @escaping () -> Void)

    Parameters

    sapURLSession

    SAPURLSession

    completionHandler

    called when the process finished.

  • Onboard function for OAuth2 authorization code grant

    Declaration

    Swift

    open func onboard(authenticationURL: URL, authenticationParameters: OAuth2AuthenticationParameters, sapURLSession: SAPURLSession, credentialStore: CodableStoring, presentationDelegate: FlowPresentationDelegate, settingsParameters: SAPcpmsSettingsParameters? = nil, completionHandler: @escaping (Error?) -> Void)

    Parameters

    authenticationURL

    resource URL that needs oauth2 authentication

    authenticationParameters

    OAuth2AuthenticationParameters

    sapURLSession

    SAPURLSession that handle the connection to the authenticationURL

    credentialStore

    credentials will be saved in the given store

    presentationDelegate

    FlowPresentationDelegate which handles the presentation of authentication webview

    completionHandler

    called when the process finished. Error filled on failure.

  • Restore function for OAuth2 authorization code grant

    Declaration

    Swift

    open func restore(authenticationURL: URL, authenticationParameters: OAuth2AuthenticationParameters, sapURLSession: SAPURLSession, credentialStore: CodableStoring, presentationDelegate: FlowPresentationDelegate, settingsParameters: SAPcpmsSettingsParameters? = nil, completionHandler: @escaping (Error?) -> Void)

    Parameters

    authenticationURL

    resource URL that needs oauth2 authentication

    authenticationParameters

    OAuth2AuthenticationParameters

    sapURLSession

    SAPURLSession that handle the connection to the authenticationURL

    credentialStore

    credentials will be saved in the given store

    presentationDelegate

    FlowPresentationDelegate which handles the presentation of authentication webview

    completionHandler

    called when the process finished. Error filled on failure.

  • Onboard function for OAuth2 client credentials grant

    Declaration

    Swift

    open func onboard(authenticationURL: URL, authenticationParameters: OAuth2ClientCredentialsAuthenticationParameters, sapURLSession: SAPURLSession, credentialStore: CodableStoring, presentationDelegate: FlowPresentationDelegate, settingsParameters: SAPcpmsSettingsParameters? = nil, completionHandler: @escaping (Error?) -> Void)

    Parameters

    authenticationURL

    resource URL that needs oauth2 authentication

    authenticationParameters

    OAuth2ClientCredentialsAuthenticationParameters

    sapURLSession

    SAPURLSession that handle the connection to the authenticationURL

    credentialStore

    credentials will be saved in the given store

    presentationDelegate

    FlowPresentationDelegate which handles the presentation of authentication webview

    completionHandler

    called when the process finished. Error filled on failure.

  • Restore function for OAuth2 client credentials grant

    Declaration

    Swift

    open func restore(authenticationURL: URL, authenticationParameters: OAuth2ClientCredentialsAuthenticationParameters, sapURLSession: SAPURLSession, credentialStore: CodableStoring, presentationDelegate: FlowPresentationDelegate, settingsParameters: SAPcpmsSettingsParameters? = nil, completionHandler: @escaping (Error?) -> Void)

    Parameters

    authenticationURL

    resource URL that needs oauth2 authentication

    authenticationParameters

    OAuth2ClientCredentialsAuthenticationParameters

    sapURLSession

    SAPURLSession that handle the connection to the authenticationURL

    credentialStore

    credentials will be saved in the given store

    presentationDelegate

    FlowPresentationDelegate which handles the presentation of authentication webview

    completionHandler

    called when the process finished. Error filled on failure.

  • Onboard function for OAuth2 password grant

    Declaration

    Swift

    open func onboard(authenticationURL: URL, authenticationParameters: OAuth2PasswordAuthenticationParameters, sapURLSession: SAPURLSession, credentialStore: CodableStoring, presentationDelegate: FlowPresentationDelegate, settingsParameters: SAPcpmsSettingsParameters? = nil, completionHandler: @escaping (Error?) -> Void)

    Parameters

    authenticationURL

    resource URL that needs oauth2 authentication

    authenticationParameters

    OAuth2PasswordAuthenticationParameters

    sapURLSession

    SAPURLSession that handle the connection to the authenticationURL

    credentialStore

    credentials will be saved in the given store

    presentationDelegate

    FlowPresentationDelegate which handles the presentation of authentication webview

    completionHandler

    called when the process finished. Error filled on failure.

  • Restore function for OAuth2 password grant

    Declaration

    Swift

    open func restore(authenticationURL: URL, authenticationParameters: OAuth2PasswordAuthenticationParameters, sapURLSession: SAPURLSession, credentialStore: CodableStoring, presentationDelegate: FlowPresentationDelegate, settingsParameters: SAPcpmsSettingsParameters? = nil, completionHandler: @escaping (Error?) -> Void)

    Parameters

    authenticationURL

    resource URL that needs oauth2 authentication

    authenticationParameters

    OAuth2PasswordAuthenticationParameters

    sapURLSession

    SAPURLSession that handle the connection to the authenticationURL

    credentialStore

    credentials will be saved in the given store

    presentationDelegate

    FlowPresentationDelegate which handles the presentation of authentication webview

    completionHandler

    called when the process finished. Error filled on failure.

  • This method creates the OAuth2TokenStore instance used by the OAuth2Observer to store (and retrieve) tokens. The step user may override this method to supply a custom store. A CodableStoring conformant store is provided as a base store.

    Note: The default implementation uses an instance of OAuth2TokenStorage which proxies the informations to (and from) the provided CodableStoring.

    Declaration

    Swift

    open func createTokenStore(using credentialsStore: CodableStoring) -> OAuth2TokenStore

    Parameters

    credentialsStore

    The provided base store.

    Return Value

    An instance of OAuth2TokenStore.

  • This method creates the SAPURLSession instance used by the OAuth2Authenticator to fetch and refresh OAuth2Tokens. The step user may override this method to supply a custom SAPURLSession. This can be needed if the token endpoint has a custom behaviour that needs to be handled in the requests.

    Note: The default implementation uses a simple instance of SAPURLSession with no additional observers or properties set.

    Declaration

    Swift

    open func createSAPURLSessionForAuthenticator() -> SAPURLSession

    Return Value

    An instance of SAPURLSession

  • This method creates the OAuth2Observer instance used on the SAPURLSession in the OnboardingContext. The step user may override this method to supply a custom OAuth2Observer. This can be needed if the endpoint has a custom challenge behaviour.

    Note: The default implementation creates a simple instance of OAuth2Observer.

    Declaration

    Swift

    open func createOAuth2Observer(authenticator: OAuth2Authentication, credentialStore: CodableStoring, settingsParameters: SAPcpmsSettingsParameters? = nil) -> OAuth2Observer

    Parameters

    authenticator

    The OAuth2Authentication used by the observer.

    credentialStore

    The CodableStoring from the OnboardingContext.

    Return Value

    An instance of the OAuth2Observer.

  • Create Authorization Code Grant Authenticator

    Declaration

    Swift

    open func createAuthorizationCodeGrantAuthenticator(authenticationParameters: OAuth2AuthenticationParameters, presentationDelegate: FlowPresentationDelegate) -> OAuth2Authentication
  • Create Client Credentials Grant Authenticator

    Declaration

    Swift

    open func createClientCredentialsGrantAuthenticator(authenticationParameters: OAuth2ClientCredentialsAuthenticationParameters) -> OAuth2Authentication
  • Create Password Grant Authenticator

    Declaration

    Swift

    open func createPasswordGrantAuthenticator(authenticationParameters: OAuth2PasswordAuthenticationParameters, presentationDelegate: FlowPresentationDelegate) -> OAuth2Authentication