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
}
-
The
OnboardingInfoKeyassociated with an instance ofOAuth2AuthenticationParametersin theOnboardingContextinfo.Declaration
Swift
public let authorizationInfoKey: OnboardingInfoKey -
The
OnboardingInfoKeyassociated with an instance ofOAuth2ClientCredentialsAuthenticationParametersin theOnboardingContextinfo.Declaration
Swift
public let clientCredentialsInfoKey: OnboardingInfoKey -
The
OnboardingInfoKeyassociated with an instance ofOAuth2PasswordAuthenticationParametersin theOnboardingContextinfo.Declaration
Swift
public let passwordInfoKey: OnboardingInfoKey -
The
OnboardingInfoKeyassociated with an instance ofsapcpmsSettingsParametersin theOnboardingContextinfo. Used for creating the SAPcpmsAuthenticationManager is the AuthenticationDelegate is present.Declaration
Swift
public var settingsParametersInfoKey: OnboardingInfoKey -
Property to set the title of info screen
Declaration
Swift
public var infoScreenText: String -
Tells the authentication step whether offline restore should be supported. If the property is
true, the authentication step gracefully handles network conditions when restoring while offline. By default this property istrue.Declaration
Swift
public var isAllowingOfflineRestore: Bool -
The delegate which is called by SAPcpmsAuthenticationManager. If this property is nil, then the SAPcpmsAuthenticationManager will not be created.
Declaration
Swift
public weak var authenticationDelegate: AuthenticationDelegate? -
OAuth 2 authentication step initializer
Declaration
Swift
public init(authorizationInfoKey: OnboardingInfoKey, clientCredentialsInfoKey: OnboardingInfoKey, passwordInfoKey: OnboardingInfoKey)Parameters
authorizationInfoKeyOnboardingInfoKey for authorizationInfoKey parameter
clientCredentialsInfoKeyOnboardingInfoKey for clientCredentialsInfoKey parameter
passwordInfoKeyOnboardingInfoKey for passwordInfoKey parameter
-
Instantiates the OAuth 2 onboarding step. Will look for the authentication parameter structure under the
OnboardingInfoKeys specified in the initializer. Will use aWKWebViewinstance to get the authorization code if the Authorization Code Grant flow is used.Declaration
Swift
public convenience init(presenter: WKWebViewPresenting & FlowPresentationDelegateClient = FioriWKWebViewPresenter(), authorizationInfoKey: OnboardingInfoKey = .oauth2AuthenticationParameters, clientCredentialsInfoKey: OnboardingInfoKey = .oauth2ClientCredentialsAuthenticationParameters, passwordInfoKey: OnboardingInfoKey = .oauth2PasswordAuthenticationParameters)Parameters
webViewPresenterThe web view presenter which will supply an
WKWebViewinstance.authorizationInfoKeyThe
OnboardingInfoKeywhich marks aOAuth2AuthenticationParametersinstance in theOnboardingContext.clientCredentialsInfoKeyThe
OnboardingInfoKeywhich marks aOAuth2ClientCredentialsAuthenticationParametersinstance in theOnboardingContext.passwordInfoKeyThe
OnboardingInfoKeywhich marks aOAuth2PasswordAuthenticationParametersinstance in theOnboardingContext. -
Instantiates the OAuth 2 onboarding step. Will look for the authentication parameter structure under the
OnboardingInfoKeys specified in the initializer. Will use aSFSafariViewControllerinstance to get the authorization code if the Authorization Code Grant flow is used.Declaration
Swift
public convenience init(presenter: SFSafariViewControllerPresenting & FlowPresentationDelegateClient, authorizationInfoKey: OnboardingInfoKey = .oauth2AuthenticationParameters, clientCredentialsInfoKey: OnboardingInfoKey = .oauth2ClientCredentialsAuthenticationParameters, passwordInfoKey: OnboardingInfoKey = .oauth2PasswordAuthenticationParameters)Parameters
webViewPresenterThe web view presenter which will supply an
SFSafariViewControllerinstance.authorizationInfoKeyThe
OnboardingInfoKeywhich marks aOAuth2AuthenticationParametersinstance in theOnboardingContext.clientCredentialsInfoKeyThe
OnboardingInfoKeywhich marks aOAuth2ClientCredentialsAuthenticationParametersinstance in theOnboardingContext.passwordInfoKeyThe
OnboardingInfoKeywhich marks aOAuth2PasswordAuthenticationParametersinstance in theOnboardingContext. -
Instantiates the OAuth 2 onboarding step. Will look for the authentication parameter structure under the
OnboardingInfoKeys specified in the initializer. Will use aASWebAuthenticationSessioninstance to get the authorization code if the Authorization Code Grant flow is used.Declaration
Swift
@available(iOS 12.0, *) public convenience init(presenter: ASWebAuthenticationSessionPresenting & FlowPresentationDelegateClient, authorizationInfoKey: OnboardingInfoKey = .oauth2AuthenticationParameters, clientCredentialsInfoKey: OnboardingInfoKey = .oauth2ClientCredentialsAuthenticationParameters, passwordInfoKey: OnboardingInfoKey = .oauth2PasswordAuthenticationParameters)Parameters
webViewPresenterThe web view presenter which will supply an
ASWebAuthenticationSessioninstance.authorizationInfoKeyThe
OnboardingInfoKeywhich marks aOAuth2AuthenticationParametersinstance in theOnboardingContext.clientCredentialsInfoKeyThe
OnboardingInfoKeywhich marks aOAuth2ClientCredentialsAuthenticationParametersinstance in theOnboardingContext.passwordInfoKeyThe
OnboardingInfoKeywhich marks aOAuth2PasswordAuthenticationParametersinstance in theOnboardingContext.
-
This function resets the modifications of the OAuth2AuthenticationStep in the SAPURLSession.
Declaration
Swift
open func reset(sapURLSession: SAPURLSession, completionHandler: @escaping () -> Void)Parameters
sapURLSessionSAPURLSessioncompletionHandlercalled when the process finished.
-
onboard(authenticationURL:authenticationParameters:sapURLSession:credentialStore:presentationDelegate:settingsParameters:completionHandler:)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
authenticationURLresource URL that needs oauth2 authentication
authenticationParametersOAuth2AuthenticationParameters
sapURLSessionSAPURLSessionthat handle the connection to the authenticationURLcredentialStorecredentials will be saved in the given store
presentationDelegateFlowPresentationDelegate which handles the presentation of authentication webview
completionHandlercalled when the process finished. Error filled on failure.
-
restore(authenticationURL:authenticationParameters:sapURLSession:credentialStore:presentationDelegate:settingsParameters:completionHandler:)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
authenticationURLresource URL that needs oauth2 authentication
authenticationParametersOAuth2AuthenticationParameters
sapURLSessionSAPURLSessionthat handle the connection to the authenticationURLcredentialStorecredentials will be saved in the given store
presentationDelegateFlowPresentationDelegate which handles the presentation of authentication webview
completionHandlercalled when the process finished. Error filled on failure.
-
onboard(authenticationURL:authenticationParameters:sapURLSession:credentialStore:presentationDelegate:settingsParameters:completionHandler:)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
authenticationURLresource URL that needs oauth2 authentication
authenticationParametersOAuth2ClientCredentialsAuthenticationParameters
sapURLSessionSAPURLSessionthat handle the connection to the authenticationURLcredentialStorecredentials will be saved in the given store
presentationDelegateFlowPresentationDelegate which handles the presentation of authentication webview
completionHandlercalled when the process finished. Error filled on failure.
-
restore(authenticationURL:authenticationParameters:sapURLSession:credentialStore:presentationDelegate:settingsParameters:completionHandler:)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
authenticationURLresource URL that needs oauth2 authentication
authenticationParametersOAuth2ClientCredentialsAuthenticationParameters
sapURLSessionSAPURLSessionthat handle the connection to the authenticationURLcredentialStorecredentials will be saved in the given store
presentationDelegateFlowPresentationDelegate which handles the presentation of authentication webview
completionHandlercalled when the process finished. Error filled on failure.
-
onboard(authenticationURL:authenticationParameters:sapURLSession:credentialStore:presentationDelegate:settingsParameters:completionHandler:)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
authenticationURLresource URL that needs oauth2 authentication
authenticationParametersOAuth2PasswordAuthenticationParameters
sapURLSessionSAPURLSessionthat handle the connection to the authenticationURLcredentialStorecredentials will be saved in the given store
presentationDelegateFlowPresentationDelegate which handles the presentation of authentication webview
completionHandlercalled when the process finished. Error filled on failure.
-
restore(authenticationURL:authenticationParameters:sapURLSession:credentialStore:presentationDelegate:settingsParameters:completionHandler:)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
authenticationURLresource URL that needs oauth2 authentication
authenticationParametersOAuth2PasswordAuthenticationParameters
sapURLSessionSAPURLSessionthat handle the connection to the authenticationURLcredentialStorecredentials will be saved in the given store
presentationDelegateFlowPresentationDelegate which handles the presentation of authentication webview
completionHandlercalled when the process finished. Error filled on failure.
-
This method creates the
OAuth2TokenStoreinstance used by theOAuth2Observerto store (and retrieve) tokens. The step user may override this method to supply a custom store. ACodableStoringconformant store is provided as a base store.Note: The default implementation uses an instance of
OAuth2TokenStoragewhich proxies the informations to (and from) the providedCodableStoring.Declaration
Swift
open func createTokenStore(using credentialsStore: CodableStoring) -> OAuth2TokenStoreParameters
credentialsStoreThe provided base store.
Return Value
An instance of
OAuth2TokenStore. -
This method creates the
SAPURLSessioninstance used by theOAuth2Authenticatorto fetch and refreshOAuth2Tokens. The step user may override this method to supply a customSAPURLSession. 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
SAPURLSessionwith no additional observers or properties set.Declaration
Swift
open func createSAPURLSessionForAuthenticator() -> SAPURLSessionReturn Value
An instance of
SAPURLSession -
This method creates the
OAuth2Observerinstance used on theSAPURLSessionin theOnboardingContext. The step user may override this method to supply a customOAuth2Observer. 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) -> OAuth2ObserverParameters
authenticatorThe
OAuth2Authenticationused by the observer.credentialStoreThe
CodableStoringfrom theOnboardingContext.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
-
Onboarding function with
OnboardingContextsupportDeclaration
Swift
open func onboard(context: OnboardingContext, completionHandler: @escaping (OnboardingResult) -> Void)Parameters
contextcompletionHandlercalled when the process finished. Error filled on failure.
-
Restore function with
OnboardingContextsupportDeclaration
Swift
open func restore(context: OnboardingContext, completionHandler: @escaping (OnboardingResult) -> Void)Parameters
contextcompletionHandlercalled when the process finished. Error filled on failure.
-
Background function with
OnboardingContextsupportDeclaration
Swift
open func background(context: OnboardingContext, completionHandler: @escaping (OnboardingResult) -> Void)Parameters
contextcompletionHandlercalled when the process finished. Error filled on failure.
-
resetPasscode function with
OnboardingContextsupportDeclaration
Swift
open func resetPasscode(context: OnboardingContext, completionHandler: @escaping (OnboardingResult) -> Void)Parameters
contextcompletionHandlercalled when the process finished. Step OnboardingResult filled.
-
This function resets the modifications of the OAuth2AuthenticationStep in
OnboardingContextDeclaration
Swift
open func reset(context: OnboardingContext, completionHandler: @escaping () -> Void)Parameters
contextcompletionHandlercalled when the process finished.