Beta

Create a tenant

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

Grants, scopes, and consent

When the printer asks for access to Ava's photos, several decisions are made by different parties: what it asks for, whether it may ask at all, what Ava agrees to, and what the photo service finally issues. Grants, scopes and consent are the words for those pieces, and keeping them apart explains why the printer doesn't always get what it requested.

Understanding grants

In Following the messages, the printer received an authorization code through Ava's browser and presented it at the token endpoint. OAuth has a name for what the printer presented. An authorization grant is a credential representing someone's authorization, which a client uses to obtain an access token. In the authorization code flow, the authorization code is that grant: it stands for Ava's approval until the printer trades it in.

A grant type names the method used at the token endpoint. The printer says which one it is using in the grant_type field of its token request, a form-encoded POST like those from Sending requests with curl:

POST /token HTTP/1.1
Host: auth.photos.example
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA&redirect_uri=https%3A%2F%2Fprinter.example%2Foauth%2Fcallback&client_id=photo-printer

The value authorization_code tells the authorization server to expect a code and check it against the redirect URI and the client. Other grant types present something else. When the printer sends orders to its print lab on its own behalf, with no person involved, it can use the client credentials grant, which presents only the printer's own credentials. The token endpoint is the same; the grant type says what kind of evidence is arriving.

You may also hear a product call a saved application connection a "grant", as in "the printer has a grant to Ava's photos". That describes the continuing relationship the service records after Ava approves. When reading a protocol exchange, keep the two apart: the stored relationship lasts until Ava disconnects the printer, while the code presented in one token request is used once and gone.

Describing access with scopes

Giving another application limited access introduced a scope as a name for a kind of access. The photo service defines its own:

photos.read
photos.write
photos.delete

The printer asks for scopes in the authorization request, as a space-separated list in its scope parameter. It needs to read photos to make a book, so it asks for photos.read. It has no reason to ask for photos.delete, and asking only for what the job needs is the first protection Ava gets: a smaller request is easier for her to judge and does less harm if the printer is ever compromised.

Those names are examples. Their meaning comes from the service that defines and enforces them, and another photo service could use different names or divide its capabilities differently. Adding photos.read to a request does not grant anything by itself. Before Ava sees anything, the authorization server checks the request against the printer's registration, the record it keeps for each client, which can limit the scopes that client may ask for at all. A request for a scope outside it is refused straight away, with no sign-in and no consent page, and the browser returns to the printer with an error:

HTTP/1.1 302 Found
Location: https://printer.example/oauth/callback?error=invalid_scope&state=af0ifjsldkj

A scope can also leave important questions unanswered. Does photos.read mean every photo in Ava's library, only the album she picked, or photos others shared with her? The name alone does not say. The service needs its own rules, and sometimes more detail in the request, to express those limits, and the photo API still checks each album as Protecting each request showed. Describing access with authorization details, in Advanced OAuth, covers one way to describe access more precisely.

Check your understanding

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

The printer asks for photos.read photos.write. Ava approves both, but the token response says scope "photos.read". What should the printer assume? 1 of 3

Choose one answer.

The printer is granted photos.read. Can it conclude that it may read every photo in Ava's library? 2 of 3

Choose one answer.

The printer asks for photos.read photos.delete, and its registration doesn't list photos.delete. Ava never sees a sign-in or consent page. Why not? 3 of 3

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