You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Incorporating Jenny's fixes for the OBO flow (#98)
* Incorporating Jenny's fixes for the OBO flow so that
the token cache is keyed by the acccess token in the case
of a Web API.
Removes a lot of code, uses the recommended patterns
Also some renaming to clarify
* Addressing PR feedback:
- from Kalyan/Tiago: renaming the Item used by StoreTokenUsedToCallWebAPI and GetTokenUsedToCallWebAPI from "token" to "JwtSecurityTokenUsedToCallWebAPI"
- from Mark: getting rid of the SetTokenCacheKey/GetUserTokenCacheKey.
- simplifying TokenAcquisition.GetAccessTokenOnBehalfOfUserAsync
Improving the comments on AcquireToken.GetAccessTokenOnBehalfOfUserAsync
* Adressing PR comment
* Fixing a typo
/// [not recommended] In a Web App, adds, to the MSAL.NET cache, the account of the user authenticating to the Web App.
87
-
/// An On-behalf-of token is added to the cache, so that it can then be used to acquire another token on-behalf-of the
88
-
/// same user in order for the Web App to call a Web APIs.
89
-
/// </summary>
90
-
/// <param name="tokenValidationContext">Token validation context passed to the handler of the OnTokenValidated event
91
-
/// for the OpenIdConnect middleware</param>
92
-
/// <param name="scopes">[Optional] scopes to pre-request for a downstream API</param>
93
-
/// <remarks>In a Web App, it's preferable to not request an access token, but only a code, and use the <see cref="AddAccountToCacheFromAuthorizationCodeAsync"/></remarks>
94
-
/// <example>
95
-
/// From the configuration of the Authentication of the ASP.NET Core Web API:
@@ -146,13 +146,21 @@ public async Task AddAccountToCacheFromAuthorizationCodeAsync(AuthorizationCodeR
146
146
147
147
/// <summary>
148
148
/// Typically used from a Web App or WebAPI controller, this method retrieves an access token
149
-
/// for a downstream API using the <a href='https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow'>on-behalf-of flow</a>
150
-
/// for the user account that is ascertained from claims are provided in the <see cref="HttpContext.User"/> instance of the <paramref name="context"/> parameter
149
+
/// for a downstream API using;
150
+
/// 1) the token cache (for Web Apps and Web APis) if a token exists in the cache
151
+
/// 2) or the <a href='https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow'>on-behalf-of flow</a>
152
+
/// in Web APIs, for the user account that is ascertained from claims are provided in the <see cref="HttpContext.User"/>
153
+
/// instance of the current HttpContext
151
154
/// </summary>
152
155
/// <param name="scopes">Scopes to request for the downstream API to call</param>
153
156
/// <param name="tenant">Enables overriding of the tenant/account for the same identity. This is useful in the
154
157
/// cases where a given account is guest in other tenants, and you want to acquire tokens for a specific tenant, like where the user is a guest in</param>
155
158
/// <returns>An access token to call the downstream API and populated with this downstream Api's scopes</returns>
159
+
/// <remarks>Calling this method from a Web API supposes that you have previously called,
160
+
/// in a method called by JwtBearerOptions.Events.OnTokenValidated, the HttpContextExtensions.StoreTokenUsedToCallWebAPI method
161
+
/// passing the validated token (as a JwtSecurityToken). Calling it from a Web App supposes that
162
+
/// you have previously called AddAccountToCacheFromAuthorizationCodeAsync from a method called by
/// [not recommended] In a Web App, adds, to the MSAL.NET cache, the account of the user authenticating to the Web App.
224
-
/// An On-behalf-of token is added to the cache, so that it can then be used to acquire another token on-behalf-of the
225
-
/// same user in order for the Web App to call a Web APIs.
226
-
/// </summary>
227
-
/// <param name="tokenValidatedContext">Token validation context passed to the handler of the OnTokenValidated event
228
-
/// for the OpenIdConnect middleware</param>
229
-
/// <param name="scopes">[Optional] scopes to pre-request for a downstream API</param>
230
-
/// <remarks>In a Web App, it's preferable to not request an access token, but only a code, and use the <see cref="AddAccountToCacheFromAuthorizationCodeAsync"/></remarks>
231
-
/// <example>
232
-
/// From the configuration of the Authentication of the ASP.NET Core Web API:
/// And then in the OnTokenValidated method, call <see cref="AddAccountToCacheFromJwtAsync(OpenIdConnect.TokenValidatedContext, IEnumerable<string>)"/>:
0 commit comments