-
Notifications
You must be signed in to change notification settings - Fork 4
feat: implement Interactive Authorization flow #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ee6358b
feat: implement interactive authorization flow
nanderstabel b865624
refactor: `InteractiveAuthorizationRequest` to use `AuthorizationRequ…
nanderstabel 029703f
feat: add utility functions for JWT claims extraction and key ID reso…
nanderstabel d1ffe01
refactor: improve JWT handling and add comprehensive tests for key ID…
nanderstabel eb80443
Merge branch 'dev' into feat/interactive-authorization-flow
nanderstabel b1af00c
fix: make `authorization_details` optional in Wallet implementation
nanderstabel cf88c20
refactor: rename `resolve_key_id` to `extract_normalized_did_kid_from…
nanderstabel 0ebdc75
refactor: move `get_unverified_jwt_claims` and `sd_jwt_to_jwt` to ded…
nanderstabel be6a949
feat: add reference to scope support in authorization request comments
nanderstabel e24cf68
refactor: rename InteractiveAuthorizationErrorCode to InteractiveAuth…
nanderstabel 09560d1
refactor: use `thiserror::Error`
nanderstabel b3bd5f2
feat: implement JWT utility functions for claims extraction and SD-JW…
nanderstabel 5107138
Merge branch 'feat/jwt-utils' into feat/interactive-authorization-flow
nanderstabel 95069d8
refactor: add TODO comments
nanderstabel fcb9e88
Merge branch 'dev' into feat/interactive-authorization-flow
nanderstabel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Oran-Dan marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| use crate::utils::jwt::{get_unverified_jwt_claims, sd_jwt_to_jwt}; | ||
| use jsonwebtoken::decode_header; | ||
|
|
||
| /// Extract the `kid` from a JWT header as a DID URL. | ||
| /// | ||
| /// If the `kid` is a relative DID fragment such as `#key-1`, this function | ||
| /// prefixes it with the unverified `iss` claim from the JWT payload to produce | ||
| /// an absolute DID URL. | ||
| /// | ||
| /// Returns an error if the JWT header cannot be decoded, if `kid` is missing, | ||
| /// or if a relative `kid` cannot be expanded because `iss` is missing or not a string. | ||
| pub fn extract_normalized_did_kid_from_jwt(jwt: &str) -> Result<String, anyhow::Error> { | ||
| let jwt = sd_jwt_to_jwt(jwt); | ||
|
|
||
| let jwt_header = decode_header(jwt).map_err(|e| anyhow::anyhow!("Failed to decode JWT header: {e}"))?; | ||
| let mut key_id = jwt_header | ||
| .kid | ||
| .ok_or_else(|| anyhow::anyhow!("Missing 'kid' in JWT header"))?; | ||
|
|
||
| if key_id.starts_with('#') { | ||
| let claims = get_unverified_jwt_claims(&serde_json::json!(jwt))?; | ||
| let iss = claims | ||
| .get("iss") | ||
| .ok_or_else(|| anyhow::anyhow!("Missing 'iss' claim"))? | ||
| .as_str() | ||
| .ok_or_else(|| anyhow::anyhow!("'iss' claim is not a string"))?; | ||
|
|
||
| key_id = format!("{iss}{key_id}"); | ||
| } | ||
|
|
||
| Ok(key_id) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn resolve_key_id_with_relative_reference() { | ||
| // JWT with relative key_id (starts with '#') | ||
| let jwt = | ||
| "eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSIsImtpZCI6IiNteWtleSJ9.eyJpc3MiOiJkaWQ6ZXhhbXBsZTppc3N1ZXIifQ.signature"; | ||
| let result = extract_normalized_did_kid_from_jwt(jwt); | ||
| assert!(result.is_ok()); | ||
| assert_eq!(result.unwrap(), "did:example:issuer#mykey"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn resolve_key_id_with_absolute_reference() { | ||
| // JWT with absolute key_id (doesn't start with '#') | ||
| let jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpleGFtcGxlOmlzc3VlciNteWtleSJ9.eyJpc3MiOiJkaWQ6ZXhhbXBsZTppc3N1ZXIifQ.signature"; | ||
| let result = extract_normalized_did_kid_from_jwt(jwt); | ||
| assert!(result.is_ok()); | ||
| assert_eq!(result.unwrap(), "did:example:issuer#mykey"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn resolve_key_id_missing_kid() { | ||
| // JWT without kid in header | ||
| let jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSJ9.eyJpc3MiOiJkaWQ6ZXhhbXBsZTppc3N1ZXIifQ.signature"; | ||
| let result = extract_normalized_did_kid_from_jwt(jwt); | ||
| assert!(result.is_err()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn resolve_key_id_missing_iss_claim() { | ||
| // JWT with relative key_id but missing 'iss' claim | ||
| let jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSIsImtpZCI6IiNteWtleSJ9.e30.signature"; | ||
| let result = extract_normalized_did_kid_from_jwt(jwt); | ||
| assert!(result.is_err()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn resolve_key_id_iss_not_string() { | ||
| // JWT with relative key_id but 'iss' claim is not a string | ||
| let jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSIsImtpZCI6IiNteWtleSJ9.eyJpc3MiOjEyMzQ1fQ.signature"; | ||
| let result = extract_normalized_did_kid_from_jwt(jwt); | ||
| assert!(result.is_err()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| pub mod did; | ||
| pub mod form_urlencoded; | ||
| pub mod jwt; | ||
| pub mod predicates; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.