OAuth2Authorizer

open class OAuth2Authorizer : OAuth2AuthorizerUI

The authorizer to use when on the macOS platform.

You can subclass this class and override presentableAuthorizeViewController(url:) and/or windowController(controller:config:) to further customize appearance.

  • The OAuth2 instance this authorizer belongs to.

    Declaration

    Swift

    public unowned let oauth2: OAuth2Base
  • Stores the default NSWindowController created to contain the web view controller.

    Declaration

    Swift

    var windowController: NSWindowController?
  • Designated initializer.

    Declaration

    Swift

    public init(oauth2: OAuth2Base)

    Parameters

    oauth2

    The OAuth2 instance for which to present an authorization UI

OAuth2AuthorizerUI

  • Uses NSWorkspace to open the authorize URL in the OS browser.

    Throws

    UnableToOpenAuthorizeURL on failure

    Declaration

    Swift

    public func openAuthorizeURLInBrowser(_ url: URL) throws

    Parameters

    url

    The authorize URL to open

  • Tries to use the given context, which on OS X should be a NSWindow, to present the authorization screen. In this case will forward to authorizeEmbedded(from:with:at:), if the context is empty will create a new NSWindow by calling authorizeInNewWindow(with:at:).

    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

Window Creation

  • Presents a modal sheet from the given window.

    Declaration

    Swift

    @available(macOS 10.10, *)
    @discardableResult
    public func authorizeEmbedded(from window: NSWindow, at url: URL) throws -> NSWindow

    Parameters

    from

    The window from which to present the sheet

    at

    The authorize URL to open

    Return Value

    The sheet that is being queued for presentation

  • Creates a new window, containing our OAuth2WebViewController, and centers it on the screen.

    Declaration

    Swift

    @available(macOS 10.10, *)
    @discardableResult
    open func authorizeInNewWindow(at url: URL) throws -> NSWindowController

    Parameters

    at

    The authorize URL to open

    Return Value

    The window that is being shown on screen

  • Instantiates and configures an OAuth2WebViewController, ready to be used in a window.

    Declaration

    Swift

    @available(macOS 10.10, *)
    open func presentableAuthorizeViewController(at url: URL) throws -> OAuth2WebViewController

    Parameters

    at

    The authorize URL to open

    Return Value

    A web view controller that you can present to the user for login

  • Prepares a window controller with the given web view controller as content.

    Declaration

    Swift

    @available(macOS 10.10, *)
    open func windowController(forViewController controller: OAuth2WebViewController, with config: OAuth2AuthConfig) -> NSWindowController

    Parameters

    forViewController

    The web view controller to use as content

    with

    The auth config to use

    Return Value

    A window controller, ready to be presented