-
Perform user authentication with the given
usernameandpassword.This method requires that the SDK has been configured with a valid
clientIDandclientSecret, usingZone5.configure(baseURL:clientID:clientSecret).If
clientIDandclientSecretrequirements 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
usernameThe user’s username.
passwordThe user’s password.
completionHandler 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.Errorvalue which represents the problem that occurred. -
Refresh the existing bearer token
This method requires that the SDK has been configured with a valid
clientIDand optionallyclientSecretdepending onclientIDsettings, Configure these values usingZone5.configure(baseURL:clientID:clientSecret).It also needs to be configured with a valid refreshable OAuthToken.
If
clientIDandclientSecretrequirements 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
usernameThe user’s username. If not passed, the configured username is used.
completionHandler called the authentication completes. If successful, the result will contain an access
acceptoptional list of terms to accept
billingCountryoptional country that terms were accepted in token that can be used to authenticate the user in future sessions, and otherwise will contain a
Zone5.Errorvalue 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
clientIDThe clientID to request an adhoc token for.
Return Value
a PendingRequest that can be canceled.
View on GitHub
OAuthView Class Reference