You can configure Fusion Server to use JSON Web Tokens (JWTs) for user authentication and authorization. Fusion can also use a shared secret key between the issuer and Fusion to encrypt the JWT payload.
How the JWT realm works
A JWT is comprised of three distinct parts: the header, payload, and signing key. Each of these parts are separately encoded using Base64url encoding.
-
The header identifies the algorithm used to generate the token.
Fusion uses both the HS256 and RS256 signature algorithms.
-
The payload consists of data that will be passed with the token.
-
The signing key validates the integrity of the token by using a “secret” to ensure the header and payload being submitted in the token match the header and payload stored in the signing key.
Within Fusion, the JWT realm uses an authorization header in the request to authenticate the user and the data inside the JWT token for the authorization. This authorization header uses the following format:
Upon receiving the authorization header, Fusion authenticates the token and emits a response accordingly.
Create a JWT token
Using the tool you use to validate users, create a JWT token. The token requires the following properties:
iss: Issuer value. If the issuer value does not match the value configured in Fusion, the user will be denied access.
iat: A JSON numeric date value. This value is calculated by counting the number of seconds between 1970-01-01T00:00:00Z UTC and the specified UTC date/time, ignoring leap seconds.
sub: Subject. The name/id of the user. The user is logged in by this name.
groups: The groups from the group-role mappings that this user belongs to. The groups key should match the one you specify while creating the JWT realm.
Example data inside token:
Create the Fusion JWT realm
To create a Fusion realm, in the Fusion UI:
- Click System > Access Control.
- Click the Security Realms tab, then Add Security Realm.
- Enter a realm name. Under type, select jwt.
- Create the security realm with the following values:
- Click Save.
Validate the new realm
When you send a request to Fusion, you should receive a response. The request to Fusion looks like this:
Bearer is case sensitive.
If no signing key is used, truncate the JWT to read … Bearer <token-header>.<token-payload>..
Enable diagnostic logs for debugging
-
Navigate to your Fusion home directory, then open the conf folder.
-
Edit the file
proxy-log4j2.xml.
-
In the
<Loggers> element, add the following:
-
Restart proxy for this change to take effect:
bin/proxy restart
Now var/log/proxy/proxy.log will show some diagnostic logs to help you troubleshoot your issues.
Resources
JWT.io is an excellent resource for learning about JWT, creating tokens, debugging tokens, and more.
Example of generating a JWT using PyJWT
Typically, you will generate your JWT token from the application you are integrating with Fusion APIs.
This example, however, uses Python to create a JWT token with the PyJWT Python egg.
-
Install the PyJWT egg:
-
Inside a Python console, run the following command using your realm configurations:
A Bearer token will be printed for use in API requests:
-
You can now use this as a bearer token in an authorization header to authenticate to Fusion.
Test your Fusion API web service call with cURL. For example, if your role is an administrator, call: