/orders
and /customers
. Your application would interact with these endpoints using different HTTP methods; for example, POST /orders
could create a new order or GET /orders
could retrieve the dataset of one or more orders.
For this implementation we will only define 2 endpoints; one for retrieving a list of all timesheets for an employee, and another which will allow an employee to create a new timesheet entry.
An HTTP GET
request to the /timesheets
endpoint will allow a user to retrieve their timesheets, and an HTTP POST
request to the /timesheets
endpoint will allow a user to add a new timesheet.
See the implementation inNode.js.
Missing or invalid token
error message to the calling app.
The validations that the API should perform are:
sub
claim which identifies the principal that is the subject to the claim. In the case of the Implicit Grant flow this claim will contain the user’s identity, which will be the unique identifier for the Auth0 user. You can use this to associate any information in external systems with a particular user.
You can also use a custom claim to add another attribute of the user - such as their email address - to the Access Token and use that to uniquely identify the user.
See the implementation inNode.js.
token id_token
. The token
part, triggers the flow to return an Access Token in the URL fragment, while the id_token
part, triggers the flow to return an as well.openid profile
will return all the user profile information in the ID Token. You also need to request the scopes required to call the API, in this case the read:timesheets create:timesheets
scopes. This will ensure that the Access Token has these scopes.authorize()
method:
parseHash()
method which parses a URL hash fragment to extract the result of an Auth0 authentication response.
The contents of the authResult object returned by parseHash depend upon which authentication parameters were used. It may include the following:
client.userInfo
method can be called passing the returned authResult.accessToken
in order to retrieve the user’s profile information. It will make a request to the /userinfo endpoint and return the user
object, which contains the user’s information, similar to the example below:
userInfo
function:
scope
of the user, you may want to show or hide certain UI elements. To determine the scope issued to a user, you will need to store the scope which was initially requested during the authorization process. When a user is authorized, the scope
will also be returned in the authResult
.
If the scope
in the authResult
is empty, then all the scopes which was requested was granted. If the scope
in the authResult
is not empty, it means a different set of scopes were granted, and you should use the ones in authResult.scope
.
See the implementation inAngular 2.
Authorization
header using the Bearer
scheme.
See the implementation inAngular 2.
7200
seconds (2 hours), but this can be controlled on a per-API basis.
Once expired, an Access Token can no longer be used to access an API. In order to obtain access again, a new Access Token needs to be obtained.
Obtaining a new Access Token can be done by repeating the authentication flow, used to obtain the initial Access Token. In a SPA this is not ideal, as you may not want to redirect the user away from their current task to complete the authentication flow again.
In cases like this you can make use of Silent Authentication. Silent authentication lets you perform an authentication flow where Auth0 will only reply with redirects, and never with a login page. This does however require that the user was already logged in via Single Sign-on (SSO).
See the implementation inAngular 2.