Skip to content

Commit ec0bd4b

Browse files
authored
Update Diagram and Primer to reflect iss check (#257)
* update primer * update diagram
1 parent b7f75f9 commit ec0bd4b

3 files changed

Lines changed: 30 additions & 19 deletions

File tree

primer/index.bs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,18 +360,27 @@ id, the [=code challenge=], the user's webid, their desired response types, and
360360
}
361361
```
362362

363-
<h4 id="authorization-code-pkce-flow-step-11" class="no-num">11. Send authorization code to redirect url</h4>
363+
<h4 id="authorization-code-pkce-flow-step-11" class="no-num">11. Send authorization code and `iss` parameter to redirect url</h4>
364364

365365
Once Alice successfully logs in, the OP redirects back to the application via the provided
366-
redirect uri, including useful information with it:
366+
redirect uri. The OP includes the authorization code as well as its own issuer identifier as the iss parameter to protect against mix-up attacks:
367367

368368
```http
369-
302 redirect to: https://decentphotos.example/callback?code=m-OrTPHdRsm8W_e9P0J2Bt
369+
302 redirect to: https://decentphotos.example/callback?code=m-OrTPHdRsm8W_e9P0J2Bt&iss=https%3A%2F%2Fsecureauth.example
370370
```
371371

372-
This redirect gives decentphotos the [=authorization code=] that it will exchange for requested tokens.
372+
This redirect gives decentphotos the [=authorization code=] that it will exchange for requested tokens, along with the issuer identifier required for the next validation step.
373373

374-
<h4 id="authorization-code-pkce-flow-step-12" class="no-num">12. Generates a DPoP Client Key Pair</h4>
374+
<h4 id="authorization-code-pkce-flow-step-12" class="no-num">12. Validate `iss` Parameter</h4>
375+
376+
Before proceeding to exchange the code for tokens, decentphotos must verify the `iss` parameter.
377+
This ensures the application is receiving the code from the exact OP it intended to communicate with.
378+
379+
The application checks that the `iss` value (`https://secureauth.example`) matches the issuer URL it resolved in Step 3.
380+
If the `iss` parameter is missing or does not match the expected OP, decentphotos must reject the response, abort the authentication flow, and optionally display an error to Alice.
381+
In our example, the issuer matches, so we may safely continue.
382+
383+
<h4 id="authorization-code-pkce-flow-step-13" class="no-num">13. Generates a DPoP Client Key Pair</h4>
375384

376385
Solid-OIDC depends on
377386
[Demonstration of Proof-of-Possession (DPoP) tokens](https://tools.ietf.org/html/draft-ietf-oauth-dpop).
@@ -410,7 +419,7 @@ The public key looks like:
410419
}
411420
```
412421

413-
<h4 id="authorization-code-pkce-flow-step-13" class="no-num">13. Generates a DPoP Header</h4>
422+
<h4 id="authorization-code-pkce-flow-step-14" class="no-num">14. Generates a DPoP Header</h4>
414423

415424
Now that we generated a private key for the client, we need to generate the DPoP header. To do
416425
so, we create a [JSON Web Token](https://jwt.io/introduction/) and sign it using the key we
@@ -459,7 +468,7 @@ Token Body:
459468
that can optionally be used by the server to defend against replay attacks
460469
- `"iat": 1603306128`: The date the token was issued, in this case October 21, 2020 15:52:33 GMT.
461470

462-
<h4 id="authorization-code-pkce-flow-step-14" class="no-num">14. Token request with code and code verifier</h4>
471+
<h4 id="authorization-code-pkce-flow-step-15" class="no-num">15. Token request with code and code verifier</h4>
463472

464473
Now, we have everything we need to make an auth request. No need to redirect the web browser
465474
for this one. We only need to make an AJAX request to the `token` endpoint as defined in the
@@ -495,7 +504,7 @@ Body:
495504

496505
Once this request is completed decentphotos can remove the code verifier from session storage.
497506

498-
<h4 id="authorization-code-pkce-flow-step-15" class="no-num">15. Validate code verifier</h4>
507+
<h4 id="authorization-code-pkce-flow-step-16" class="no-num">16. Validate code verifier</h4>
499508

500509
The OP looks up the [=authorization code=] that was saved earlier in a keystore. It checks to see that the client
501510
id in the keystore corresponds to the client id from the request. If it does not, it must
@@ -511,13 +520,13 @@ BASE64URL-ENCODE(SHA256(ASCII(code_verifier))) == code_challenge
511520
If they do not correspond the OP must reject the request with a 400 HTTP status and `invalid_grant`
512521
error code.
513522

514-
<h4 id="authorization-code-pkce-flow-step-16" class="no-num">16. Validates DPoP Token Signature</h4>
523+
<h4 id="authorization-code-pkce-flow-step-17" class="no-num">17. Validates DPoP Token Signature</h4>
515524

516525
The OP extracts the client's public key from the DPoP header (at header.jwk). It confirms that
517526
the DPoP token has a valid signature. If not, the OP must reject the request with a 400 HTTP
518527
status and `invalid_dpop_proof` error code.
519528

520-
<h4 id="authorization-code-pkce-flow-step-17" class="no-num">17. Converts the DPoP public key to a JWK thumbprint</h4>
529+
<h4 id="authorization-code-pkce-flow-step-18" class="no-num">18. Converts the DPoP public key to a JWK thumbprint</h4>
521530

522531
Currently the DPoP token contains a JWK public key, but before we place it inside the access
523532
token, it needs to be converted into a [JWK thumbprint](https://tools.ietf.org/html/rfc7638).

primer/primer-login.mmd

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ sequenceDiagram
1717
note over OP: 8. Validates redirect url with Client ID Document
1818
note over OP: 9. Alice Logs In
1919
note over OP: 10. Generates an authorization code
20-
OP->>Client: 11. Send authorization code to redirect url
21-
note over Client: 12. Generates DPoP Client Key Pair
22-
note over Client: 13. Generates a DPoP Header
23-
Client->>OP: 14. Token request with code and code verifier
24-
note over OP: 15. Validates code verifier
25-
note over OP: 16. Validates DPoP Token signature
26-
note over OP: 17. Converts the DPoP public key to a JWK thumbprint
20+
OP->>Client: 11. Send authorization code and iss parameter to redirect url
21+
note over Client: 12 Validates that the returned iss matches the expected OP issuer
22+
note over Client: 13. Generates DPoP Client Key Pair
23+
note over Client: 14. Generates a DPoP Header
24+
Client->>OP: 15. Token request with code and code verifier
25+
note over OP: 16. Validates code verifier
26+
note over OP: 17. Validates DPoP Token signature
27+
note over OP: 18. Converts the DPoP public key to a JWK thumbprint
2728
note over OP: 19. Generates id token
2829
note over OP: 20. Generates refresh token
29-
OP->>Client: 21. Send tokens
30+
OP->>Client: 21. Send tokens

sequence.mmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ sequenceDiagram
1414
OP->> ClientID: get Client ID document
1515
ClientID->> OP: ClientID document
1616
Note over OP: compare redirect_uri
17-
OP ->> C: return Authorization Code
17+
OP ->> C: return Authorization Code and iss parameter
18+
Note over C: Validate iss matches expected OP
1819
C ->> OP: present Authorization Code and DPoP proof
1920
Note over OP: ⚙️ Client is authenticated ✅
2021
OP ->> C: return DPoP bound OIDC ID Token

0 commit comments

Comments
 (0)