OAuth2PasswordGrant

open class OAuth2PasswordGrant : OAuth2

A class to handle authorization for clients via password grant.

If no credentials are set when authorizing, a native controller is shown so that the user can provide them.

  • Declaration

    Swift

    override open class var grantType: String { get }
  • Declaration

    Swift

    override open class var clientIdMandatory: Bool { get }
  • The username to use during authorization.

    Declaration

    Swift

    open var username: String?
  • The password to use during authorization.

    Declaration

    Swift

    open var password: String?
  • Properties used to handle the native controller.

    Declaration

    Swift

    open lazy var customAuthorizer: OAuth2CustomAuthorizerUI { get set }
  • If credentials are unknown when trying to authorize, the delegate will be asked a login controller to present.

    OAuth2Error.noPasswordGrantDelegate will be thrown if the delegate is needed but not set.

    Declaration

    Swift

    open var delegate: OAuth2PasswordGrantDelegate?
  • Adds support for the password & username setting.

    Declaration

    Swift

    override public init(settings: OAuth2JSON)
  • Performs the accessTokenRequest if credentials are already provided, or ask for them with a native view controller.

    If you choose to not automatically dismiss the login controller, you can do so on your own by calling dismissLoginController(animated:).

    Declaration

    Swift

    override open func doAuthorize(params: OAuth2StringDict? = nil) throws

    Parameters

    params

    Optional key/value pairs to pass during authorization

  • Submits loginController’s provided credentials to the OAuth server.

    This doesn’t automatically dismiss the login controller once the user is authorized, allowing the login controller to perform any kind of confirmation before its dismissal. Use endAuthorization to end the authorizing by dismissing the login controller.

    Declaration

    Swift

    public func tryCredentials(username: String, password: String, errorHandler: @escaping (OAuth2Error) -> Void)

    Parameters

    username

    The username to try against the server

    password

    The password to try against the server

    completionHandler

    The closure to call once the server responded. The response’s JSON is send if the server accepted the given credentials. If the JSON is empty, see the error field for more information about the failure.

  • Dismiss the login controller, if any.

    Declaration

    Swift

    open func dismissLoginController(animated: Bool = true)

    Parameters

    animated

    Whether dismissal should be animated

  • Creates a POST request with x-www-form-urlencoded body created from the supplied URL’s query part.

    Declaration

    Swift

    open func accessTokenRequest(params: OAuth2StringDict? = nil) throws -> OAuth2AuthRequest

    Parameters

    params

    Optional key/value pairs to pass during authorization

  • Create a token request and execute it to receive an access token.

    Uses accessTokenRequest(params:) to create the request, which you can subclass to change implementation specifics.

    Declaration

    Swift

    public func obtainAccessToken(params: OAuth2StringDict? = nil, callback: @escaping ((_ params: OAuth2JSON?, _ error: OAuth2Error?) -> Void))

    Parameters

    params

    Optional key/value pairs to pass during authorization

    callback

    The callback to call after the request has returned