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
OnboardingInfoKey
associated with an instance ofOAuth2AuthenticationParameters
in theOnboardingContext
info.Declaration
Swift
public let authorizationInfoKey: OnboardingInfoKey
-
The
OnboardingInfoKey
associated with an instance ofOAuth2ClientCredentialsAuthenticationParameters
in theOnboardingContext
info.Declaration
Swift
public let clientCredentialsInfoKey: OnboardingInfoKey
-
The
OnboardingInfoKey
associated with an instance ofOAuth2PasswordAuthenticationParameters
in theOnboardingContext
info.Declaration
Swift
public let passwordInfoKey: OnboardingInfoKey
-
The
OnboardingInfoKey
associated with an instance ofsapcpmsSettingsParameters
in theOnboardingContext
info. 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
authorizationInfoKey
OnboardingInfoKey for authorizationInfoKey parameter
clientCredentialsInfoKey
OnboardingInfoKey for clientCredentialsInfoKey parameter
passwordInfoKey
OnboardingInfoKey for passwordInfoKey parameter
-
Instantiates the OAuth 2 onboarding step. Will look for the authentication parameter structure under the
OnboardingInfoKey
s specified in the initializer. Will use aWKWebView
instance 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
webViewPresenter
The web view presenter which will supply an
WKWebView
instance.authorizationInfoKey
The
OnboardingInfoKey
which marks aOAuth2AuthenticationParameters
instance in theOnboardingContext
.clientCredentialsInfoKey
The
OnboardingInfoKey
which marks aOAuth2ClientCredentialsAuthenticationParameters
instance in theOnboardingContext
.passwordInfoKey
The
OnboardingInfoKey
which marks aOAuth2PasswordAuthenticationParameters
instance in theOnboardingContext
. -
Instantiates the OAuth 2 onboarding step. Will look for the authentication parameter structure under the
OnboardingInfoKey
s specified in the initializer. Will use aSFSafariViewController
instance 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
webViewPresenter
The web view presenter which will supply an
SFSafariViewController
instance.authorizationInfoKey
The
OnboardingInfoKey
which marks aOAuth2AuthenticationParameters
instance in theOnboardingContext
.clientCredentialsInfoKey
The
OnboardingInfoKey
which marks aOAuth2ClientCredentialsAuthenticationParameters
instance in theOnboardingContext
.passwordInfoKey
The
OnboardingInfoKey
which marks aOAuth2PasswordAuthenticationParameters
instance in theOnboardingContext
. -
Instantiates the OAuth 2 onboarding step. Will look for the authentication parameter structure under the
OnboardingInfoKey
s specified in the initializer. Will use aASWebAuthenticationSession
instance 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
webViewPresenter
The web view presenter which will supply an
ASWebAuthenticationSession
instance.authorizationInfoKey
The
OnboardingInfoKey
which marks aOAuth2AuthenticationParameters
instance in theOnboardingContext
.clientCredentialsInfoKey
The
OnboardingInfoKey
which marks aOAuth2ClientCredentialsAuthenticationParameters
instance in theOnboardingContext
.passwordInfoKey
The
OnboardingInfoKey
which marks aOAuth2PasswordAuthenticationParameters
instance in theOnboardingContext
.
-
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(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
authenticationURL
resource URL that needs oauth2 authentication
authenticationParameters
OAuth2AuthenticationParameters
sapURLSession
SAPURLSession
that handle the connection to the authenticationURLcredentialStore
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(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
authenticationURL
resource URL that needs oauth2 authentication
authenticationParameters
OAuth2AuthenticationParameters
sapURLSession
SAPURLSession
that handle the connection to the authenticationURLcredentialStore
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(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
authenticationURL
resource URL that needs oauth2 authentication
authenticationParameters
OAuth2ClientCredentialsAuthenticationParameters
sapURLSession
SAPURLSession
that handle the connection to the authenticationURLcredentialStore
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(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
authenticationURL
resource URL that needs oauth2 authentication
authenticationParameters
OAuth2ClientCredentialsAuthenticationParameters
sapURLSession
SAPURLSession
that handle the connection to the authenticationURLcredentialStore
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(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
authenticationURL
resource URL that needs oauth2 authentication
authenticationParameters
OAuth2PasswordAuthenticationParameters
sapURLSession
SAPURLSession
that handle the connection to the authenticationURLcredentialStore
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(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
authenticationURL
resource URL that needs oauth2 authentication
authenticationParameters
OAuth2PasswordAuthenticationParameters
sapURLSession
SAPURLSession
that handle the connection to the authenticationURLcredentialStore
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 theOAuth2Observer
to store (and retrieve) tokens. The step user may override this method to supply a custom store. ACodableStoring
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 providedCodableStoring
.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 theOAuth2Authenticator
to fetch and refreshOAuth2Token
s. 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
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 theSAPURLSession
in 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) -> OAuth2Observer
Parameters
authenticator
The
OAuth2Authentication
used by the observer.credentialStore
The
CodableStoring
from 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
OnboardingContext
supportDeclaration
Swift
open func onboard(context: OnboardingContext, completionHandler: @escaping (OnboardingResult) -> Void)
Parameters
context
completionHandler
called when the process finished. Error filled on failure.
-
Restore function with
OnboardingContext
supportDeclaration
Swift
open func restore(context: OnboardingContext, completionHandler: @escaping (OnboardingResult) -> Void)
Parameters
context
completionHandler
called when the process finished. Error filled on failure.
-
Background function with
OnboardingContext
supportDeclaration
Swift
open func background(context: OnboardingContext, completionHandler: @escaping (OnboardingResult) -> Void)
Parameters
context
completionHandler
called when the process finished. Error filled on failure.
-
resetPasscode function with
OnboardingContext
supportDeclaration
Swift
open func resetPasscode(context: OnboardingContext, completionHandler: @escaping (OnboardingResult) -> Void)
Parameters
context
completionHandler
called when the process finished. Step OnboardingResult filled.
-
This function resets the modifications of the OAuth2AuthenticationStep in
OnboardingContext
Declaration
Swift
open func reset(context: OnboardingContext, completionHandler: @escaping () -> Void)
Parameters
context
completionHandler
called when the process finished.