WebViewPresenter
WebViewPresenter
Web views are required by some authentication steps, as they need to present a login form for user authentication.
This SDK supports three web view types:
- WKWebView
- SFSafariViewController
- ASWebAuthenticationSession
There are “presenter” protocols for each supported web view type:
- WKWebViewPresenting
- SFSafariViewControllerPresenting
- ASWebAuthenticationSessionPresenting
And one default implementation for each:
- WKWebViewPresenter
- SFSafariViewControllerPresenter
- ASWebAuthenticationSessionPresenter
Using ASWebAuthenticationSessionPresenter
Client apps can make use of ASWebAuthenticationSession for OAuth2 authentication, in place of WKWebView or SFSafariViewController web view presenters.
Refer to Configuring OAuth2 authentication with ASWebAuthenticationSession section in the help documentation for more details.
Usage
Usage scenario 1: Pass presenter to SDK components
- Create an instance of one of the default presenters (or implement your own).
- Set it as
webViewPresenter
for authenticator components.
The following listing is an example of how to use this component in combination with WKWebViewPresenter
which is one of the provided default implementations:
let authenticatorParams = SAMLAuthenticationParameters(authorizationEndpointURL: URL(string:<##>)!, finishEndpointURL: URL(string:<##>)!)
let authenticator = SAMLAuthenticator(using: authenticatorParams)
authenticator.webViewPresenter = WKWebViewPresenter()
The example above assumes you have an SAMLAuthenticator
component that you want to use with your own presenter.
Usage scenario 2: Use presenter directly in your app
- Create an instance of one of the default presenters (or implement your own).
- Use it for your own purposes.
- Call
dismissWebView()
once you finish.
let presenter = WKWebViewPresenter()
presenter.presentWebView { webView, error in
if let error = error {
// error handling
return
}
wkWebView.load(request: request)
// Dismiss the web view when you don't need it anymore
presenter.dismissWebView()
}
Notes:
You must call the “present” and “dismiss” method of the presenter on the main thread!
View hierarchy
By default, the default web view presenters present the web view on top of the top-most UIViewController.
You can change this by setting the webViewPresentingViewController
property (on the default presenters) to your own UIViewController. For example:
let wkWebViewPresenter = WKWebViewPresenter()
wkWebViewPresenter.webViewPresentingViewController = <presenting UIViewController of your choice>
Custom implementation
You can define your own implementation of the presenter:
- Implement one of the supported web view presenter protocols.
- Supply one of the system web views in the presentWebView’s completionHandler.
You must call the completionHandler on the main thread!
-
Default implementation of
See moreASWebAuthenticationSessionPresenting
.Declaration
Swift
@available(iOS 12.0, *) public class ASWebAuthenticationSessionPresenter : ASWebAuthenticationSessionPresenting
-
Default implementation of
See moreSFSafariViewControllerPresenting
.Declaration
Swift
public class SFSafariViewControllerPresenter : NSObject, SFSafariViewControllerPresenting, SFSafariViewControllerDelegate
-
This protocol represents a delegate which can be called by one of the web view presenting implementation.
See moreDeclaration
Swift
public protocol WebViewPresenterDelegate : AnyObject
-
Default implementation of
See moreWKWebViewPresenting
.Declaration
Swift
public class WKWebViewPresenter : WKWebViewPresenting
-
This protocol represents an API which is capable of presenting a
See moreASWebAuthenticationSession
.Declaration
Swift
@available(iOS 12.0, *) public protocol ASWebAuthenticationSessionPresenting : AnyObject
-
This protocol represents an API which is capable of presenting a
See moreSFSafariViewController
.Declaration
Swift
public protocol SFSafariViewControllerPresenting : AnyObject
-
This protocol represents an API which is capable of presenting a
See moreWKWebView
.Declaration
Swift
public protocol WKWebViewPresenting : AnyObject
-
This protocol extends the
See moreWKNavigationDelegate
with SAP specific functionality.Declaration
Swift
public protocol SAPWKNavigationDelegate : AnyObject