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

Add RedirectUri to MicrosoftIdentityOptions #144

Merged
merged 2 commits into from
May 5, 2020
Merged

Conversation

jennyf19
Copy link
Collaborator

@jennyf19 jennyf19 commented May 5, 2020

  • add tests

fix for #115

Copy link
Collaborator

@jmprieur jmprieur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome to me

I've proposed a more verbose XML comment
and also you might want to remove the /* test only */ comment

src/Microsoft.Identity.Web/MicrosoftIdentityOptions.cs Outdated Show resolved Hide resolved
@jmprieur jmprieur requested a review from bgavrilMS May 5, 2020 17:53
@@ -371,7 +364,7 @@ private async Task<IConfidentialClientApplication> BuildConfidentialClientApplic
authority = $"{ _applicationOptions.Instance}tfp/{_microsoftIdentityOptions.Domain}/{_microsoftIdentityOptions.DefaultUserFlow}";
app = ConfidentialClientApplicationBuilder
.CreateWithApplicationOptions(_applicationOptions)
.WithRedirectUri(currentUri)
Copy link
Member

@bgavrilMS bgavrilMS May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You can combine the 2 builders to avoid repeated code. #Resolved

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea.


In reply to: 420316439 [](ancestors = 420316439)

@@ -570,11 +563,34 @@ private IAccount GetAccountByUserFlow(IEnumerable<IAccount> accounts, string use
foreach (var account in accounts)
{
string accountIdentifier = account.HomeAccountId.ObjectId.Split('.')[0];
if (accountIdentifier.EndsWith(userFlow.ToLower()))
if (accountIdentifier.EndsWith(userFlow.ToLower(CultureInfo.CurrentCulture), StringComparison.InvariantCulture))
Copy link
Member

@bgavrilMS bgavrilMS May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use InvariantCulture in ToLower(). #Resolved

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes thanks.


In reply to: 420317657 [](ancestors = 420317657)

{
return _microsoftIdentityOptions.RedirectUri;
}
else
Copy link
Member

@bgavrilMS bgavrilMS May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else is not needed because you return at line 579 #Resolved

}
else
{
_logger.LogInformation("MicrosoftIdentityOptions RedirectUri value must have a Uri Scheme " +
Copy link
Member

@bgavrilMS bgavrilMS May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't you want to throw an exception here? #Resolved

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no because we can still figure out the redirect URI based on the httpContext. But logging the information. I guess this is more of question for JM>


In reply to: 420320742 [](ancestors = 420320742)


var request = CurrentHttpContext.Request;
return UriHelper.BuildAbsolute(
request.Scheme,
Copy link
Member

@bgavrilMS bgavrilMS May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand the value here, but I think you've discussed this and you're ok with it. #Resolved

Copy link
Collaborator

@jmprieur jmprieur May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imagine that you run locally on http;//localhost:1234
then you deploy to azure (bg.azurewebapps.net)

if you don't use redirectUri, you don't need to change your config file.
Now if you add a reverse proxy that tweaks your URI, you might want to specify it (there are cases where that's needed. See [Bug] Redirect URI is set to http instead of https when deploying to Azure App Service for Docker container (Linux) #115 #Resolved

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what JM said. :)


In reply to: 420358960 [](ancestors = 420358960)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the explanation!

[InlineData("http://cats.b2clogin.com/signout-callback-oidc", true)]
public void ValidateRedirectUriFromMicrosoftIdentityOptions(
string redirectUri,
bool isTrue)
Copy link
Member

@bgavrilMS bgavrilMS May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can come up with a better name here :) #Resolved

Copy link
Member

@bgavrilMS bgavrilMS May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expectConfiguredUri? #Resolved

Copy link
Collaborator

@jmprieur jmprieur May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected?
#Resolved

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol...yes true...this was a quick thing for the test.


In reply to: 420322679 [](ancestors = 420322679)

string redirectUri,
bool isTrue)
{
string httpContextRedirectUri = "https://IdentityDotNetSDKAutomation/";
Copy link
Member

@bgavrilMS bgavrilMS May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this value make into _tokenAcquisition ? #Resolved

Copy link
Collaborator

@jmprieur jmprieur May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

through the MicrosoftIdentityOptions, which are injected by DI in the TokenAcquisition constructor #Resolved

Copy link
Collaborator

@jmprieur jmprieur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More suggestions based on Bogdan's feedback

@jennyf19 jennyf19 force-pushed the jennyf/redirect branch from 2104009 to e0c6d58 Compare May 5, 2020 22:16
@jennyf19
Copy link
Collaborator Author

jennyf19 commented May 5, 2020

thanks for the suggestions. i took them all much appreciated (and thanks for responding to Bogdan's questions as well.)


In reply to: 406100408 [](ancestors = 406100408)

@jennyf19 jennyf19 merged commit 6396e13 into master May 5, 2020
@jennyf19 jennyf19 deleted the jennyf/redirect branch May 5, 2020 22:23
Copy link
Contributor

@pmaytak pmaytak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

/// In a Web app, gets or sets the RedirectUri (URI where the token will be sent back by
/// Azure Active Directory or Azure Active Directory B2C)
/// This property is exclusive with <see cref="CallbackPath"/> which should be used preferably if you don't want
/// to have a different deployed configuration from your developper configuration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

developer.

/// This property is exclusive with <see cref="CallbackPath"/> which should be used preferably if you don't want
/// to have a different deployed configuration from your developper configuration.
/// There are cases where RedirectUri is needed, for instance when you use a reverse proxy that transforms https
/// URLs (external world) to http URLs (inside the protected area). This can also be useful for Web apps running
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTTP

/// Azure Active Directory or Azure Active Directory B2C)
/// This property is exclusive with <see cref="CallbackPath"/> which should be used preferably if you don't want
/// to have a different deployed configuration from your developper configuration.
/// There are cases where RedirectUri is needed, for instance when you use a reverse proxy that transforms https
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTTPS

{
return _microsoftIdentityOptions.RedirectUri;
}
_logger.LogInformation("MicrosoftIdentityOptions RedirectUri value must have a Uri Scheme " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URI scheme, HTTP, HTTPS.

@jmprieur
Copy link
Collaborator

jmprieur commented May 6, 2020

@pmaytak : please propose a PR with your suggestions.
cc: @jennyf19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants