Skip to content

How authorization works

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.

Example: an online store

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.

sign in

sign in

client access token:
aud: api.shop.example/cart
scope: store:browse cart:read

user access token:
aud: api.shop.example/cart
scope: store:browse cart:read
roles: Shopper
permissions: browse-store, checkout-cart

user access token:
aud: api.shop.example/payments
scope: payments:read
roles: Store manager
permissions: approve-payment

Backend: Online store application

Shopping cart API
assigned to the storefront

Payments API
assigned to the storefront

Inventory API
not assigned

auth

token

Storefront
client

Mosaic

User with role: Shopper

User with role: Manager

sign in

sign in

client access token:
aud: api.shop.example/cart
scope: store:browse cart:read

user access token:
aud: api.shop.example/cart
scope: store:browse cart:read
roles: Shopper
permissions: browse-store, checkout-cart

user access token:
aud: api.shop.example/payments
scope: payments:read
roles: Store manager
permissions: approve-payment

Backend: Online store application

Shopping cart API
assigned to the storefront

Payments API
assigned to the storefront

Inventory API
not assigned

auth

token

Storefront
client

Mosaic

User with role: Shopper

User with role: Manager

Resources

Deprecation notice

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:

ResourceURIExpiration
Shopping carthttps://api.shop.example/cartAccess token 1 hour
Refresh token 14 days
Session 30 days
Paymentshttps://api.shop.example/paymentsAccess token 15 minutes
Refresh token 1 day
Session 1 day
Inventoryhttps://api.shop.example/inventoryAccess 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.

Permissions

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:

PermissionAction
browse-storeBrowse the store catalog

The shopping cart resource owns these permissions:

PermissionAction
create-cartCreate a cart
update-cartAdd, change, or remove items in a cart
delete-cartDelete a cart
checkout-cartStart checkout for a cart

The payments resource owns these permissions:

PermissionAction
view-paymentView a payment
approve-paymentApprove a payment

User roles

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:

RoleGlobal permissionsShopping cart permissionsPayments permissions
Shopperbrowse-storecreate-cart, update-cart, checkout-cartview-payment
Store managerbrowse-storecreate-cart, update-cart, delete-cart, checkout-cartview-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.

Scopes

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.

Note

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:

ScopeWhat the client may request
store:browseBrowse the store catalog

The shopping cart resource owns these scopes:

ScopeWhat the client may request
cart:readRead a cart
cart:writeCreate or update a cart
cart:checkoutStart checkout

The payments resource owns these scopes:

ScopeWhat the client may request
payments:readRead payments
payments:approveApprove 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.

How claims are issued in tokens

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.

ClaimDescription
audLists the resource URI the token is intended for. If the authorization request does not include a resource, this is userid-api.
scopeLists scopes that are assigned to the client:
  • Global scopes assigned to the client.
  • Resource-specific scopes assigned to the client, when they belong to the requested resource.
For first-party clients, Mosaic ignores any other requested scope, and resource-specific scopes that belong to a different resource. For third-party clients, requesting an unassigned scope, or a resource-specific scope of another resource, fails the request entirely. If the request does not include a resource, only global scopes are considered. When the flow includes a consent screen, the user must also have consented to requested scopes.
permissionsOn a user access token, lists:
  • Global permissions from the user's roles.
  • Resource-specific permissions from those roles that belong to the requested resource.
Permissions that belong to other resources are omitted. If the request does not include a resource, only global permissions are included.
rolesLists the user's roles. It is not filtered by resource.
Note

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.

Example: User access token

Auth request for the payments resource

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:

ClaimValue
audhttps://api.shop.example/payments
scopestore:browse payments:read
permissionsbrowse-store, view-payment
rolesShopper

The token includes:

  • aud is included and set to https://api.shop.example/payments because the client requested this resource and it is assigned to this client.
  • store:browse is included because it is a global scope assigned to the storefront client and the client requested it.
  • payments:read is included because it belongs to the payments resource, it is assigned to the storefront client, and the client requested it.
  • browse-store is included because it is a global permission on the Shopper role.
  • view-payment is 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:read is not in scope, because that scope belongs to the shopping cart resource. It is not a scope of the payments resource that was requested.
  • payments:approve is not in scope, because that scope is not assigned to the storefront client.
  • create-cart, update-cart, and checkout-cart are not in permissions, because they belong to the shopping cart resource.
  • delete-cart and approve-payment are not in permissions, because the Shopper role does not include them.

The payments API accepts this token. The cart API and the inventory API reject it.

Auth request with two assigned resources

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:

ClaimValue
audhttps://api.shop.example/cart
scopestore:browse cart:read cart:write
permissionsbrowse-store, create-cart, update-cart, checkout-cart
rolesShopper

The token includes:

  • aud is https://api.shop.example/cart because the token request picked that resource. aud includes one resource.
  • store:browse is 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-store is included because it is a global permission on the Shopper role.
  • checkout-cart is 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:approve is not in scope, because that scope belongs to the payments resource. It is not a scope of the shopping cart resource that was requested.
  • delete-cart and approve-payment are not in permissions, because the Shopper role does not include them. A store manager's token for the shopping cart resource would include delete-cart.
  • https://api.shop.example/payments is not in aud, because the token can only target a single resource and teh cart resource was picked at the token request.
  • view-payment and payments:read are also absent because belong to the payments resource.

The cart API accepts this token. The payments API and the inventory API reject it.

Unassigned resource

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.

Example: Client access token

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:

ClaimValue
audhttps://api.shop.example/cart
scopestore:browse cart:read

The token includes:

  • aud is included and set to https://api.shop.example/cart because the client requested this resource and it is assigned to this client.
  • store:browse is included because it is a global scope assigned to the storefront client and the client requested it.
  • cart:read is 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:approve is not in scope, 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.

Next steps

Configure the store in the Admin Portal and send these requests in Implement the authorization model.