Service Account

Authenticates the API using Service Account credentials. Details about the authentication flow implementation can be found in our OAuth2 Example.

Preliminaries

  • To authenticate using this method, a Service Account with sufficient permissions is required. If you’re unfamiliar with this concept, read our Introduction to Service Accounts.

Usage

The following snippet authentications all functionality in the package at once.

import os
import disruptive as dt

# It is good practice to fetch credentials from an environment or file.
key_id = os.environ.get('DT_SERVICE_ACCOUNT_KEY_ID', '')
secret = os.environ.get('DT_SERVICE_ACCOUNT_SECRET', '')
email = os.environ.get('DT_SERVICE_ACCOUNT_EMAIL', '')

# Using the fetched credentials, authenticate the package.
dt.default_auth = dt.Auth.service_account(key_id, secret, email)

Method

disruptive.Auth.service_account(key_id, secret, email)

This method uses an OAuth2 authentication flow. With the provided credentials, a JWT is created and exchanged for an access token.

Parameters:
  • key_id (str) – Unique Service Account key ID.

  • secret (str) – Service Account secret.

  • email (str) – Unique Service Account email address.

Returns:

auth – Object to initialize and maintain authentication to the REST API.

Return type:

ServiceAccountAuth

Class

class disruptive.authentication.ServiceAccountAuth(key_id, secret, email)

Ensures that the access token is available and up-to-date.

Variables:

token_endpoint (str) – URL to which the jwt is exchanged for an access token.