Before writing a complete application with authorization, you might like to walk through how tokens are issued, how to configure The Usher, etc. If so, take a look at QUICKSTART.
An application leveraging The Usher for Authorization will usually have four components:
- a client application (web app, mobile app, desktop app)
- a backend resource API/server
- an identity provider service
- an instance of The Usher
The client application manages the login, forwarding the unauthenticated user to the identity provider, uses the IdP token to obtain an access token from The Usher, and then accesses the secured backend resource. You could do all these steps manually using an HTTP client like cURL or Postman. Note that information in the client itself isn't considered secured, as anyone could access that content by viewing source, disabling JavaScript, and/or decompiling. So, any content or service that you wish to secure should be stored in the backend API.
Note that you could run all of these components locally on your workstation. However we don't have an identity provider implementation, so you'll probably want to rely on something like Auth0 or Azure AD. We have used Auth0 during development and it supports redirects to localhost.
- Make sure to have an instance of The Usher up and running somewhere.
- [CONFIG] Decide if you wish to have The Usher validate the
audience
claim of the IdP tokens that the client application will pass to it. If not, removeTHEUSHER_AUD_CLAIMS
from The Usher's .env file. - If you opt for validating the IdP
audience
claim, generate a string for this. It could simply be the URL of The Usher's instance. Configure it, possibly including localhost if testing locally, asTHEUSHER_AUD_CLAIMS=https://us-central1-dmgt-oocto.cloudfunctions.net/the-usher,http://localhost:3001
. The value can be a comma-separated list of URLs.
- [CONFIG] Decide if you wish to have The Usher validate the
- Set up your identity provider with at least 1 user. This user could be set up with SSO or via a password database in your identity provider. Determine their
sub_claim
. (In Auth0 this might look likeauth0|5e5feabeb087080ddea78663
).- If using Auth0: Register an API for The Usher, and set its Identifier (the
audience
claim it will put in the IdP tokens) to the claim The Usher expects. - Also, note the Token Expiration (seconds) Setting attribute within Auth0 / IdP as this will serve as the maximum value for the Refresh Token window (ceiling of this value or
SESSION_LIFETIME_SECONDS
).
- If using Auth0: Register an API for The Usher, and set its Identifier (the
- Into The Usher's PostgreSQL database, insert information about your tenant, personas, roles and permissions.
- Tenant information: include the JWKS URL The Usher will use for IdP token validation (e.g., https://dmgt-prod.auth0.com/.well-known/jwks.json)
- Persona information: include the
sub_claim
for each persona
- Decide on a place to host your client application, and a place to host your backend resource API.
- Write your client application to perform the flow of steps listed below (and/or see the demo client application).
- Write your backend resource API to validate the token from The Usher and check scopes before returning data or performing services.
The general flow for an application that uses The Usher is:
- A user attempts to access an application (henceforth called the
client application
). But the not logged user in (does not have an identity token). - The user is redirected and authenticates with their organization's Identity Provider (IdP).
- The IdP token has a sub claim, and may also have group claims.
- If a portal, the client application may use the IdP token to determine the other client applications to which the user has access by calling The Usher
/self/clients/
endpoint - The client application uses the IdP token and its
client_id
(andclient_secret
) to get anaccess_token
from The Usher via the/self/token
endpoint - The client application will then use the
access_token
to access resources like APIs and backend services. - The client application may use the refresh token to obtain a new access token if necessary (and supported).
For illustrations of specific flows, see the Web Sequence diagrams collected here.
Here is a demo client application illustrating how to request an token from The Usher and use it to access an API.
- Sample Web Client App (source code | deployed to Glitch)
Here is a demo backend resource server API that verifies tokens issued by The Usher, and checks scopes prior to yielding access.
- Sample Backend Resource Server (API) (source code | deployed to Glitch)
(Coming soon)
Roles and permissions can be assigned to personas by inserting it into the database. Examples of inserting sample data can be found in the database/init directory. See the files with "sample" in the filename.
(Coming soon)
The Usher supports an experimental feature to assist with gradually migrating a set of applications to another issuer domain name. This feature is called Issuer Aliases.
As part of branding or refactoring, an organization using The Usher may wish to migrate their identity provider issuer claim to a new claim. Some identity providers, like Auth0, allow to use your own custom branded domain name. If this migration cannot happen at once for all services authorized via The Usher tokens, The Usher will need to simultaneously accept identity provider tokens with two distinct issuer claims.
To use Issuer Aliases, update The Usher's configuration to:
- list the custom domain name in the
ISSUER_WHITELIST
configuration/environment variable - create a dictionary in a new configuration/environment variable called
ISSUER_ALIASES
mapping the new custom domain name(s) to the domain name registered in The Usher's database (tenant
table).
For example, suppose there is an instance of The Usher with a tenant having an iss_claim
of "dmgt-test.auth0.com"
. If an organization were to begin migrating to an iss
claim of "auth.labs.dmgt.com"
, they will configure ISSUER_ALIASES
to be:
{"auth.labs.dmgt.com": "dmgt-test.auth0.com"}
With the above configuration, if a token is presented from identity provider with iss
claim "auth.labs.dmgt.com"
, the JWKS used to validate the signature will be the same as for tokens with iss
claim "dmgt-test.auth0.com"
.
As noted above, for security reasons, the alias must also be whitelisted (listed in ISSUER_WHITELIST
):
["dmgt-test.auth0.com", "auth.labs.dmgt.com"]