To use Skyflow’s Management API, Data API, or SDKs, you need a JWT bearer token (recommended) or an API Key to authenticate your API calls. JWT Bearer tokens and API keys allow scoped and permission-sensitive access to your account and the vaults it has. JWT Bearer tokens are time-limited, and API keys are long-lived.
Skyflow’s bearer tokens match the RFC 6750 Authorization Bearer Token Header specification.
Sign in to your Skyflow account. If you don’t have an account, sign up for a free trial.
When generating tokens using a Skyflow SDK or Python script, you must create a service account. A service account is an identity for machine access to your vault. The service account’s roles, and the policies attached to those roles, decide the level of access a service account has to a vault.
If you already have a service account, skip to the method you want to use to generate a bearer token.
In Studio, click Manage Account.
Click Service accounts.
Click Add service account.
For Name, enter a value. For example, “Authenticate”.
For Service account admins, select the admins of your service account, then click Next.
For Authentication type, select whether to authenticate via JWT bearer tokens or an API key. JWT bearer tokens are time-limited, while API keys are long-lived.
Unless you have a valid business need, use JWT bearer tokens to authenticate.
If you want to enforce context-aware authentication, select Inject context_identifier in bearer token.
Click Next.
For Assignments, select the resource and roles for which you want to assign to the service account. You may need to expand the resource tree to find your vault.
For roles, select the role for which you want to assign to the resource.
Click Create service account.
Your browser downloads a credentials.json file. Store this file in a secure location. You’ll need it to generate bearer tokens.
You can generate a bearer token with an SDK, Python script, or through Skyflow Studio. In production environments, we recommend using Skyflow-provided SDKs.
When you integrate your backend systems with one of Skyflow’s SDKs, you can use service account credentials to generate bearer tokens.
Bearer tokens generated from SDKs are valid for 60 minutes and let you make API calls allowed by the policies associated with the service account.
Now that you have your credentials.json file, it’s time to prepare the SDK in the language of your choice.
Make sure your project is using Go Modules:
Then reference skyflow-go in a Go program with import:
With the SDK installed, you can generate bearer tokens by passing your credentials.json file into an appropriate language-specific function.
The Go SDK has two functions that can take credentials.json and return a bearer token:
GenerateBearerToken(filepath) takes the path to credentials.json as input.GenerateBearerTokenFromCreds(credentials) takes the body of credentials.json as a string as input.Once you have your bearer token, you can programmatically interact with Skyflow APIs. See next steps.
You can generate bearer tokens through Studio for short-term use. Bearer tokens generated in Studio are valid for 24 hours and let you make API calls allowed by the policies associated with your account.
Studio copies the token onto your clipboard.
In production environments, generate bearer tokens using Skyflow-provided SDKs. However, you can use this Python script to test generating bearer tokens on your local machine. To execute the script, make sure you have the credentials.json file, downloaded during the service account creation.
This guide uses Homebrew to run Python installation commands. Adapt your Python installation accordingly.
From your terminal, run the following commands to install python and the appropriate libraries.
Install Python version 3.5 or later.
Install the following libraries:
Now that you have your credentials.json file, it’s time to prepare the Python script for generating a bearer token. To get started, copy, and paste the following getBearerToken.py script into your IDE.
Locate the jwtToken, creds parameter and enter the full path to your credentials.json file.
Save this file as getBearerToken.py to a secure location. You’ll need it to execute the script.
From your terminal, navigate to the folder with the getBearerToken.py script and run the following command to generate a bearer token.
Skyflow validates the JWT assertion and returns a bearer token.
Once you have your bearer token, you can programmatically interact with Skyflow APIs. See next steps.
Skyflow’s client-side SDKs doesn’t have direct methods to generate bearer tokens. Bearer token generation typically involves sensitive operations that shouldn’t happen in client-side environments (like browsers) because of security concerns.
Bearer tokens are usually generated on a server, where you can securely store your application’s credentials and use them to authenticate with the Management API to retrieve a token. You then pass the token to the client-side application, which can use a client-side SDK to interact with Skyflow.
Here’s a general outline of the steps you would take to generate a bearer token and use it with a client-side SDK:
getBearerToken parameter of the initialization method. This function should make an API call to your backend service to retrieve the bearer token.Here’s a sample JavaScript implementation of the getBearerToken function in your client code:
You would initialize the Skyflow client like this:
Remember that generating and handling bearer tokens requires careful security considerations, as these tokens provide access to your Skyflow vault. Always keep your credentials secure, and never expose them to the client-side.
API key-based authentication is an alternate but less secure method of authenticating service accounts.
When using API key-based authentication, remember the following practices:
When configuring your authentication method for a service account, you can use either JWT bearer tokens or API keys. You can generate API keys by calling the Create Service Account API while creating a service account. After configuring your service account, you can create, rotate, disable, or delete the key with the Management API.
You can’t generate bearer tokens with a service account configured to use API keys or create API keys with a service account configured to use bearer tokens.
Call the Service Accounts API with apiKeyEnabled set to true:
$MANAGEMENT_URL is your environment’s Management API URL:
https://manage.skyflowapis.comhttps://manage.skyflowapis-preview.comYou can now use your bearer token to interact with Skyflow APIs.
If you’re new to Skyflow, see Get started with Skyflow. Otherwise, see the various ways you can use Skyflow APIs: