OAuth2WebViewController

@available(macOS 10.10, *)
public class OAuth2WebViewController : NSViewController, WKNavigationDelegate, NSWindowDelegate

A view controller that allows you to display the login/authorization screen.

  • Designated initializer.

    Declaration

    Swift

    public init()
  • Handle to the OAuth2 instance in play, only used for debug logging at this time.

    Declaration

    Swift

    var oauth: OAuth2Base?
  • Configure the view to be shown as sheet, false by default; must be present before the view gets loaded.

    Declaration

    Swift

    var willBecomeSheet: Bool
  • The URL to load on first show.

    Declaration

    Swift

    public var startURL: URL? { get set }
  • The URL string to intercept and respond to.

    Declaration

    Swift

    public var interceptURLString: String? { get set }
  • Internally used; the URL components, derived from interceptURLString, comprising the URL to be intercepted.

    Declaration

    Swift

    var interceptComponents: URLComponents?
  • Closure called when the web view gets asked to load the redirect URL, specified in interceptURLString. Return a Bool indicating that you’ve intercepted the URL.

    Declaration

    Swift

    public var onIntercept: ((URL) -> Bool)?
  • Called when the web view is about to be dismissed manually.

    Declaration

    Swift

    public var onWillCancel: (() -> Void)?
  • Our web view; implicitly unwrapped so do not attempt to use it unless isViewLoaded() returns true.

    Declaration

    Swift

    var webView: WKWebView!
  • Initializer from an NSCoder.

    Declaration

    Swift

    required public init?(coder aDecoder: NSCoder)

View Handling

  • Default web view window width; defaults to 600.

    Declaration

    Swift

    internal static let webViewWindowWidth: CGFloat
  • Default web view window height; defaults to 500.

    Declaration

    Swift

    internal static let webViewWindowHeight: CGFloat
  • Override to fully load the view; adds a WKWebView, optionally a dismiss button, and shows the loading indicator.

    Declaration

    Swift

    override public func loadView()
  • This override starts loading startURL if nothing has been loaded yet, e.g. on first show.

    Declaration

    Swift

    override public func viewWillAppear()
  • Override to set the window delegate to self.

    Declaration

    Swift

    override public func viewDidAppear()
  • Adds a loading indicator view to the center of the view.

    Declaration

    Swift

    func showLoadingIndicator()
  • Hides the loading indicator, if it is currently being shown.

    Declaration

    Swift

    func hideLoadingIndicator()
  • Convenience method to show an error message; will add the error to a

    element shown centered in the web view.

    Declaration

    Swift

    func showErrorMessage(_ message: String, animated: Bool)

Actions

  • Loads the given URL in the web view.

    Declaration

    Swift

    public func loadURL(_ url: URL)

    Parameters

    url

    The URL to load

  • Tells the web view to go back in history.

    Declaration

    Swift

    func goBack(_ sender: AnyObject?)
  • Tells the web view to stop loading the current page, then calls the onWillCancel block if it has a value.

    Declaration

    Swift

    @objc
    func cancel(_ sender: AnyObject?)

Web View Delegate

  • Undocumented

    Declaration

    Swift

    public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void)
  • Undocumented

    Declaration

    Swift

    public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)
  • Undocumented

    Declaration

    Swift

    public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error)

Window Delegate

  • Undocumented

    Declaration

    Swift

    public func windowShouldClose(_ sender: NSWindow) -> Bool