Skip to content

API tokens

An admin user that SSO manages has no password. Thus the REST, SOAP and GraphQL APIs refuse the usual admin token request of the user. With this feature, the user gets an admin API token after a re-authentication at the identity provider.

  1. Go to Stores > Configuration > Advanced > Admin > Visus Single Sign-On.

  2. Set Allow API Tokens For Single Sign-On Accounts to Yes.

  3. In API Token Lifetime (Minutes), enter the lifetime of each token. The default is 60 minutes.

  4. Click Save Config.

  5. Go to System > Permissions > User Roles.

  6. For each role that needs API access, add the API Tokens For Single Sign-On resource under My Account.

If the admin token lifetime of Magento (OAuth > Access Token Expiration) is shorter, a token expires at the end of that lifetime.

The My Account > API Tokens page of an SSO-managed user. It shows the token lifetime, the Create Token button, the Active Tokens list with the Created, Expires and IP Address columns, and the Revoke All Tokens button.

  1. Go to My Account, and open API Tokens.

  2. Click Create Token.

  3. In the Create API Token dialog, verify your identity with your identity provider.

  4. Create the token.

  5. Copy the token. You cannot see the token again after you close the window.

  6. Click Done.

Use the token as a bearer token:

Terminal window
curl -H "Authorization: Bearer <token>" https://shop.example.com/rest/V1/store/storeViews

Magento revokes all the admin tokens of a user, not one token. Thus a revoke also stops the tokens that the user got in another way.

  • Your own tokens: on My Account > API Tokens, click Revoke All Tokens.
  • The tokens of other users: go to System > Permissions > Visus Single Sign-On > API Tokens. Click Revoke All For User in the row of the user. To revoke the tokens of more than one user, select the rows, and use the Revoke All Tokens Of Users mass action.

The grid shows the unexpired tokens that SSO users got after a re-authentication. To see the grid, the role needs View API Tokens. To revoke, the role needs Revoke API Tokens.

The SSO API Tokens grid in the admin, with the admin email, the provider, the IP address, the issue time and the expiry time of each token, and the Revoke All For User row action.

The token is an ordinary admin token of Magento. Each time an API reads the token, the module examines it:

  • The module refuses an admin token of an SSO-managed user. This also applies to a token from a time before SSO managed the user.
  • The exception is a token that the user got on the API Tokens page. The module accepts it until the lifetime of the module ends.
  • If you turn off Allow API Tokens For Single Sign-On Accounts, the module refuses these tokens too.

The module does not change the tokens of customers and integrations.

The visus_admin_sso_clean_expired_api_tokens cron job deletes the records of the expired tokens every hour.