Disruptive Documentation

Class Basic​Auth​Authenticator

public class BasicAuthAuthenticator: Authenticator  

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

A BasicAuthAuthenticator is authenticated by default, so there is no need to call login(). However if you'd like the authenticator to no longer be authenticated, you can call logout(), and then login() if you want it to be authenticated again.

See Authenticator for more details about the properties and methods.

Note: This should only be used for development/testing. For production use-cases the OAuth2Authenticator should be used.

Example:

let credentials = ServiceAccountCredentials(email: "<EMAIL>", keyID: "<KEY_ID>", secret: "<SECRET>")
let authenticator = BasicAuthAuthenticator(credentials: credentials)
let disruptive = Disruptive(authenticator: authenticator)
%263 BasicAuthAuthenticator BasicAuthAuthenticator Authenticator Authenticator BasicAuthAuthenticator->Authenticator

Conforms To

Authenticator

Defines the interface required to authenticate the Disruptive struct.

Initializers

init(credentials:​)

public init(credentials: ServiceAccountCredentials)  

Initializes a BasicAuthAuthenticator using a set of ServiceAccountCredentials.

Parameters

credentials Service​Account​Credentials

The ServiceAccountCredentials to use for authentication. It can be created in DT Studio by clicking the Service Account tab under API Integrations in the side menu.

Properties

credentials

public let credentials : ServiceAccountCredentials

auth

private(set) public var auth: Auth? 

The authentication details.

should​Auto​Refresh​Access​Token

private(set) public var shouldAutoRefreshAccessToken = true

A BasicAuthAuthenticator will default to automatically get a fresh access token. This will be switched on and off when logout() and login() is called.

Methods

login(completion:​)

public func login(completion: @escaping AuthHandler)  

Refreshes the access token, stores it in the auth property, and sets shouldAutoRefreshAccessToken to true.

logout(completion:​)

public func logout(completion: @escaping AuthHandler)  

Logs out the auth provider by setting auth to nil and shouldAutoRefreshAccessToken to false. Call login() to log the auth provider back in again.

refresh​Access​Token(completion:​)

public func refreshAccessToken(completion: @escaping AuthHandler)  

Used internally to create a new access token from the service account credentials passed in to the initializer. This access token is stored in the auth property along with an expiration date in the .distantFuture.