Beta

Create a tenant

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

Starting sign-in from another service

Sometimes the click that starts a sign-in happens somewhere other than the relying party, such as a provider's list of the applications someone uses. This lesson follows Ava from the photo service's Applications page into the collage app, and the collage app as it treats that click as a request to start its own sign-in, checking each value before it acts on it.

A tile on the dashboard

The photo service gives every account an Applications page: a dashboard with a tile for each application its owner has connected, such as the collage app and the printer. When Ava is signed in at the photo service and selects the collage app's tile, she expects to land in the collage app, already signed in, without meeting another sign-in page. All domains, identifiers and values in these examples are fictional.

Every sign-in so far has started at the relying party. Ava selected Continue with your photo account at the collage app, and the collage app wrote the authentication request. Here the first click happens somewhere else. The Applications page knows which application Ava wants and which provider she uses, but the sign-in still has to finish at the collage app, with an ID token the collage app has reason to trust.

The simplest tile would be a plain link to https://collage.example. The collage app would see a visitor with no session and offer its sign-in page, and Ava would choose her photo account again, although she had just told the photo service which application she wanted. A collage app with one provider could skip its page and send every visitor straight to the photo service, but this one has two buttons.

The tile also has more to say. The collage app accepts two providers, the photo service and the mail service, as Supporting several providers set up, so it would not know which one to use. Ava may hold more than one photo account, and the photo service knows which one she is using right now. And the click may not be meant for the front page at all. The page for Ava's Album 42 has a Make a poster button, and when she selects it she wants to land on a new poster made from that album, not on the collage app's home page.

OpenID Connect gives this click a standard form, called third-party initiated login. "Third party" here means any party other than the relying party. Most often it is the provider's own dashboard, as here, but it could be a company intranet page or a partner's site that lists the applications its users can open. The initiator does not sign anyone in. It sends the browser to the relying party with a request: please start a sign-in, at this provider.

The login initiation endpoint

The collage app accepts these requests at its login initiation endpoint, an address it chooses for the purpose. Registering a relying party mentioned the registration field that records it, initiate_login_uri. The collage company added it to its registration at the photo service:

Client ID: photo-collage
Redirect URIs:
  https://collage.example/signin/callback
Login initiation endpoint (initiate_login_uri):
  https://collage.example/signin/start

The address must use HTTPS. It does not have to be the collage app's home page, and usually is not, because it does a different job: it starts a sign-in rather than showing anything. When Ava selects Make a poster on Album 42, the photo service sends her browser there:

https://collage.example/signin/start
  ?iss=https%3A%2F%2Fauth.photos.example
  &login_hint=user-2048
  &target_link_uri=https%3A%2F%2Fcollage.example%2Falbums%2F42%2Fnew-poster

The request has three parameters, and only the first is required:

The parameters of a login initiation request
ParameterWhat it asks the collage app to do
issRequired. Send its authentication request to the provider with this issuer identifier, which must be an HTTPS URL.
login_hintOptional. Suggest this account to the provider. Here the photo service uses Ava's subject identifier, user-2048, one of the values the specification mentions. An email address or username is also common.
target_link_uriOptional. Show this page once Ava is signed in.

The parameters can arrive in the query string of a GET request, as here, or as fields of a form that the photo service's page submits automatically with POST. A relying party that registers a login initiation endpoint must accept both. It must understand iss and login_hint, should support target_link_uri, and ignores any parameter it does not understand.

Each value is phrased as a request, and the collage app decides whether to honor it. A tile on the photo service's Applications page and a link in a stranger's email arrive at this endpoint looking exactly alike, which is why the second half of this lesson follows the collage app's decision about each parameter.

A request, not a result

The design is easiest to appreciate next to the alternative. The photo service already knows Ava is signed in. It could skip the request altogether and send the collage app a signed statement through the browser: this is user-2048, who signed in at 08:40. Some older single sign-on deployments work exactly that way, including the identity provider initiated sign-in of SAML that SP-initiated and IdP-initiated sign-in examined, where the provider posts the application an assertion that no request asked for.

The trouble lies in "no request asked for." When the collage app receives an ID token, it checks the state in the callback and the nonce in the token against a pending sign-in started in that same browser. An unrequested statement has nothing to match. The application cannot tell whether this browser asked to be signed in at all, or whose idea the statement was.

That gap is enough for an attack. Someone signs in at the provider with their own account, captures the statement meant for the application, and gets Ava's browser to deliver it, perhaps through a page that submits it automatically. The application signs Ava in to the attacker's account, and whatever she uploads or types there lands where the attacker can read it. It is the sign-in version of the forged callback in Request correlation and CSRF. A captured statement can also be replayed until it expires, unless the application remembers every one it has accepted.

Third-party initiated login avoids both problems by never sending a result that was not asked for. The photo service's page only asks the collage app to begin. The collage app then creates a pending sign-in for this browser and sends Ava to the photo service with an ordinary authentication request of its own. Everything that comes back answers a request the collage app made, in this browser, and is checked exactly as the collage app checks the sign-ins it starts from its own button.

The photo service only asks the collage app to start. From the collage app's redirect onward, this is an ordinary sign-in that the collage app began and checks itself.

For Ava, the extra hops are invisible. The photo service still holds her session from this morning, so it answers the collage app's request at once, without a sign-in page, and the browser arrives at the new poster a moment after the click. If that session has expired, Ava signs in again with the right account already suggested, because the collage app passed the login_hint along.

Some dashboards offer a shortcut for applications that have no login initiation endpoint: they send a code or an ID token straight to the application's redirect URI, as if the application had asked. A careful relying party rejects such a callback, because it matches no pending sign-in in the browser that delivered it. Registering a login initiation endpoint gives the dashboard a way to start sign-in that the collage app can accept without lowering that rule.

Choosing the provider

The collage app accepts iss only if it exactly matches the issuer identifier of a provider it is already configured to use, compared character for character, as Issuer, audience, and authorized party compared the iss claim. Its list has two entries, https://auth.photos.example and https://accounts.mail.example. A request naming any other issuer, including the lookalike above, starts no sign-in. The collage app shows its ordinary sign-in page instead, where Ava can begin in the usual way.

A match selects configuration the collage app already holds for that provider: its authorization and token endpoints, its key set, and the collage app's own client ID and credentials there. The collage app never runs discovery for an issuer it has just read from a request. Provider discovery said that trust starts from an issuer the relying party chose, never one taken from a token or a callback, and a login initiation request is one more place where an issuer can be offered. Fetching configuration for an arbitrary issuer would let anyone choose where Ava signs in, and would let anyone make the collage app's servers send requests to addresses of their choosing.

The matched issuer becomes the expected issuer of the pending sign-in, exactly as when Ava chooses a button on the collage app's own page. The protections from Supporting several providers apply unchanged: the response and the ID token must come from the issuer this attempt expected.

login_hint needs less care, because it grants nothing. The collage app can pass it to the provider in its authentication request, where, as Login hints explained, it only suggests an account. The provider still authenticates whoever is at the browser. The collage app checks that the value is short and well formed before copying it into a URL, and drops it otherwise. A hint naming someone else's account cannot sign Ava in as that person. At most, the provider suggests the wrong account on its sign-in page.

Checking the target

target_link_uri is the parameter the specification singles out. The relying party must verify it, so that its login initiation endpoint cannot be used as an open redirector to other sites. Redirect URI validation described open redirects and why attackers value them: a link that begins with a trusted address and ends on the attacker's page. This one is especially convincing, because Ava would reach the attacker's page straight after a genuine sign-in, at the moment she has every reason to trust the next page.

The collage app checks the target against the pages it is willing to show:

  • It parses the value with a standard URL parser and requires the scheme https and its own host, collage.example, compared exactly. A prefix check fails here for the same reasons it failed for redirect URIs. https://collage.example.attacker.example/ begins with the right characters and belongs to someone else.
  • It requires the path to be one of the collage app's own pages, such as a new poster page, from a list or pattern the collage app maintains.
  • If the target is missing or fails either check, it ignores the target and lands on the collage app's home page after sign-in. The target was only a preference, so there is no need to refuse the whole sign-in, although refusing the request outright is also safe.

The collage app keeps the checked path with the pending sign-in on its own server, not in state, as Correlating requests and responses advised for return destinations. After the callback, it reads the destination from the pending sign-in, never from the callback itself.

Reaching the target is not the same as being allowed to use it. The new poster page still checks, as every page that reads photos does, that the collage app holds Ava's permission to read Album 42. A link from the photo service says where Ava wanted to go. The collage app's own permissions decide what she finds there.

Starting a fresh request

With a provider chosen and a destination checked, the collage app does exactly what its own sign-in button does. It creates a pending sign-in for this browser:

Pending sign-in: demo-collage-signin-4
Initiating session: the current, not yet signed-in collage session
Expected issuer: https://auth.photos.example
Redirect URI: https://collage.example/signin/callback
Nonce: demo-collage-nonce-4
PKCE verifier: held privately on the backend
Return destination: /albums/42/new-poster
Status: pending, with a limited lifetime

Then it redirects the browser to the photo service with an ordinary authentication request:

https://auth.photos.example/authorize
  ?response_type=code
  &client_id=photo-collage
  &redirect_uri=https%3A%2F%2Fcollage.example%2Fsignin%2Fcallback
  &scope=openid%20profile
  &state=demo-collage-signin-4
  &nonce=demo-collage-nonce-4
  &code_challenge=N746XYTHj5ctZ7qbJbjsq9xKqCn-uPhdKT7Qrm3clys
  &code_challenge_method=S256
  &login_hint=user-2048

Readable values help us follow the example. Real ones are fresh and unpredictable, and every one of them is created here, by the collage app. The login initiation request supplied none of them, and if it had carried parameters named state or nonce, the collage app would ignore them, because they would be values someone else chose. From here on the sign-in is an ordinary one. The callback must match this pending sign-in in this browser, and the ID token is validated as in Validating an ID token, nonce included.

Sometimes Ava already has a collage session from earlier in the day. The collage app can then skip the round trip and go straight to the checked target, provided that session came from the issuer the request named and belongs to the account the hint names. Here the hint is a subject identifier, so the collage app can compare it with the session's subject directly. If they differ, the collage app starts a fresh sign-in rather than opening whichever account happens to be signed in. The login initiation request itself never changes who is signed in. Only a completed, validated sign-in like this one can do that.

One risk remains. Any website can send Ava's browser to the login initiation endpoint, and because the photo service remembers her, the whole exchange can complete without showing a single page. Ava can end up signed in to the collage app without having chosen to. That gives no one anything on its own. Combined with clickjacking, though, it matters: a page loads the collage app inside an invisible frame and tricks Ava into clicking buttons she cannot see, acting in the collage app with her new session. The specification asks relying parties to defend against this. Browsers that withhold cookies from frames on other sites already make it harder, as How browser privacy changes affect federation showed, but the collage app should not depend on that. The standard defense is a response header that forbids other sites from framing the collage app's pages at all:

Content-Security-Policy: frame-ancestors 'none'
X-Frame-Options: DENY

Current browsers follow the first header, and the second covers older ones. The collage app sends them with every page, including the login initiation endpoint and the sign-in callback.

Check your understanding

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

Ava selects Make a poster on her album at the photo service. What does the collage app receive at its login initiation endpoint? 1 of 3

Choose one answer.

The collage app accepts any target_link_uri that begins with https://collage.example. A request arrives whose target is on the host collage.example.attacker.example. What happens? 2 of 3

Choose one answer.

For an application with no login initiation endpoint, a dashboard sends an authorization code straight to the application's redirect URI, as if the application had asked. What should a careful relying party do? 3 of 3

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