Starting sign-in from another service
Sometimes the click that starts a sign-in happens somewhere other than the relying partyAn application that accepts and relies on a sign-in from another service, the name used in OpenID Connect and for passkeys. SAML calls the same role a service provider., 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 authenticationChecking evidence that someone, or some application, controls an account, such as a password or a passkey. It establishes which account is being used, not what that account may do. 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 tokenIn OpenID Connect, a signed JWT from the provider, addressed to one client, saying which account authenticated, when, and in answer to which request. It reports a sign-in and is not used to call APIs. 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 sessionThe ongoing connection between later requests and an earlier sign-in, so you are not asked for your password on every click. It is often tracked with a cookie holding an unpredictable session identifier. 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 ConnectAn identity layer on top of OAuth 2.0 that lets an application sign people in with an account at another service. It adds the ID token, standard claims, and discovery to the OAuth exchange. 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/startThe address must use HTTPSHTTP protected by TLS, so traffic is encrypted and checked for changes while it travels. It protects the connection, but does not prove that the site at the other end is honest.. 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-posterThe request has three parameters, and only the first is required:
| Parameter | What it asks the collage app to do |
|---|---|
iss | Required. Send its authentication request to the provider with this issuer identifier, which must be an HTTPS URL. |
login_hint | Optional. 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_uri | Optional. 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-onSigning in once and then using several applications without entering credentials again, usually because they all rely on the same identity provider. deployments work exactly that way, including the identity providerA service that authenticates users and tells other applications about the sign-in, so those applications never handle the users' passwords. In OpenID Connect it is called an OpenID Provider. initiated sign-in of SAMLThe Security Assertion Markup Language, a federation standard widely used for workplace single sign-on, in which the identity provider sends the application a signed assertion about the user. 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 tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret., 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.
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.
Anyone can send this link
Now the collage app's developers write the code behind /signin/start. The request it handles looks official. It came from the photo service's page, it names the photo service's issuerThe party that creates and signs a token, assertion, or certificate, named in a token's iss claim. A recipient must check that the issuer is exactly the one it expected and trusts., and it points at a real album. Nothing in it proves any of that.
A login initiation request is a URLA web address, such as https://photos.example/api/albums/42?limit=10. It names how to connect (https), the domain, the path to a particular page or resource, and any extra parameters after the question mark., or an automatically submitted form, with a few plain parameters. It carries no signature and no client authentication, and nothing in it identifies who built it. It arrives through Ava's browser, which may have been sent there by the photo service, by a link in an email, or by any page on the web. Anyone can write this one:
https://collage.example/signin/start
?iss=https%3A%2F%2Fauth.photos-sso.example
&login_hint=user-2048
&target_link_uri=https%3A%2F%2Fcollage-example.site%2Fsession-expiredAt a glance it resembles the photo service's request. The issuer is a lookalike domain that the attacker controls, and so is the target. A collage app that trusted both values would send Ava to the attacker's sign-in page, which could imitate the photo service's perfectly. Afterward it would send her to the attacker's site, which could claim the session had expired and ask for her password again.
The collage app's task is to take from the request only what it can check against its own configuration, and to treat the rest as suggestions it may ignore. Each parameter gets its own decision.
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
httpsand 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 lifetimeThen 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-2048Readable 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: DENYCurrent 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.
Try it in the Lab
- Validate login initiation requests, then launch from the Applications pageSend a hosted relying party login initiation requests anyone could write, see an unknown issuer, an outside target and a malformed hint refused, complete a fresh sign-in, then launch it like a dashboard tile.