OAuth2DynReg

open class OAuth2DynReg

Class to handle OAuth2 Dynamic Client Registration.

This is a lightweight class that uses a OAuth2 instance’s settings when registering, only few settings are held by instances of this class. Hence it’s highly portable and can be instantiated when needed with ease.

For the full OAuth2 Dynamic Client Registration spec see https://tools.ietf.org/html/rfc7591

  • Additional HTTP headers to supply during registration.

    Declaration

    Swift

    open var extraHeaders: OAuth2StringDict?
  • Whether registration should also allow refresh tokens. Defaults to true, making sure refresh_token grant type is being registered.

    Declaration

    Swift

    open var allowRefreshTokens: Bool
  • Designated initializer.

    Declaration

    Swift

    public init()
  • Register the given client.

    Declaration

    Swift

    open func register(client: OAuth2, callback: @escaping ((_ json: OAuth2JSON?, _ error: OAuth2Error?) -> Void))

    Parameters

    client

    The client to register and update with client credentials, when successful

    callback

    The callback to call when done with the registration response (JSON) and/or an error

  • Returns a URL request, set up to be used for registration: POST method, JSON body data.

    Declaration

    Swift

    open func registrationRequest(for client: OAuth2) throws -> URLRequest

    Parameters

    for

    The OAuth2 client the request is built for

    Return Value

    A URL request to be used for registration

  • The body data to use for registration.

    Declaration

    Swift

    open func registrationBody(for client: OAuth2) -> OAuth2JSON
  • Parse the registration data that’s being returned.

    This implementation uses OAuth2.parseJSON() to convert the data to OAuth2JSON.

    Declaration

    Swift

    open func parseRegistrationResponse(data: Data, client: OAuth2) throws -> OAuth2JSON

    Parameters

    data

    The NSData instance returned by the server

    client

    The client for which we’re doing registration

    Return Value

    An OAuth2JSON representation of the registration data

  • Called when registration has returned data and that data has been parsed.

    This implementation extracts client_id, client_secret and token_endpoint_auth_method and invokes the client’s storeClientToKeychain() method.

    Declaration

    Swift

    open func didRegisterWith(json: OAuth2JSON, client: OAuth2)

    Parameters

    json

    The registration data in JSON format

    client

    The client for which we’re doing registration