Skip to main content

Authentication

important

Codefi Assets uses OpenID Connect authentication provided by Auth0.

Access tokens

Authenticate calls to the API with an access token.

note

For the following tutorials, you only need an access token for the admin account. Other accounts (issuer and investors) only require the administrator access token. This means that anyone with admin credentials can perform actions on behalf of every user.

Dedicated access tokens

If a user was created with the /essentials/user endpoint, and the parameter auth0UserCreate, an access token issued to the same user as the parameter {{userId}} is required to authenticate requests.

This behavior is not used in the tutorials. Here, user accounts are created without the auth0UserCreate parameter, and so the admin access token can be used everywhere.

Generate access token

Make a POST request to the {{ AUTH_URL }}/oauth/token endpoint with the following body:

{
"grant_type": "password",
"username": "{{AUTH_USERNAME}}",
"password": "{{AUTH_PASSWORD}}",
"audience": "https://api.codefi.network",
"scope": "openid profile email",
"client_id": "{{AUTH_CLIENT_ID}}",
"client_secret": "{{AUTH_CLIENT_SECRET}}"
}
Execute commands
ADMIN_ACCESS_TOKEN=$(curl \
--header "Content-Type: application/json" \
--request POST --data '{ "grant_type": "password", "username": "'"$AUTH_USERNAME"'", "password": "'"$AUTH_PASSWORD"'", "audience": "'"$AUTH_AUDIENCE"'", "scope": "openid profile email", "client_id": "'"$AUTH_CLIENT_ID"'", "client_secret": "'"$AUTH_CLIENT_SECRET"'" }' \
$AUTH_URL/oauth/token | jq -r '.access_token')
echo ADMIN_ACCESS_TOKEN=$ADMIN_ACCESS_TOKEN
Example output
ADMIN_ACCESS_TOKEN=eyJh...M8T8A
info