Disruptive Documentation

Protocol Authenticator

public protocol Authenticator  

Defines the interface required to authenticate the Disruptive struct.

Any conforming types needs a mechanism to acquire an access token that can be used to authenticate against the Disruptive Technologies' REST API.

%77 Authenticator Authenticator BasicAuthAuthenticator BasicAuthAuthenticator BasicAuthAuthenticator->Authenticator OAuth2Authenticator OAuth2Authenticator OAuth2Authenticator->Authenticator

Types Conforming to Authenticator

BasicAuthAuthenticator

An Authenticator that logs in a service account using basic auth.

OAuth2Authenticator

An Authenticator that logs in a service account using OAuth2 with a JWT Bearer Token as an authorization grant. This is a more secure flow than the basic auth counter-part, and is the recommended way to authenticate a service account in a production environment.

Requirements

auth

var auth: Auth?  

The authentication data (token, and expiration date). This should be set by a conforming type after a call to refreshAccessToken().

should​Auto​Refresh​Access​Token

var shouldAutoRefreshAccessToken: Bool  

Indicates whether the auth provider should automatically attempt to refresh the access token if the local one is expired, or if no local access token is available. This is intended to prevent any accidental re-authentications being made after the client has logged out.

Auth​Handler

typealias AuthHandler = (Result<Void, DisruptiveError>) -> () 

The completion closure type used by the auth functions

login(completion:​)

func login(completion: @escaping AuthHandler) 

A conforming type should call refreshAccessToken() to get an initial access token, and if successful, set shouldAutoRefreshAccessToken to true.

logout(completion:​)

func logout(completion: @escaping AuthHandler) 

A conforming type should clear out any state that was created while logging in, including setting auth to nil and shouldAutoRefreshAccessToken to false.

refresh​Access​Token(completion:​)

func refreshAccessToken(completion: @escaping AuthHandler) 

A conforming type should use a mechanism to acquire an access token than can be used to authenticate against the Disruptive Technologies' REST API. Once that token has been acquired, it should be stored in the auth property along with a relevant expiration date.

This will be called automatically when necessary as long as shouldAutoRefreshAccessToken is set to true.