Using JSON Web Tokens (JWTs) to secure your APIs has become an ad-hoc standard in the IT-industry. However, the underlying concepts and mechanisms can be complex and are often misunderstood.
The general advice below pertains to both clients (id tokens) and API-s (access tokens). The specific guidelines regarding access tokens should be followed by API providers.
Info |
---|
General advice when using JWTs
|
Info |
---|
Things to consider when using Access Tokens
|
Note |
---|
Always verify the integrity of the JWT
|
Note |
---|
DO NOT BLINDLY TRUST THE VALUE IN CLAIMSExamples:
|
...
Always validate claims in the Access Token
...
Always verify the "exp" claim to make sure the token hasn’t expired
...
Always verify the claim "nbf" to make sure the token actually is "active"
...
When verifying claims with timestamps, take into account that there may be some time skew between the token issuer and your internal systems.
...
Always verify the claim "iss" to make sure that the token issuer is someone you actually trust
...
Always verify the claim "aud" to make sure that the token is intended for you
...
Reject the request if the "aud" claim is missing
...
Consider rejecting tokens with multiple values in the “aud” claim.
...
If you use "scopes" for access control you must always make sure that the values in the “scope” claims are valid and correct.
...
Always validate and verify that the value in the claim “helseid://claims/identity/assurance_level“, alternatively “helseid://claims/identity/security_level”, corresponds with the requirements for your API.
...
Consider validating and verifying the value in the claim "helseid://claims/identity/pid".
...
Consider validating and verifying the value in the claim "helseid://claims/hpr/hpr_number".
...
Dette dokumentet har blitt flyttet til Utviklerportalen, og skilt i to dokumenter:
This document has been separated into two documents in NHN Utviklerportalen: