-
Notifications
You must be signed in to change notification settings - Fork 1k
Jmprieur/sync from web api tutorial #186
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
Conversation
in TokenAcquisition.cs from the code which is currently in the ASP.NET Core Web API tutorial
/// This method appends in the HttpResponse being sent back to the client, a 403 (forbidden) status code and populates the 'WWW-Authenticate' header with additional information. | ||
/// The client, when it receives the 403 code with this header, can use the additional information provided in the header to trigger an interaction with the user where the user | ||
/// can then consent to additional scopes. | ||
/// Used in Web APIs (which therefore cannot have an interaction with the user). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better comments (from Jenny)
/// <param name="scopes">The additional scopes that the user needs to consent to</param> | ||
/// <param name="msalServiceException"><see cref="MsalUiRequiredException"/> The MsalUiRequiredException that is examined to see if there is case for this response.</param> | ||
|
||
/// <param name="scopes">Scopes to consent to</param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better comments (from Jenny)
/// <param name="msalServiceException"><see cref="MsalUiRequiredException"/> The MsalUiRequiredException that is examined to see if there is case for this response.</param> | ||
|
||
/// <param name="scopes">Scopes to consent to</param> | ||
/// <param name="msalServiceException"><see cref="MsalUiRequiredException"/> triggering the challenge</param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better comments (from Jenny)
public void ReplyForbiddenWithWwwAuthenticateHeader(IEnumerable<string> scopes, MsalUiRequiredException msalServiceException) | ||
{ | ||
// A user interaction is required, but we are in a Web API, and therefore, we need to report back to the client through an wwww-Authenticate header https://tools.ietf.org/html/rfc6750#section-3.1 | ||
string proposedAction = "consent"; | ||
if (msalServiceException.ErrorCode == MsalError.InvalidGrantError) | ||
{ | ||
if (AcceptedTokenVersionIsNotTheSameAsTokenVersion(msalServiceException)) | ||
if (AcceptedTokenVersionMismatch(msalServiceException)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better method name (from Jenny)
{ | ||
throw msalServiceException; | ||
} | ||
} | ||
|
||
string consentUrl = $"{application.Authority}/oauth2/v2.0/authorize?client_id={_azureAdOptions.ClientId}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consent URL to provision the Web API in multi-tenant / MSA
@@ -38,20 +38,18 @@ public static class WebApiServiceCollectionExtensions | |||
this IServiceCollection services, | |||
IConfiguration configuration, | |||
X509Certificate2 tokenDecryptionCertificate = null, | |||
string configSectionName = "AzureAD", | |||
string configSectionName = "AzureAd", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing the name of the section (like Kalyan did for the Web App)
bool subscribeToJwtBearerMiddlewareDiagnosticsEvents = false) | ||
{ | ||
services.AddAuthentication(AzureADDefaults.JwtBearerAuthenticationScheme) | ||
.AddAzureADBearer(options => configuration.Bind(configSectionName, options)); | ||
services.Configure<AzureADOptions>(options => configuration.Bind(configSectionName, options)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing the binding
@TiagoBrenck @kalyankrishna1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I learned something important from this PR: services.Configure<AzureADOptions>(options => configuration.Bind(configSectionName, options));
needs to be after the AddAuthentication() AddAzureADBearer()
.
Purpose
Does this introduce a breaking change?
Pull Request Type
What kind of change does this Pull Request introduce?
How to Test
What to Check
Verify that the following are valid
Other Information