OAuth2Authorizer

open class OAuth2Authorizer: OAuth2AuthorizerUI

This authorizer takes care of iOS-specific tasks when showing the authorization UI.

You can subclass this class and override willPresent(viewController:naviController:) in order to further customize presentation of the UI.

  • Uses UIApplication to open the authorize URL in iOS’s browser.

    Throws

    UnableToOpenAuthorizeURL on failure

    Declaration

    Swift

    public func openAuthorizeURLInBrowser(_ url: URL) throws

    Parameters

    url

    The authorize URL to open

  • Tries to use the current auth config context, which on iOS should be a UIViewController, to present the authorization screen.

    Throws

    Can throw OAuth2Error if the method is unable to show the authorize screen

    Declaration

    Swift

    public func authorizeEmbedded(with config: OAuth2AuthConfig, at url: URL) throws

    Parameters

    with

    The configuration to be used; usually uses the instance’s authConfig

    at

    The authorize URL to open

  • Called with the view- and (possibly) navigation-controller that is about to be presented. Useful for subclasses, default implementation does nothing.

    Declaration

    Swift

    open func willPresent(viewController: UIViewController, in naviController: UINavigationController?)

    Parameters

    viewController

    The Safari- or web view controller that will be presented

    naviController

    The navigation controller embedding the view controller, if any

  • Presents a Safari view controller from the supplied view controller, loading the authorize URL.

    The mechanism works just like when you’re using Safari itself to log the user in, hence you need to implement application(application:openURL:sourceApplication:annotation:) in your application delegate.

    This method does NOT dismiss the view controller automatically, you probably want to do this in the callback. Simply call this method first, then call dismissViewController() on the returned web view controller instance in that closure. Or use authorizeEmbedded(with:at:) which does all this automatically.

    Declaration

    Swift

    public func authorizeSafariEmbedded(from controller: UIViewController, at url: URL) throws -> SFSafariViewController

    Parameters

    from

    The view controller to use for presentation

    at

    The authorize URL to open

    Return Value

    SFSafariViewController, being already presented automatically

  • Presents a web view controller, contained in a UINavigationController, on the supplied view controller and loads the authorize URL.

    Automatically intercepts the redirect URL and performs the token exchange. It does NOT however dismiss the web view controller automatically, you probably want to do this in the callback. Simply call this method first, then assign that closure in which you call dismissViewController() on the returned web view controller instance.

    Declaration

    Swift

    public func authorizeEmbedded(from controller: UIViewController, at url: URL) throws -> OAuth2WebViewController

    Parameters

    from

    The view controller to use for presentation

    at

    The authorize URL to open

    Return Value

    OAuth2WebViewController, embedded in a UINavigationController being presented automatically