Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Protected resource metadata

Authorization server metadata left the printer with one value a person typed: which authorization server goes with the photo API. This lesson follows the printer as an API names its own authorization servers, and shows the two decisions that keep that safe: whether the API's document really describes the address the printer called, and whether the server it names deserves Ava's visit.

An API that describes itself

The printer knows the photo API because its developers told it about the API. They configured the address https://api.photos.example, the issuer https://auth.photos.example whose tokens it accepts, the scope photos.read, and the fact that tokens go in the Authorization header. Authorization server metadata reduced the authorization server's settings to one trusted issuer, but the link between the API and that issuer is still something a person typed.

Now the printer's developers want to go further. They want people to print from photo libraries the printer has never been set up for: any service that offers the same kind of photo API. Ava would type the address of her library's API, and the printer would work out the rest. That only works if an API can describe itself, and it is only safe if the printer checks what the API says before acting on it.

Protected resource metadata, published as RFC 9728, does for APIs what authorization server metadata does for authorization servers. OAuth calls an API that accepts access tokens a protected resource, and the specification lets each one publish a JSON document saying which authorization servers it accepts tokens from, which scopes it uses, and how it wants tokens presented.

An API is named by its resource identifier: an HTTPS URL with no fragment, and normally no query either. The photo API's identifier is https://api.photos.example, the same value the photo service puts in the aud claim of tokens issued for it. All domains, tokens and values in these examples are fictional. Like the authorization server's document, the API's lives at a well-known address built from its identifier, here with the name oauth-protected-resource:

GET /.well-known/oauth-protected-resource HTTP/1.1
Host: api.photos.example
HTTP/1.1 200 OK
Content-Type: application/json

{
  "resource": "https://api.photos.example",
  "authorization_servers": ["https://auth.photos.example"],
  ...
}

The insertion rule from authorization server metadata applies when the identifier has a path. If the photo service published a second version of its API with the identifier https://api.photos.example/v2, that API's document would be at https://api.photos.example/.well-known/oauth-protected-resource/v2.

Each protected resource publishes its own document at an address derived from its own identifier, even when one server hosts several APIs. The specification relies on that: because a document's address is fixed by the identifier it describes, a document can speak only for the resource whose address it sits under.

Asking the API directly

A client does not always know an API's identifier. Sometimes all it has is an address to call, such as the one Ava typed. RFC 9728 lets the API point the way when a client calls that address without a token. The printer requests https://api.photos.example exactly as Ava typed it:

GET / HTTP/1.1
Host: api.photos.example

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://api.photos.example/.well-known/oauth-protected-resource"

The request line shows / because that is how HTTP sends an address with no path. As Using access tokens described, a request that carries no token earns a 401 with a WWW-Authenticate challenge and no error code. The resource_metadata parameter adds the address of the API's metadata document.

The parameter is not limited to plain bearer tokens. An API that requires DPoP can include it in a DPoP challenge like those in Validating proofs at the server, and it can sit in the same challenge as other parameters, such as the max_age value a step-up challenge uses. An API can also send it later, to a client that already uses it, as a signal that its metadata may have changed. The client then fetches the document again and validates it before using any new values, which lets an API move to a different authorization server without coordinating with every client in advance.

Reading the resource document

The photo API's complete document is short. Most of it answers questions the printer used to settle with a developer's help:

{
  "resource": "https://api.photos.example",
  "authorization_servers": ["https://auth.photos.example"],
  "scopes_supported": ["photos.read", "photos.write", "photos.delete"],
  "bearer_methods_supported": ["header"],
  "dpop_signing_alg_values_supported": ["ES256"],
  "dpop_bound_access_tokens_required": false,
  "resource_name": "Photo API",
  "resource_documentation": "https://photos.example/developers/api"
}

resource is the only required member. It repeats the identifier the document describes, and the client checks it before trusting anything else in the document.

authorization_servers lists the issuer identifiers of authorization servers whose tokens this API accepts. An API may leave some out, and an API whose authorization servers cannot be listed in advance omits the member entirely.

scopes_supported lists the scopes used to request access to this API. As with the authorization server's list, it shows what exists, not what to ask for. The printer still requests only photos.read, because a photo book needs nothing more.

bearer_methods_supported says how the API accepts bearer tokens. The defined values are header, body and query. This API accepts only the Authorization header, which is also the method Using access tokens recommended. If the member were missing, a client could not conclude anything either way.

The two DPoP members say that the API accepts DPoP proofs signed with ES256 but does not insist on them, because dpop_bound_access_tokens_required is false. The DPoP-bound tokens of the printer's phone app work here, and so do the plain bearer tokens of its website. An API that set the value to true would refuse any token not bound to a key.

resource_name and resource_documentation are for people. Like a client's name in its registration, described in Redirect URIs and client metadata, the resource name is whatever the API's operator chose to type.

From resource to authorization server

The issuer in authorization_servers is exactly the starting point authorization server metadata needs. The printer builds https://auth.photos.example/.well-known/oauth-authorization-server from it, fetches the document, checks that its issuer matches, and reads the endpoints. Put together, discovery runs in this order:

  1. Call the address the client was given, without a token, and receive a challenge naming the metadata address.
  2. Fetch the API's metadata, check its resource value against the address called, and decide whether to use the authorization server it lists.
  3. Fetch that authorization server's metadata and check its issuer value.
  4. Run the authorization flow, then call the API with the new access token.
Starting from nothing but the API's address, the printer learns which authorization server to use and where its endpoints are, checking each document before acting on it.

When an API lists more than one authorization server, the client chooses. A list does not oblige a client to use any of the servers on it. The client uses one that it trusts and where it has, or can obtain, a client registration. An authorization server's own metadata can also list the resources it serves, in a protected_resources member. Where an application relies on both lists, it can check that they agree.

With the endpoints in hand, the printer starts the authorization code flow it already knows. The request names the API it wants access to with the resource parameter from Selecting the intended resource, so the token it receives is restricted to that audience:

https://auth.photos.example/authorize
  ?response_type=code
  &client_id=photo-printer
  &redirect_uri=https%3A%2F%2Fprinter.example%2Foauth%2Fcallback
  &scope=photos.read
  &resource=https%3A%2F%2Fapi.photos.example
  &state=demo-attempt-7
  &code_challenge=qd-75t-gnweZAhIl6REjxxgFnPXGwvqYcxq3vlsaJYQ
  &code_challenge_method=S256

Naming the resource matters more for a client that follows APIs to authorization servers than for one configured by hand. RFC 9728 recommends audience-restricted tokens for any client that expects to use more than one protected resource. Without them, a client that takes directions from APIs could be steered into requesting a token that some other API would also accept. After the code exchange, the printer calls the API again, this time asking for GET /photos with the access token, and the API returns Ava's photos.

Checking the resource value

Every document along the way was written by someone else. For the photo service, those documents say what the printer's developers would have configured anyway. For an API someone typed into a box, they say whatever its operator wants them to say.

The first check mirrors the issuer check from Authorization server metadata. A metadata address is built from a resource identifier, as https://api.photos.example/.well-known/oauth-protected-resource is built from https://api.photos.example, and the document's resource member must be identical to the identifier its address was built from. If it is not, the client must not use any of the document.

A second check applies when the metadata address came from a challenge, and it stops a quieter trick. Suppose Ava was persuaded to add a library at https://api.attacker.example. The printer calls that address, and the attacker's API answers with a challenge that points at the photo API's genuine metadata:

GET / HTTP/1.1
Host: api.attacker.example

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://api.photos.example/.well-known/oauth-protected-resource"

Everything the printer fetches next is authentic, and it passes the first check. The document is the photo API's own, it names the real photo service, and Ava signs in at the real photo service. The printer receives a genuine token for the photo API, so audience restriction does nothing to stop what follows. The printer then sends its requests for Ava's photos to the attacker's API, the address she gave it, with that token attached, and the attacker replays the token at the real photo API.

The defense is to compare the document's resource with the address the client actually called. When metadata was found through a challenge, RFC 9728 requires its resource value to be identical to the URL the client used for the request that produced the challenge, and if it is not, none of the document may be used. The comparison is exact, like the issuer comparison, so it matches only when the client called the resource identifier itself. In code, that means comparing with the address as the client stored it, not a copy an HTTP library has rewritten, for example by adding a trailing slash. The printer's request to the photo API went to https://api.photos.example, exactly the identifier the photo API's document names, so the genuine API passes. Here the printer called https://api.attacker.example while the document names https://api.photos.example, so the printer stops before any token exists.

Calling the photo API

Address called
https://api.photos.example
Challenge points at
the photo API's metadata
resource
https://api.photos.example

Identical: use the document

Calling the attacker's API

Address called
https://api.attacker.example
Challenge points at
the photo API's metadata
resource
https://api.photos.example

Different: stop before any token exists

Without the check, the attacker's API would receive a genuine photo API token and replay it at the real photo API.

Both challenges lead to the photo API's genuine document. Its resource matches the address the printer called only when the printer called the photo API itself.

Deciding whether to trust an authorization server

A valid document proves only that the API said it. authorization_servers is the API's claim about where to get tokens, and RFC 9728 leaves the decision to trust a listed server with the client. Two abuses show why that decision matters.

A malicious API can list an authorization server its operator controls, with a sign-in page made to look like the photo service's. The printer would send Ava there to connect her library, and she might type her photo service password into it. A client that discovers authorization servers should show people the server's real domain before sending them there. The habits that resist phishing elsewhere matter here too, such as password managers that fill in a password only on the domain where it was saved, and authenticators that cannot be used on the wrong site.

A malicious API can also list a genuine authorization server and ask for a scope that another API uses. If that authorization server issued tokens every API would accept, the malicious API could replay the printer's token elsewhere. Requesting an audience-restricted token with the resource parameter, as the printer did above, limits a token obtained for one API to that API.

Beyond those defenses, a client needs a policy. The printer might accept only authorization servers on a list its operators maintain, or only those where it already has a registration, and treat anything else as a reason to ask Ava or to stop. The same decision applies when an API the printer already uses starts naming a different authorization server. The specification lets an API change servers this way, and a client should judge the new server as carefully as a stranger. Whatever the policy, two rules hold: tokens issued for one API are never sent to another, and credentials registered at one authorization server are never presented to another.

Fetching and refreshing safely

Discovery makes the printer's backend request addresses that other parties chose: the API address Ava typed, the metadata address in a challenge, the issuer in a document. That invites server-side request forgery, tricking a server into sending requests to addresses an attacker picks, often internal services the attacker cannot reach directly but the server can. Someone who entered an internal address as their photo library could make the printer's backend probe the printing company's own network.

RFC 9728 says clients should take precautions against this, such as blocking requests to internal address ranges. In practice, a backend that fetches discovered addresses accepts only HTTPS, resolves each host and rejects addresses that lead inside its own network: private addresses such as 10.0.0.1, loopback addresses such as 127.0.0.1, and link-local addresses such as 169.254.169.254, where many cloud servers answer questions about themselves. It applies the same rule to any redirect, and limits how long it waits and how much it reads. It checks the server certificate on every fetch, exactly as it does for authorization server metadata.

Resource metadata is fetched with an ordinary HTTP GET, so ordinary caching applies, and an API can say how long its document may be reused with a Cache-Control header. When an API sends a new challenge containing resource_metadata, the client fetches the document again and validates the fresh copy as it did the first. Like authorization server metadata, a resource's document can also carry signed_metadata; a client that supports it checks the signature and decides whether it trusts the signer.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

The printer calls https://api.attacker.example, whose challenge points at the photo API's genuine metadata. That document's resource is https://api.photos.example. What should happen? 1 of 4

Choose one answer.

Why does the printer include resource=https://api.photos.example in its authorization request after discovering the API through metadata? 2 of 4

Choose one answer.

An API Ava typed in publishes valid metadata listing https://login.photos-secure.example, an authorization server the printer has never used, whose sign-in page looks like the photo service's. What should the printer do? 3 of 4

Choose one answer.

Someone enters a plain HTTP address on the printing company's internal network as their photo library. What should the printer's backend do before discovery goes any further? 4 of 4

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity