Authorization
header of each subsequent request to your API. You want that token to be something standard, like since you will find libraries in most of the platforms and you don’t want to do your own crypto.
With both approaches, you can get the same amount of information from the user. That’s controlled by the scope
parameter sent in the login request (either using the Lock, our JavaScript library or a plain link). The scope
is a parameter of the .signin({scope: 'openid name email'})
method which ends up being part of the query string in the login request.
By default, we use scope=openid
in token-based authentication to avoid having a huge token. You can control any standard Connect (OIDC) claims that you want to get in the token by adding them as scope values. For example, scope=openid name email family_name address phone_number
. To learn more, see Standard Claims on openid.net.
You can mix token-based authentication with cookie-based authentication. Take into account that cookies will work just fine if the web app and the API are served from the same domain, so you might not need token based authentication. If you need to, we also return a JWT on the web app flow. Each of our SDKs will do it differently. If you want to call your APIs from JavaScript(instead of using the existing cookie), then you have to set the access tokens using Web Workers or JavaScript closures to handle token transmissions and storage. To learn more, read the Browser in-memory scenarios section of our Token Storage page.
offline_access
scope in your request).
Rules will run for the refresh token exchange. To execute special logic, you can look at the context.protocol
property in your rule. If the value is oauth2-refresh-token
, then the rule is running during the exchange.
When trying to get a refresh token, the parameter is not available on the Rules context object. If you receive an error when attempting to add the audience parameter, verify that you do not have it set on the token.
If you try to do a redirect with context.redirect
, the authentication flow will return an error.
If you have added custom claims to your tokens using a rule, the custom claims will appear in new tokens issued when using a refresh token for as long as your rule is in place. Although new tokens do not automatically inherit custom claims, rules run during the refresh token flow, so the same code will be executed. This allows you to add or change custom claims in newly-issued tokens without forcing previously-authorized applications to obtain a new refresh token.
user_id
that you need to persist during tests to be used later.offline_access
is requested in the authorization request, a new refresh token is issued to the user. In the case users log out and in again with the same device, a new refresh token is issued. Depending on how your application stores and uses refresh tokens, the old refresh token from the first login might become obsolete, and your application will most likely use the new refresh tokens if both tokens are issued with the same audience. To learn more, read Token Storage.
To avoid accumulating obsolete refresh tokens, even though the refresh token limit removes the oldest token first, we recommend you configure refresh token expiration. Both rotating and non-rotating (or reusable) refresh tokens can be configured to expire with either idle or absolute expiry values. Both expiration values help remove tokens that are not in active use and avoid accumulating tokens for the user. To learn more, read Configure Refresh Token Expiration.