Page History
...
This call will return a JWT (JSON Web Token) in the response in the Authorization header according to the bearer scheme, this token has to be used in subsequent calls to provide your authentication details.
Login using the HAL-browser
The HAL browser has been extended to support login in. You can find the login in the navigation where you can enter your credentials. After supplying valid credentials the token will be saved in a cookie and every request will get this token from the cookie and send it in the authorization header.
Pass the token
For DSpace to detect the token it has to be send in the Authorization header with the Bearer schema, that is prepend the token with "Bearer" then leave a space and paste the token.
Authentication Status
The authentication status can be checked by sending your received token to the status endpoint in the Authorization header:
...
curl -v "http://{spring-rest.url}/api/authn/login" -H "Authorization: Bearer eyJhbG...COdbo"
Which will return something like this:
HTTP/1.1 200 OK
Authorization: Bearer eyJhbG...COdbo
Now you can use this new token to continue making authenticated requests.
Configuration properties
The new stateless authentication introduced a few new properties that can be configured, these can all be found under modules/authentication.cfg:
jwt.token.secret | Manually define a key here that will be used to sign the tokens. If this is empty a random key will be generated. Note that if you want to run DSpace in a cluster with multiple instances this has to be configured and every instance has to use the same key |
jwt.encryption.enabled | Boolean property, defaults to false. If enabled the tokens will be encrypted and unreadable clientside. As a downside enabling this makes the tokens a bit larger which will make the size of requests a bit larger, another disadvantage is not being able to use the data that is inside the token clientside |
jwt.encryption.secret | Key to use if encryption for jwt is enabled, if none is specified DSpace will generate a random one, but when using clusters and encryption then one should be configured |
jwt.token.expiration | Enter the time in minutes that a token should be valid for, by default this is 30 |
jwt.token.include.ip | Boolean property, if true then the signing key will also use the ip-address of the user, this will prevent the same token from being used from another ip-address. Defaults to true |
Running DSpace in a clustered setup
One of the biggest advantages of this stateless authentication is that we can scale horizontally and run multiple instances of DSpace and be able to send the same token to all of them. To do so a few properties have to be configured:
jwt.token.secret: This property has to be the same on every instance of DSpace. It's best to choose a long, non trivial one for extra security.
if jwt.encryption.enabled is set to true then jwt.encryption.secret also has to be configured and the same key has to be used on every instance.
Construction of signing key
The signing key of the tokens is constructed by
- a random generated salt per user +
- The jwt.token.secret or a random one if empty +
- The ip-address of the user is jwt.token.include.ip = true
The salt is saved in the EPerson table in the database and is used for:
Invalidating tokens: When someone logs out the salt will be removed from the database, so that the token won't be valid anymore since the sign key can't be constructed anymore
Making sure the signing key has a valid length: The salt is always 32 bytes and the key to sign is required to be >32 bytes