OAuth2 Scopes and Presentation Definition Mapping

Scope design

When designing a system that uses OAuth2, you have to decide how scopes map to resources that the client will attempt to access. "Resource access" is typically a specific REST-style HTTP operation on a specific URL, e.g. POST /products/staplers/1. Things to consider when designing scopes are discussed in this section.

Broad v.s. narrow scopes

Broad scopes are generally high level e.g., a scope that gives access to a certain use case or larger group of resources. Narrow scopes are often low-level e.g., a scope that gives read access to a specific resource, limited set of resources or operations. Examples scopes for an employee that's authorized to buy supplies for their employer:

How scopes are mapped to operations on resources influences:

Broad, high-level Scopes

High-level, broad scopes typically give access to an entire use case, service, or group of resources. Checks that are executed before an access token is issued are limited to the Verifiable Credentials the client can present.

A real-life example of a broad scope is the Nuts eOverdracht use case, which specifies the following scopes:

However, when a resource is accessed, the system needs to verify that the scope gives access to the specific resource operation.

This type of scope is supported by the Nuts node.

Narrow, low-level Scopes

Narrow, low-level scopes typically give access to specific operations on specific resources, e.g., reading a specific patient's medical summary.

Narrow scopes with an AuthZen policy decision point are supported from Nuts node v6.3.

The Nuts node supports narrow scopes next to a broad scope. The vendor runs an AuthZen policy decision point (PDP) that decides on them:

Things to consider:

Without a PDP, an access token request can't contain other scopes (profile-only, the default), or the other scopes are granted without checks (passthrough).

Policies: Mapping Scope to Authentication Subject

Due to the ongoing development of personal authentication methods and associated protocols, the Nuts node currently only supports the OAuth2 vp_token grant for production. User authentication via OpenID4VP is experimental and not intended for production. It's still required to pass user claims within the token request if a data exchange contains PII (Personally Identifiable Information) and/or medical data (e.g., Social Security Number or EHR records)

Mapping document

This section contains an example of a presentation definition mapping document as it could be specified by a use case. The Presentation Definition is described more in detail in AuthN using Verifiable Credentials.

{
  "zorgtoepassing": {
    "organization": {
      "format": {
        "ldp_vc": {
          "proof_type": [
            "JsonWebSignature2020"
          ]
        },
        "ldp_vp": {
          "proof_type": [
            "JsonWebSignature2020"
          ]
        },
        "jwt_vc": {
          "alg": [
            "ES256"
          ]
        },
        "jwt_vp": {
          "alg": [
            "ES256"
          ]
        }
      },
      "id": "pd_any_care_organization",
      "name": "Care organization",
      "purpose": "Finding a care organization for authorizing access to medical metadata",
      "input_descriptors": [
        {
          "id": "id_nuts_care_organization_cred",
          "constraints": {
            "fields": [
              {
                "path": [
                  "$.type"
                ],
                "filter": {
                  "type": "string",
                  "const": "NutsOrganizationCredential"
                }
              },
              {
                "id": "organization_name",
                "path": [
                  "$.credentialSubject.organization.name",
                  "$.credentialSubject[0].organization.name"
                ],
                "filter": {
                  "type": "string"
                }
              },
              {
                "id": "organization_city",
                "path": [
                  "$.credentialSubject.organization.city",
                  "$.credentialSubject[0].organization.city"
                ],
                "filter": {
                  "type": "string"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

What the use case decides

The use case's policy file sets, per scope:

How the Nuts node reads the policy file is described in Access Token Policy in the Nuts node documentation. That covers the file format, introspection claims, returning part of a value, the two-VP flow and credential_selection.

Example: claims in the token introspection response

Each constraint field with an id becomes a claim in the token introspection response, named by that id. This field in the presentation definition:

{
  "id": "fullName",
  "path": ["$.credentialSubject.fullName"],
  "filter": {
    "type": "string"
  }
}

gives this introspection response (some fields left out):

{
  "iss": "did:web:example.com",
  "active": true,
  "scope": "example_scope",
  "fullName": "John Doe"
}

Example: returning part of a value

To return only part of a text value, use a pattern filter with one capture group. The claim then holds what the capture group matched. The credential has "role": "Admin level 4"; this field returns "admin_level": "4":

{
  "id": "admin_level",
  "path": ["$.credentialSubject.role"],
  "filter": {
    "type": "string",
    "pattern": "Admin level ([0-9])"
  }
}

Example: service provider credentials (in development)

A constraint field with the same id in the organization and service_provider presentation definitions links the two presentations: the value found in the care organization's presentation must also be the value in the service provider's. Here, the service provider must present a ServiceProviderDelegationCredential issued by the DID that issued the care organization's HealthcareProviderCredential:

{
  "example_delegated_scope": {
    "organization": {
      "id": "org_pd",
      "input_descriptors": [{
        "id": "hcp_credential",
        "constraints": {
          "fields": [
            { "path": ["$.type"], "filter": { "type": "string", "const": "HealthcareProviderCredential" } },
            { "id": "delegating_hcp", "path": ["$.issuer"] }
          ]
        }
      }]
    },
    "service_provider": {
      "id": "sp_pd",
      "input_descriptors": [{
        "id": "delegation_credential",
        "constraints": {
          "fields": [
            { "path": ["$.type"], "filter": { "type": "string", "const": "ServiceProviderDelegationCredential" } },
            { "id": "delegating_hcp", "path": ["$.issuer"] }
          ]
        }
      }]
    }
  }
}

This must be enabled in the Nuts node, see Two-VP flow.


Revision #14
Created 2024-04-24 07:08:03 UTC by Rein Krul
Updated 2026-11-07 07:37:29 UTC by Rein Krul