Class
BasicAuthAuthenticator
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)
Relationships
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
Name | Type | Description |
---|---|---|
credentials | ServiceAccountCredentials |
The |
Properties
credentials
public let credentials : ServiceAccountCredentials
shouldAutoRefreshAccessToken
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.
refreshAccessToken(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
.