feat: Adds Token Vault support#1064
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1064 +/- ##
==========================================
+ Coverage 25.51% 25.53% +0.02%
==========================================
Files 3155 3156 +1
Lines 148277 148320 +43
Branches 10018 10021 +3
==========================================
+ Hits 37832 37874 +42
- Misses 108132 108133 +1
Partials 2313 2313
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| public class FederatedConnectionAccessTokenRequest : IClientAuthentication | ||
| { | ||
| /// <summary> | ||
| /// The Auth0 token being exchanged. Currently this must be a valid Auth0 refresh token. |
There was a problem hiding this comment.
This doc says the subject token must be an Auth0 refresh token, but the example, every test in this PR, and the Token Vault docs all use an access token (subject_token_type = urn:ietf:params:oauth:token-type:access_token). The Auth0 docs describe subject_token as the Auth0 access token that identifies the user.
The class remark on line 11 and the SubjectTokenType note on line 25 say the same refresh token thing, so all three spots contradict what the code actually does. Since this text shows up in IntelliSense, a user following it would pass a refresh token and get a 400. Can we update these to say access token (TokenType.AccessToken)? If refresh tokens are also valid, then let us word it as access or refresh token, but right now nothing exercises the refresh token path.
There was a problem hiding this comment.
Addressed in 5b53c29
subject_token_type can be both AccessToken or RefreshToken. Updated the code docs to reflect the same.
| { "grant_type", "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token" }, | ||
| { "client_id", request.ClientId }, | ||
| { "subject_token", request.SubjectToken }, | ||
| { "subject_token_type", request.SubjectTokenType }, |
There was a problem hiding this comment.
SubjectToken and SubjectTokenType are both required but we add them to the body with no check. We already throw a clear ArgumentException for a missing Connection a few lines up, so it feels odd to let these two through and get back an opaque 400 from the server.
Can we add the same kind of early null or empty guard for SubjectToken and SubjectTokenType?
| /// <summary> | ||
| /// Indicates that the token is an OAuth 2.0 refresh token: <c>urn:ietf:params:oauth:token-type:refresh_token</c>. | ||
| /// </summary> | ||
| public const string RefreshToken = "urn:ietf:params:oauth:token-type:refresh_token"; |
There was a problem hiding this comment.
This RefreshToken constant does not seem to be used anywhere in the feature. All the code paths and tests use AccessToken. It looks like it was added only to support the refresh token wording in the request model, which I think is not correct (left a note there).
If refresh token subjects are genuinely supported, can we add a test that uses this? Otherwise I would drop it so we do not signal a path that does not work. Low priority either way.
There was a problem hiding this comment.
Addressed in 5b53c29
This is a public property. Also, now we have added test cases that use this RefreshToken as well.
Changes
Adds Token Vault support to the
Auth0.AuthenticationApipackage. Token Vault lets a private client exchange an Auth0 token for an access token issued by one of Auth0's federated connections (Google, Facebook, etc.), so the app can call that provider's APIs on the user's behalf.Classes/methods added:
FederatedConnectionAccessTokenRequest(implementsIClientAuthentication) — carriesSubjectToken,SubjectTokenType,Connection(required), optionalLoginHint,Nonce, and the standard client-auth members (ClientId,ClientSecret,ClientAssertionSecurityKey,ClientAssertionSecurityKeyAlgorithm,SigningAlgorithm).Task<AccessTokenResponse> GetTokenAsync(FederatedConnectionAccessTokenRequest request, CancellationToken)onIAuthenticationApiClient/AuthenticationApiClient. Builds the request body, applies client authentication, hardcodesrequested_token_type, POSTs to/oauth/token, and reuses the existingAccessTokenResponse(the federated token is returned inAccessToken;issued_token_typeis surfaced viaIssuedTokenType).TokenTypeconstants:RefreshToken(urn:ietf:params:oauth:token-type:refresh_token) andFederatedConnectionAccessToken(http://auth0.com/oauth/token-type/federated-connection-access-token).Usage:
References
Testing
Checklist