This article describes the concepts in Resource-Aware Authorization and how Mosaic places them on user and client access tokens. For an introduction and the benefits of the model, see Authorization.
The sections below use an online store example to show how the model works.
The store exposes three APIs in one application: a shopping cart API, a payments API, and an inventory API. Shoppers and store managers sign in through a storefront client. The storefront may call the shopping cart API and the payments API. It is not assigned the inventory API. Each access token is issued for one resource, so a token for the cart API cannot be presented to the payments API.
Tenant-wide resources and the APIs that manage them are being deprecated. Define resources in the Mosaic application, as described in this article.
A resource is a protected API or service in your end-user application. Each resource has a URI. You assign a resource to the clients that should receive tokens for it. A resource can own permissions and scopes that apply only when that resource is requested.
You assign a resource to the clients that are allowed to request it. A resource also controls how long access to that resource lasts:
- Access token expiration (seconds)
- Refresh token expiration (seconds)
- Session expiration (seconds), the absolute lifetime of the refresh token, after which it cannot be rotated
Requesting a resource is optional. If the authorization request does not include one, Mosaic uses a default resource. Token lifetimes for that default resource come from the client's token timeout settings: Access token expiration, Refresh token expiration, and Max refresh time (the client's Access Control settings). By default, the access token expires after 1 hour, the refresh token expires after 14 days. If you change those client settings, a request that omits resource uses the values you set.
If the authorization request includes two or more resources, the refresh token expiration and max rotation also come from the client's token timeout settings, rather than the resource settings. In this case, only the access token expiration comes from the resource.
Example: In the store, the resources are:
| Resource | URI | Expiration |
|---|---|---|
| Shopping cart | https://api.shop.example/cart | Access token 1 hour Refresh token 14 days Session 30 days |
| Payments | https://api.shop.example/payments | Access token 15 minutes Refresh token 1 day Session 1 day |
| Inventory | https://api.shop.example/inventory | Access token 8 hours Refresh token 7 days Session 7 days |
The shopping cart and payments resources are assigned to the storefront client, so the storefront can request tokens for them. The payments API can use a shorter access token than the shopping cart API.
The inventory resource is not assigned, so Mosaic rejects a storefront request for it.
A permission is an action a user is allowed to perform. Permissions are defined in the Mosaic application. User roles reference those permissions, and you assign the roles to users.
A permission is either global or owned by one resource:
- A global permission is not tied to a resource. It can appear in a token no matter which resource was requested.
- A resource-specific permission belongs to one resource. It appears in a token only when that resource was requested.
Each permission has a system-generated ID, a mandatory value, and an optional description. The value is what your API checks. Values are unique across the Mosaic application, including global permissions and permissions on every resource. The same value cannot exist both as a global permission and on a resource, or on two resources.
You choose global or resource-specific when you create the permission. That association does not change later. To move a permission, create a new one and update the roles that reference it.
Example: The store defines this global permission. It is not owned by the shopping cart or the payments resource, so it can appear on a token for either API:
| Permission | Action |
|---|---|
browse-store | Browse the store catalog |
The shopping cart resource owns these permissions:
| Permission | Action |
|---|---|
create-cart | Create a cart |
update-cart | Add, change, or remove items in a cart |
delete-cart | Delete a cart |
checkout-cart | Start checkout for a cart |
The payments resource owns these permissions:
| Permission | Action |
|---|---|
view-payment | View a payment |
approve-payment | Approve a payment |
A user role is a named set of permissions. A role can reference global permissions and resource-specific permissions from any resource in the Mosaic application. The same permission can belong to more than one role. A user can have more than one role, and the user's permissions are the union of the permissions on those roles.
After the user signs in, your application reads two claims on the user access token. The roles claim lists every role assigned to the user, including roles that reference other resources. The permissions claim lists only the permissions that apply to the resource the client requested: global permissions on those roles, plus permissions owned by that resource. The same role can appear on a shopping cart token and on a payments token. See Role-based access control.
Example: In the store, the roles reference permissions as follows:
| Role | Global permissions | Shopping cart permissions | Payments 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 a B2B application, member roles are also bundled into role groups, and those groups are assigned to organizations. See Define app roles and Create app role groups.
A scope is a privilege that a client can request. Scopes are defined at the Mosaic application level and assigned to clients. For a scope to be included in the access token, it must be:
- Assigned to the client.
- Requested by the client in the authorization request.
- If the authentication flow includes a consent screen for third-party clients, approved by the user. The user consents to all requested scopes at once.
A custom scope is either global or owned by one resource:
- A global custom scope is not tied to a resource. A client can request it with any resource, or with no resource.
- A resource-specific custom scope belongs to one resource. A client can request it only together with that resource. You can assign it to a client only when that resource is also assigned to the client.
Scope values are case-sensitive and unique across the Mosaic application, including global scopes and scopes on every resource. The association with a resource is set when you create the scope and does not change later.
Reserved OAuth and OIDC scopes (openid, profile, email, address, phone, and offline_access) are granted to every client. They are not custom scopes, and you cannot create a custom scope with one of these values. If the client requests a reserved scope, Mosaic includes it in the token.
A scope and a permission answer different questions. A scope says the client is allowed to call an operation. A permission says this user is allowed to perform the action. Your API should check both before it acts.
Example: The store defines this global scope. It is not owned by the shopping cart or the payments resource, so the client can request it with either API:
| Scope | What the client may request |
|---|---|
store:browse | Browse the store catalog |
The shopping cart resource owns these scopes:
| Scope | What the client may request |
|---|---|
cart:read | Read a cart |
cart:write | Create or update a cart |
cart:checkout | Start checkout |
The payments resource owns these scopes:
| Scope | What the client may request |
|---|---|
payments:read | Read payments |
payments:approve | Approve a payment |
The storefront client is assigned store:browse, cart:read, cart:write, cart:checkout, and payments:read. It is not assigned payments:approve, so a request for that scope does not add it to the token.
In the store, starting checkout requires the cart:checkout scope on the token and the checkout-cart permission for the user.
The claims in an access token define the access that was granted. Which claims Mosaic includes depends on the authorization request.
The authorization request can include several resources and a list of scopes. If at least one of the requested resources is not assigned to the client, Mosaic redirects back with invalid_target error. If every requested resource is assigned, the client completes the flow at /oidc/token by picking one of those initially requested resources. A later refresh token request can obtain an access token for another resource from that authorization request (see Refresh app's access). Mosaic grants a requested scope only when that scope is assigned to the client. Resource-specific scopes are granted only if the resource who owns them is also requested. When the flow includes a consent screen, the user must also have consented to the requested scopes. On a user access token, Mosaic derives permissions from the roles assigned to the user.
| Claim | Description |
|---|---|
aud | Lists the resource URI the token is intended for. If the authorization request does not include a resource, this is userid-api. |
scope | Lists scopes that are assigned to the client:
|
permissions | On a user access token, lists:
|
roles | Lists the user's roles. It is not filtered by resource. |
The permissions and scopes authorize calls to your APIs. They are separate from client roles, which control access to Mosaic APIs and appear on client access tokens as ts_permissions.
The same shopper later needs to view a payment. The storefront requests the payments resource and the scopes store:browse, payments:read, cart:read, and payments:approve. The payments resource is assigned to the storefront client. The storefront client is assigned payments:read. It is not assigned payments:approve.
Mosaic issues a user access token that includes:
| Claim | Value |
|---|---|
aud | https://api.shop.example/payments |
scope | store:browse payments:read |
permissions | browse-store, view-payment |
roles | Shopper |
The token includes:
audis included and set tohttps://api.shop.example/paymentsbecause the client requested this resource and it is assigned to this client.store:browseis included because it is a global scope assigned to the storefront client and the client requested it.payments:readis included because it belongs to the payments resource, it is assigned to the storefront client, and the client requested it.browse-storeis included because it is a global permission on the Shopper role.view-paymentis included because it belongs to the Shopper role and to the payments resource.- The requested scopes do not filter permissions.
- The Shopper role is listed in
roles.
The token does not include what the request asked for but either client or the shopper cannot have:
cart:readis not inscope, because that scope belongs to the shopping cart resource. It is not a scope of the payments resource that was requested.payments:approveis not inscope, because that scope is not assigned to the storefront client.create-cart,update-cart, andcheckout-cartare not inpermissions, because they belong to the shopping cart resource.delete-cartandapprove-paymentare not inpermissions, because the Shopper role does not include them.
The payments API accepts this token. The cart API and the inventory API reject it.
The storefront requests the shopping cart resource, https://api.shop.example/cart, and the payments resource, https://api.shop.example/payments. Both resources are assigned to the storefront client. The request also includes the custom scopes store:browse, cart:read, cart:write, payments:read, and payments:approve.
The token request to /oidc/token picks the shopping cart resource and issues a user access token that includes:
| Claim | Value |
|---|---|
aud | https://api.shop.example/cart |
scope | store:browse cart:read cart:write |
permissions | browse-store, create-cart, update-cart, checkout-cart |
roles | Shopper |
The token includes:
audishttps://api.shop.example/cartbecause the token request picked that resource.audincludes one resource.store:browseis included because it is a global scope assigned to the storefront client and the client requested it. It is also included on the payments token.browse-storeis included because it is a global permission on the Shopper role.checkout-cartis included because it belongs to the Shopper role and to the shopping cart resource.- The requested scopes do not filter permissions.
- The Shopper role is listed in
roles.
The token does not include what the request asked for but either client or the shopper cannot have:
payments:approveis not inscope, because that scope belongs to the payments resource. It is not a scope of the shopping cart resource that was requested.delete-cartandapprove-paymentare not inpermissions, because the Shopper role does not include them. A store manager's token for the shopping cart resource would includedelete-cart.https://api.shop.example/paymentsis not inaud, because the token can only target a single resource and teh cart resource was picked at the token request.view-paymentandpayments:readare also absent because belong to the payments resource.
The cart API accepts this token. The payments API and the inventory API reject it.
The storefront requests the shopping cart resource, https://api.shop.example/cart, and the inventory resource, https://api.shop.example/inventory. The shopping cart resource is assigned to the storefront client while the inventory resource is not. Mosaic checks the requested resources before the shopper logs in and denies a request.
A client access token, such as a token from the client credentials grant, follows the same audience and scope rules. It does not include user permissions or user roles, because those come from roles assigned to a user.
Client credentials request: The storefront requests the shopping cart resource, https://api.shop.example/cart, and the scopes store:browse, cart:read, and payments:approve. The shopping cart resource is assigned to the storefront client.
Mosaic issues a client access token that includes:
| Claim | Value |
|---|---|
aud | https://api.shop.example/cart |
scope | store:browse cart:read |
The token includes:
audis included and set tohttps://api.shop.example/cartbecause the client requested this resource and it is assigned to this client.store:browseis included because it is a global scope assigned to the storefront client and the client requested it.cart:readis included because it belongs to the shopping cart resource, it is assigned to the storefront client, and the client requested it.
The token does not include what the request asked for but the client cannot have:
payments:approveis not inscope, because that scope belongs to the payments resource. It is not a scope of the shopping cart resource that was requested.
The token does not include permissions or roles.
The cart API accepts this token. The payments API and the inventory API reject it.
Configure the store in the Admin Portal and send these requests in Implement the authorization model.