Skip to content
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

Handle possible null HttpContext in ReplyForbiddenWithWwwAuthenticateHeaderAsync #380

Closed
pmaytak opened this issue Jul 31, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request fixed P1

Comments

@pmaytak
Copy link
Contributor

pmaytak commented Jul 31, 2020

Come up with a solution to handle possible null HttpContext in ReplyForbiddenWithWwwAuthenticateHeaderAsync in TokenAcquisition class.

var httpResponse = CurrentHttpContext.Response;
var headers = httpResponse.Headers;
httpResponse.StatusCode = (int)HttpStatusCode.Forbidden;
headers[HeaderNames.WWWAuthenticate] = new StringValues($"{Constants.Bearer} {parameterString}");

@jmprieur
Copy link
Collaborator

jmprieur commented Jul 31, 2020

We should have an extra parameter with a default value of null.
If passed-in we'd use it in the method, otherwise we'd use the HttpContextAccessor as we do today.

public async Task ReplyForbiddenWithWwwAuthenticateHeaderAsync(
         IEnumerable<string> scopes,
         MsalUiRequiredException msalServiceException, 
         HttpContext httpContext = null)

Alternatively we could just pass-in the HttpResponse:

  1. Pro this is all it needs
  2. in term of usability this could be more complicated for customers to find they need to use HttpContext.Reponse ?

@jennyf19 @pmaytak what do you think?

We could also handle it automatically.

@jmprieur jmprieur added enhancement New feature or request P1 labels Jul 31, 2020
@jmprieur jmprieur added this to the [3] Fundamentals milestone Jul 31, 2020
@jmprieur
Copy link
Collaborator

jmprieur commented Aug 2, 2020

@pmaytak
Let's go with providing the HttpResponse as a parameter

This will also fix Azure devops Bug 1099665: Defect : CS8602, Component : src\Microsoft.Identity.Web\TokenAcquisition.cs (1 issue) and therefore assigning to you.

@jmprieur
Copy link
Collaborator

jmprieur commented Aug 8, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed P1
Projects
None yet
Development

No branches or pull requests

3 participants