BrowserBasedAuthenticationHandlerDelegate

public protocol BrowserBasedAuthenticationHandlerDelegate : FailableAuthenticationHandlerDelegate

Authentication handlers that rely on calling an a web-based oAuth2 authentication flow to gather and validate authentication credentials will support this delegate to support display of the authentication web page, detecting the oAuth2 redirectURI and handling errors.

  • Implementation Required

    Called when/if the UI should display the authentication URL for web-based oAuth2 authentication.

    Example:

    Assuming you’re using a WKWebView to load the authentication page, in your WKNavigationDelegate object:

    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
    
        if let url = navigationAction.request.url {
           if shouldFollowRedirect(to: url) {
               decisionHandler(.allow)
               return
           }
           decisionHandler(.cancel)
        }
    }
    

    Declaration

    Swift

    func authenticationHandler(_ authenticationHandler: AuthenticationHandler, loadWebAuthenticationUrl url: URL, shouldFollowRedirect: @escaping (_ to: URL) -> (Bool))

    Parameters

    authenticationHandler

    the authenticationHandler associated with this delegate

    url

    The URL to display

    shouldFollowRedirect

    A closure that parses the provided URL and determines if the URL is the expected post-authentication redirect URI.

    to

    The URL to parse in shouldFollowRedirect

    Return Value

    True if the normal redirect web page loading should be allowed to continue. False if the provided URL was in fact the expected oAuth2 redirect URI, and the web view should not continue loading.

  • Implementation optional

    Allows for modifying, type conversion, or adding to the oAuth2 authentication response’s query string provided metadata during the authentication process.

    After validating the oAuth2 redirect, the authentication process parses the redirect’s query string. This delegate method is called after the query string has been parsed, but prior to storing that data in the AuthenticationHandler’s authenticationResponsePayload property. The return value from this method is what is stored.

    Default Implementation

    If no implementation is provided, this function returns same dictionary as was provided in the queryStringInfo parameter.

    Declaration

    Swift

    func authenticationHandler(_ authenticationHandler: AuthenticationHandler, willStoreQueryParameters queryStringInfo: [String: String]) -> [String: Any]

    Parameters

    authenticationHandler

    the AuthenticationHandler associated with this delegate

    queryStringInfo

    Dictionary of the parsed query string.

    Return Value

    Dictionary of authentication information