Client Credentials access token

To be able to send request and receive responses from the Bracken API the client needs to have the correct authorisation and authentication.

Authentication

The client obtains permission to access the API through an Access Token. This token gives the client developer authorisation to use the API within their domain.

Getting a token in Bracken

Example code in Python 3.8

# Libraries to helping with requests and dealing with OAuth 2.0
import requests
from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import BackendApplicationClient

# Declare your variables
domainkey = 00000
client_id = 'your-client_id'
client_secret = 'your-client_secret'

# Sending information to get the token
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url='https://identity.brackenlearning.com/connect/token', client_id=client_id,client_secret=client_secret)

# Request a new access token
s = requests.Session()
s.headers.update({'Authorization': 'Bearer {}'.format(token['access_token'])})

# 's' is your access token
print(s)

Example code in PHP

Here is an an example of how to requesting a certificate from the bracken api using PHP and jumbojett/OpenID-Connect-PHP lib.

See https://github.com/jumbojett/OpenID-Connect-PHP on how to install OpenID-Connect-PHP lib.

#!/usr/bin/php

<?php
// Requires
// OpenIDConnectClient (see https://github.com/jumbojett/OpenID-Connect-PHP)
// also php-curl extension.

// Path to OpenIDConnectClient lib.
require __DIR__ . "/vendor/autoload.php";

// Import OpenIDConnectClient lib
use Jumbojett\OpenIDConnectClient;

$identityUrl = "https://identity.brackenlearning.com";
$tokenEndpoint = $identityUrl."/connect/token";

$client_id = "YOUR client_id";
$client_secret = "YOUR client_secret";
$client_scope = "bracken-api-scope";

// Request Client to Request token
$oidc = new OpenIDConnectClient($identityUrl,$client_id,$client_secret);
$oidc->providerConfigParam(array("token_endpoint"=>$tokenEndpoint));
// Add scope
$oidc->addScope($client_scope); 

// this assumes success (to validate check if the access_token property is there and a valid JWT) :
$clientCredentialsToken = $oidc->requestClientCredentialsToken()->access_token;
echo $clientCredentialsToken."\r\n";
 
$token = $clientCredentialsToken;
echo token;
?>

Helpful resources

Here are some helpful articles and resources to give a greater insight into OAuth 2.0 and how to gain the access token.