This guide shows how to configure Resource-Aware Authorization in Mosaic and how to request it on a token. For how the model works, see How authorization works.
If you already use tenant-wide resources, migrate them to the new authorization model. See Migrate from tenant-wide resources.
Applying the model has four stages:
- Build the model: Create one inventory of resources, scopes, permissions, and roles for each Mosaic application. (Steps 1-3)
- Assign authorization: Assign resources and scopes to clients, and assign roles to users. (Steps 4-5)
- Authorize the request: The client requests a resource and scopes. Mosaic returns an access token that contains only the authorization granted for that request. (Step 6)
- Enforce authorization: Your API validates the token and checks the audience, scope, and permissions before it performs an action. (Step 7)
When you create a Mosaic app, it has no access controls configured. You can sign users in before you create resources, permissions, or custom scopes. Mosaic still returns access tokens and these tokens include basic authorization:
audisuserid-api.- Token lifetimes come from the client's token timeout settings.
- Reserved scopes that the client requests, such as
openid, are included.
If this is your first time integrating with Mosaic, create a Mosaic application in the Admin Portal as described here and add an OIDC-based User authentication client skipping resource and scope selection (see Configure OIDC clients), then implement a login for your app.
Before you create anything in the Admin Portal, decide what the application needs to protect and who may do what.
- List the APIs that need their own token. Each API is a resource.
- List the actions a user may perform. An action that belongs to one API is a permission on that resource. An action that applies no matter which API is called is a global permission.
- List the privileges a client may request. Each privilege is a scope, either global or owned by one resource.
- Group the permissions into user roles.
- Decide which clients may request each resource, and which scopes each client may receive.
You can create resources and scopes and leave them unassigned but a client cannot request scopes and resources it doesn't have.
Example: an online store
| Item | What you will create |
|---|---|
| Resources | Shopping cart (https://api.shop.example/cart), Payments (https://api.shop.example/payments), and Inventory (https://api.shop.example/inventory) |
| Global permission | browse-store, so a user can browse the catalog on any token |
| Global scope | store:browse, so the client can request catalog access with any resource |
| Shopping cart permissions | create-cart, update-cart, delete-cart, checkout-cart |
| Shopping cart scopes | cart:read, cart:write, cart:checkout |
| Payments permissions | view-payment, approve-payment |
| Payments scopes | payments:read, payments:approve |
| Roles | Shopper and Store manager |
| Storefront client | Shopping cart and Payments, not Inventory. Scopes store:browse, cart:read, cart:write, cart:checkout, and payments:read |
In this example, payments:approve stays off the storefront client. Inventory is created so a later request can ask for a resource the storefront is not assigned.
In the Admin Portal, navigate to your Mosaic app > Access Control > Resources. Create one resource for each API you identified. When creating a resource, add the permissions and scopes that belong to that resource before you save. A permission or scope created here is owned by the resource. Under Session management, set how long access to this resource lasts–use a shorter access token for a more sensitive resource:
- Access token expiration
- Refresh token expiration. Won't apply if the authorization request includes two or more resources. In this case, refresh token expiration time derives from the client settings.
- Session expiration, the maximum period of time the refresh token can be rotated for this resource. Won't apply if the authorization request includes two or more resources. In this case, maximum rotation time derives from the client settings.
Create global permissions from Access Control > Permissions, and leave them unassigned to a resource. A global permission can appear on a token for any API.
Create global scopes from Access Control > Scopes, and leave them unassigned to a resource. A client can request a global scope with any resource.
Example: an online store
Create the shopping cart resource:
| Field | Value |
|---|---|
| Resource name | Shopping cart |
| Resource URI | https://api.shop.example/cart |
| Access token expiration | 3600 (1 hour) |
| Refresh token expiration | 1209600 (14 days) |
| Session expiration | 2592000 (30 days) |
| Permissions | create-cart, update-cart, delete-cart, checkout-cart |
| Scopes | cart:read, cart:write, cart:checkout |
Save the resource, then create the payments resource the same way:
| Field | Value |
|---|---|
| Resource name | Payments |
| Resource URI | https://api.shop.example/payments |
| Access token expiration | 900 (15 minutes) |
| Refresh token expiration | 86400 (1 day) |
| Session expiration | 86400 (1 day) |
| Permissions | view-payment, approve-payment |
| Scopes | payments:read, payments:approve |
Create the inventory resource with no permissions or scopes. It won't be assigned to the storefront client.
| Field | Value |
|---|---|
| Resource name | Inventory |
| Resource URI | https://api.shop.example/inventory |
| Access token expiration | 28800 (8 hours) |
| Refresh token expiration | 604800 (7 days) |
| Session expiration | 604800 (7 days) |
Create browse-store from Access Control > Permissions.
Create store:browse from Access Control > Scopes.
Navigate to Access Control > Roles. Create each role and select permissions from the inventory. The role references permissions that already exist. A role can reference global permissions and resource-specific permissions.
Example: an online store
| Role | Permissions |
|---|---|
| Shopper | browse-store, create-cart, update-cart, checkout-cart, view-payment |
| Store manager | browse-store, create-cart, update-cart, delete-cart, checkout-cart, view-payment, approve-payment |
- In your Mosaic app settings, proceed to the Clients tab and expand settings for a client that represents your app (OIDC-based user authentication client).
- In Access Control, assign the resources that client may request, and assign the scopes it may request. A resource-specific scope can be assigned only when its resource is also assigned to the client. You do not have to assign every resource in the application.
Example: an online store
Open the storefront client. Assign the Shopping cart and Payments resources. Do not assign Inventory. Assign the scopes the client may request: store:browse, cart:read, cart:write, cart:checkout, and payments:read.
Leave payments:approve unassigned.
Assign each role to the users who should have it. A user access token includes the permissions from the roles assigned to that user, limited to the resource that was requested. The roles claim lists every role assigned to the user.
Example: an online store
Assign the Shopper role to each shopper, and the Store manager role to each store manager.
The authorization request is where the client states the access it wants. The client sends resource and scope to Mosaic together with the other parameters of the flow, completes the flow, and receives tokens. In the authorization code flow, that means exchanging the authorization code for tokens.
You can send resource and scope on these flows:
- Authorization code, including PKCE and PAR
- CIBA
- Device authorization
- Client credentials, for a client access token. That token has no user permissions or roles.
- Token exchange, to retarget an existing user token at another resource. Mosaic recomputes the scope and permissions for that resource, and never grants
openidoroffline_access. - Token refresh, to exchange a refresh token for an access token for another resource from the same authorization request.
You can send resource on these flows utilizing Mosaic authentication APIs:
- OIDC-based Password login and backend-initiated Password login
- OIDC-based Email magic link login and backend-initiated Email magic link login
- OIDC-based Email OTP login and backend-initiated Email OTP login
- TOTP login
- Mobile biometrics
- etc.
The example below uses the authorization code flow. SCOPE is the URL-encoded list of scopes, and RESOURCE_URI is the URL-encoded resource URI. Repeat resource to request more than one resource.
Mosaic checks each requested resource before the user logs in. If one is not assigned to the client, Mosaic redirects to the redirect URI with the invalid_target error.
https://api.transmitsecurity.io/cis/oidc/auth?
client_id=CLIENT_ID&
scope=openid%20SCOPE&
response_type=code&
redirect_uri=REDIRECT_URI&
resource=RESOURCE_URIIf every requested resource is assigned, the token request to /oidc/token must specify a resource–pick one of the initially resources. If the initial request included one resource, it can be omitted at the token request. The aud always targets a single resource.
curl -i -X POST \
https://api.transmitsecurity.io/oidc/token \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d grant_type=authorization_code \
-d client_id=CLIENT_ID \
-d client_secret=CLIENT_SECRET \
-d code=CODE \
-d redirect_uri=REDIRECT_URI \
-d resource=RESOURCE_URIUpon a code exchange (oidc/token), Mosaic returns a user access token that includes:
audis the one resource picked on the token request.scopelists the requested scopes Mosaic granted: reserved scopes such asopenid, global scopes assigned to the client, and resource-specific scopes that belong to the requested resource and are assigned to the client. When the flow includes a consent screen, the user has to consent to granting these scopes as well.permissionslists the global permissions on the user's roles, plus the resource-specific permissions on those roles that belong to the requested resource. Requested scopes do not filter permissions.roleslists every role assigned to the user.
For first-party clients, Mosaic omits a scope that belongs to another resource, a scope that is not assigned to the client, and a permission the user's roles do not include for that resource. In case of third-party clients, Mosaic denies the request entirely if one of the requested scopes cannot be granted in a token or the user didn't consent to requested scopes. Step 7 describes how your API checks these claims.
Exchange the refresh token to obtain an access token for another resource from that authorization request. See Refresh app's access.
curl -i -X POST \
https://api.transmitsecurity.io/oidc/token \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d grant_type=refresh_token \
-d client_id=CLIENT_ID \
-d client_secret=CLIENT_SECRET \
-d refresh_token=REFRESH_TOKEN \
-d resource=RESOURCE_URIExample: an online store
A shopper signs in through the storefront. The authorization request asks for the shopping cart and inventory resources. The inventory resource is not assigned to the storefront.
https://api.transmitsecurity.io/cis/oidc/auth?
client_id=CLIENT_ID&
scope=openid%20store:browse%20cart:read&
response_type=code&
redirect_uri=REDIRECT_URI&
resource=https%3A%2F%2Fapi.shop.example%2Fcart&
resource=https%3A%2F%2Fapi.shop.example%2FinventoryMosaic redirects to the redirect URI with invalid_target before the shopper logs in. No token is issued.
A later authorization request asks for the shopping cart and payments resources. Both are assigned to the storefront. The request includes store:browse, cart:read, cart:write, payments:read, and payments:approve. openid is included because this is a user login. offline_access is included so Mosaic can return a refresh token. It is a reserved scope, so Mosaic grants it without an assignment on the client. Set prompt to consent, which is required to obtain a refresh token.
https://api.transmitsecurity.io/cis/oidc/auth?
client_id=CLIENT_ID&
scope=openid%20offline_access%20store:browse%20cart:read%20cart:write%20payments:read%20payments:approve&
response_type=code&
prompt=consent&
redirect_uri=REDIRECT_URI&
resource=https%3A%2F%2Fapi.shop.example%2Fcart&
resource=https%3A%2F%2Fapi.shop.example%2FpaymentsThe code exchange at /oidc/token must pick one of those resources. This exchange picks the shopping cart resource:
curl -i -X POST \
https://api.transmitsecurity.io/oidc/token \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d grant_type=authorization_code \
-d client_id=CLIENT_ID \
-d client_secret=CLIENT_SECRET \
-d code=CODE \
-d redirect_uri=REDIRECT_URI \
-d resource=https://api.shop.example/cartMosaic returns a user access token that includes:
| Claim | Value |
|---|---|
aud | https://api.shop.example/cart |
scope | openid offline_access store:browse cart:read cart:write |
permissions | browse-store, create-cart, update-cart, checkout-cart |
roles | Shopper |
store:browse is included because it is a global scope assigned to the storefront and the client requested it. browse-store and checkout-cart are included from the Shopper role. checkout-cart was not sent in the request. Requested scopes do not filter permissions.
The token leaves out what this client or this shopper cannot have. payments:read and payments:approve are not in scope, because they belong to the payments resource, not the shopping cart resource that was granted. delete-cart, approve-payment, and view-payment are not in permissions. The cart API accepts this token. The payments API and the inventory API reject it.
The payments resource was also on the authorization request. Exchange the refresh token from this login to obtain an access token for that resource:
curl -i -X POST \
https://api.transmitsecurity.io/oidc/token \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d grant_type=refresh_token \
-d client_id=CLIENT_ID \
-d client_secret=CLIENT_SECRET \
-d resource=https://api.shop.example/payments \
-d refresh_token=REFRESH_TOKENMosaic returns an access token for the payments resource:
| Claim | Value |
|---|---|
aud | https://api.shop.example/payments |
scope | openid offline_access store:browse payments:read |
permissions | browse-store, view-payment |
roles | Shopper |
payments:read is included because it belongs to the payments resource, it is assigned to the storefront, and the authorization request included it. payments:approve is not in scope, because it is not assigned to the storefront client. The cart scopes and cart permissions are absent because they belong to the shopping cart resource. The payments API accepts this token. The cart API and the inventory API reject it.
The same shopper can also start a new authorization request that asks only for the payments resource, with the scopes store:browse, payments:read, cart:read, and payments:approve:
https://api.transmitsecurity.io/cis/oidc/auth?
client_id=CLIENT_ID&
scope=openid%20store:browse%20payments:read%20cart:read%20payments:approve&
response_type=code&
redirect_uri=REDIRECT_URI&
resource=https%3A%2F%2Fapi.shop.example%2FpaymentsMosaic returns:
| Claim | Value |
|---|---|
aud | https://api.shop.example/payments |
scope | openid store:browse payments:read |
permissions | browse-store, view-payment |
roles | Shopper |
cart:read is not in scope, because it belongs to the shopping cart resource. payments:approve is not in scope, because it is not assigned the storefront client. The cart permissions are absent because they belong to the shopping cart resource. The payments API accepts this token. The cart API and the inventory API reject it.
Client access tokens, such as tokens from the client credentials grant, follow the same audience and scope rules but exclude permissions or roles, because those come from roles assigned to a user.
A client credentials request sends resource and scope to /oidc/token. SCOPE is the space-separated list of scopes, and RESOURCE_URI is the resource URI. A request to /oidc/token specifies one resource value. There is no authorization code to exchange.
curl -i -X POST \
https://api.transmitsecurity.io/oidc/token \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d grant_type=client_credentials \
-d client_id=CLIENT_ID \
-d client_secret=CLIENT_SECRET \
-d resource=RESOURCE_URI \
-d scope=SCOPEExample: an online store
A client credentials request for the storefront asks for the shopping cart resource and the scopes store:browse, cart:read, and payments:approve:
curl -i -X POST \
https://api.transmitsecurity.io/oidc/token \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d grant_type=client_credentials \
-d client_id=CLIENT_ID \
-d client_secret=CLIENT_SECRET \
-d resource=https://api.shop.example/cart \
-d scope='store:browse cart:read payments:approve'Mosaic returns a client access token that includes:
| Claim | Value |
|---|---|
aud | https://api.shop.example/cart |
scope | store:browse cart:read |
payments:approve is not in scope, because it belongs to the payments resource. The token does not include permissions or roles. The cart API accepts this token. The payments API and the inventory API reject it.
Validate the access token before you use it. After validation succeeds, your API decides whether this call is allowed.
On each call, check all of the following. Reject the call if any check fails:
audis this API's resource URI. Reject a token issued for another resource.scopeincludes the scope for this operation. A scope says the client may call the operation.permissionsincludes the permission for this action. A permission says this user may perform the action. A requested scope does not replace this check.
Do not authorize from roles alone. That claim lists every role assigned to the user, including roles that reference other resources. Use permissions for the decision.
A client access token has no user. Check aud and scope only.
Example: an online store
Starting checkout on the cart API requires:
audofhttps://api.shop.example/cartscopeincludescart:checkoutpermissionsincludescheckout-cart
A cart token is rejected by the payments API and the inventory API, because aud is not their resource URI. A payments token that includes view-payment can view a payment. It cannot approve one unless permissions also includes approve-payment.
Tenant-wide resources and the APIs that manage them are being deprecated. Create resources in the Mosaic applications, and verify your integrations use a new model.
For your convenience, Mosaic has automatically migrated tenant-wide resources to the application level, with the resource naming preserved. In the Admin Portal, navigate to the Mosaic apps > Access Control > Resources to confirm required resources are present. If an app-level resource is missing:
- Create an application resource for each tenant-wide resource your integration still uses. See Step 2.
- Assign each new resource to the clients that should receive tokens for it. See Step 4.
- Update authorization requests to send the new resource URI as
resource. See Step 6. - Update Mosaic API calls that pass resource IDs. Send the ID of the application resource, not the tenant-wide resource. For example, Create client takes those IDs in
resources.