OAuthView

public class OAuthView : APIView

Undocumented

  • Perform user authentication with the given username and password.

    This method requires that the SDK has been configured with a valid clientID and clientSecret, using Zone5.configure(baseURL:clientID:clientSecret).

    If clientID and clientSecret requirements are not satisfied, the server will respond with an appropriate 401 response.

    On success the returned access token is automatically saved and will be the access token used from here on.

    Does not pass back a PendingRequest as this is not something that we want to cancel mid-request

    Declaration

    Swift

    public func accessToken(username: String, password: String, redirectURI: String = "https://localhost", completion: @escaping (_ result: Result<OAuthToken, Zone5.Error>) -> Void)

    Parameters

    username

    The user’s username.

    password

    The user’s password.

    completion

    Handler called the authentication completes. If successful, the result will contain an access token that can be used to authenticate the user in future sessions, and otherwise will contain a Zone5.Error value which represents the problem that occurred.

  • Refresh the existing bearer token

    This method requires that the SDK has been configured with a valid clientID and optionally clientSecret depending on clientID settings, Configure these values using Zone5.configure(baseURL:clientID:clientSecret).

    It also needs to be configured with a valid refreshable OAuthToken.

    If clientID and clientSecret requirements are not satisfied, the server will respond with an appropriate 401 response.

    If there is no token to refresh the method will call the completion with Zone5.Error.invalidConfiguration.

    On success the returned access token is automatically saved and will be the access token used from here on.

    Does not pass back a PendingRequest as this is not something that we want to cancel mid-request

    If you are using the sdk for all comms then explicit use of this method is unnessessary as it is done implicitely whenever your token nears expiry

    Declaration

    Swift

    public func refreshAccessToken(username: String? = nil, refreshToken: String? = nil, accept: [String]? = nil, billingCountry: String? = nil, completion: @escaping (_ result: Result<OAuthToken, Zone5.Error>) -> Void)

    Parameters

    username

    The user’s username. If not passed, the configured username is used.

    completion

    Handler called the authentication completes. If successful, the result will contain an access

    accept

    optional list of terms to accept

    billingCountry

    optional country that terms were accepted in token that can be used to authenticate the user in future sessions, and otherwise will contain a Zone5.Error value which represents the problem that occurred.

  • Fetch an adhoc access token on behalf of another app (different clientID) that can be used to authenticate with the zone5 server. This is an authenticated endpoint so requires there to be a valid configured access token.

    Declaration

    Swift

    @discardableResult
    public func adhocAccessToken(for clientID: String, completion: @escaping (_ result: Result<OAuthToken, Zone5.Error>) -> Void) -> PendingRequest?

    Parameters

    clientID

    The clientID to request an adhoc token for.

    Return Value

    a PendingRequest that can be canceled.