OAuth2CodeGrant

open class OAuth2CodeGrant: OAuth2

A class to handle authorization for confidential clients via the authorization code grant method.

This auth flow is designed for clients that are capable of protecting their client secret but can be used from installed apps. During code exchange and token refresh flows, if the client has a secret, a Basic key:secret Authorization header will be used. If not the client key will be embedded into the request body.

  • A class to handle authorization for confidential clients via the authorization code grant method.

    This auth flow is designed for clients that are capable of protecting their client secret but can be used from installed apps. During code exchange and token refresh flows, if the client has a secret, a Basic key:secret Authorization header will be used. If not the client key will be embedded into the request body.

    Declaration

    Swift

    override open class var grantType: String
  • A class to handle authorization for confidential clients via the authorization code grant method.

    This auth flow is designed for clients that are capable of protecting their client secret but can be used from installed apps. During code exchange and token refresh flows, if the client has a secret, a Basic key:secret Authorization header will be used. If not the client key will be embedded into the request body.

    Declaration

    Swift

    override open class var responseType: String?
  • Generate the request to be used for the token request from known instance variables and supplied parameters.

    This will set grant_type to authorization_code, add the code provided and fill the remaining parameters. The client_id is only added if there is no secret (public client) or if the request body is used for id and secret.

    Declaration

    Swift

    open func accessTokenRequest(with code: String, params: OAuth2StringDict? = nil) throws -> OAuth2AuthRequest

    Parameters

    code

    The code you want to exchange for an access token

    params

    Optional additional params to add as URL parameters

    Return Value

    A request you can use to create a URL request to exchange the code for an access token

  • Extracts the code from the redirect URL and exchanges it for a token.

    Declaration

    Swift

    override open func handleRedirectURL(_ redirect: URL)
  • Takes the received code and exchanges it for a token.

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

    Declaration

    Swift

    public func exchangeCodeForToken(_ code: String)
  • Validates the redirect URI: returns a tuple with the code and nil on success, nil and an error on failure.

    Declaration

    Swift

    open func validateRedirectURL(_ redirect: URL) throws -> String