Create a Beyond Identity Management API token
You can automate administrative tasks for your Beyond Identity tenant using the Beyond Identity Management API.
All of the functionality available in the Beyond Identity Admin Console is also available through the API.
In order to call the API, you must create access tokens for the Beyond Identity Management API resource server that include the scopes your app or script will need, and then configure your app or script to use the the tokens in API calls.
Prerequisites​
In order to request an access token, you need to have an app configured in your Beyond Identity tenant.
For Beyond Identity Management API access tokens, this can be the built in Beyond Identity Management API app or another app you create that points to the 'Beyond Identity Management API' Resource Server.
Select your scopes​
Before creating or requesting any tokens for the Beyond Identity Management API (or for any resource), determine the list of scopes the tokens must have, which will determine what access your app or script will have to which resources.
The Beyond Identity Management API documentation provides the required scopes for each supported API action within the "Authorizations" section.
For example, when creating a Realm, the access token must contain the realms:create
scope as shown below:
Admin Console​
The simplest way to acquire an access token for the Beyond Identity Management API is interactively through the Beyond Identity Admin Console.
You can also request the token programmatically using OAuth or OIDC flows.
Create access token in the console​
Under Apps, select the app for which you want a token, such as the Beyond Identity Management API application.
Select the API Tokens tab, and then click on Create token. (Note that the API Tokens tab only exists for apps that use the client credentials grant type. For apps that use the authorization code grant type, you'll need to request the token programmatically. )
Configure the token with a Name, modify the list of Scopes based on your use case, and click Create token.
Note that the list of Scopes available to request comes from the Resource Server associated with the app.
Create access token via API​
To request tokens for the Beyond Identity Management API programmatically, we recommend that you create an app that references the 'Beyond Identity Management API' Resource Server, then send a request to the app's /authorize
and/or /token
API endpoints following the OAuth and OIDC protocols.
Follow the steps below based on the flow you wish to use, either client credentials or authorization code:
- Client Credentials
- Authorization Code
Create an app with the following properties:
Property Value Protocol OAuth2 Client Type Confidential PKCE Disabled Token Endpoint Auth Method Client Secret Basic Grant Type Client Credentials Resource Server Beyond Identity Management API Allowed Scopes add the scopes required for the API call based on the Beyond Identity Management API documentation Fill in a Display Name, then click Submit to save the app.
Next, create the
/token
request as shown below:- Curl
- CSharp
- Dart
- Go
- Java
- Node
- Python
- Ruby
- Rust
/token
1 2 3 4 5
curl "https://auth-$(us|eu).beyondidentity.com/v1/tenants/$(tenant_id)/realms/$(realm_id)/applications/$(application_id)/token" \ -X POST \ -u "$(client_id):$(client_secret)" --basic \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=client_credentials&scope=$(scope)"
/token
/token
/token
/token
/token
/token
/token
/token
where:
application_id is the Application ID of the app you created
client_id and client_secret are the Client ID and Client Secret, respectively, of the app you created
scopes is one or more of the app's Allowed Scopes, space delimited, and includes the required scopes for the API call(s) your app will make
Create an app with the following properties:
Property Value Protocol OIDC Client Type Confidential PKCE S256 Token Endpoint Auth Method Client Secret Basic Grant Type Authorization Code Resource Server Beyond Identity Management API Allowed Scopes add the scopes required for the API call based on the Beyond Identity Management API documentation Configuration Type (on Authenticator Config tab) Hosted Web Fill in a Display Name and at least one Redirect URI, then click Submit to save the app.
Next, use the following examples to obtain an authorization code and then to create a token with that code:
Create the
/authorize
call to obtain an authorization code:- Curl
- CSharp
- Dart
- Go
- Java
- Node
- Python
- Ruby
- Rust
/authorize
1 2 3 4 5 6 7 8
curl -G "https://auth-{us|eu}.beyondidentity.com/v1/tenants/{tenant_id}/realms/{realm_id}/applications/{application_id}/authorize" \ --data-urlencode "response_type=code" \ --data-urlencode "client_id=$(client_id)" \ --data-urlencode "redirect_uri=$(redirect_uri)" \ --data-urlencode "scope=$(scopes)" \ --data-urlencode "state=$(state)" \ --data-urlencode "code_challenge=$(codeChallenge)" \ --data-urlencode "code_challenge_method=S256"
/authorize
/authorize
/authorize
/authorize
/authorize
/authorize
/authorize
/authorize
where:
application_id is the Application ID of the app you created
client_id is your app's Client ID
redirect_uri is one of the app's configured Redirect URI values
scopes is 'openid' plus one or more of the app's Allowed Scopes, space delimited
state is a value generated by your app to maintain state betewen the request and response
codeChallenge is generated as defined in RFC 7636, example JavaScript snippet below:
codeVerifier = crypto.randomBytes(32).toString("base64url");
codeChallenge = crypto
.createHash("sha256")
.update(codeVerifier)
.digest()
.toString("base64url");Then create the
/token
call to create an access token:- Curl
- CSharp
- Dart
- Go
- Java
- Node
- Python
- Ruby
- Rust
/token
1
curl "https://auth-{us|eu}.beyondidentity.com/v1/tenants/{tenant_id}/realms/{realm_id}/applications/{application_id}/token" \ -X POST \ -u "$(client_id):$(client_secret)" --basic \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=authorization_code&code=$(authorization_code)&redirect_uri=${redirect_uri}&client_id=$(client_id)&code_verifier=$(CODE_VERIFIER)"
/token
/token
/token
/token
/token
/token
/token
/token
where:
application_id is the Application ID of the app you created
client_id and client_secret are the Client ID and Client Secret, respectively, of the app you created
redirect_uri is one of the app's configured Redirect URI values and matches the redirect_uri sent in the
/authorize
callauthorization_code is the code returned from the
/authorize
callcodeVerifier is defined as in RFC 7636, example JavaScript snippet below:
codeVerifier = crypto.randomBytes(32).toString("base64url");
codeChallenge = crypto
.createHash("sha256")
.update(codeVerifier)
.digest()
.toString("base64url");