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

Support for setting redirect-url in token-fetch portion of confidential-app authentication code flow #96

Closed
wants to merge 6 commits into from

Conversation

harikb
Copy link

@harikb harikb commented Dec 6, 2020

Changes

  1. Correcting some broken links in README
  2. Support for adding RedirectURI in token-fetch portion of confidential-app authentication code flow.

See also this comment elsewhere for context Azure/azure-sdk-for-go#13565 (comment)

The change retains the ability to have a default RedirectURI while still allowing the caller to set one if available.
@jhendrixMSFT

@ghost
Copy link

ghost commented Dec 6, 2020

CLA assistant check
All CLA requirements met.

@harikb harikb changed the title Minor doc updates Support for setting redirect-url in token-fetch portion of confidential-app authentication code flow Dec 6, 2020
@@ -129,4 +129,5 @@ type AcquireTokenByDeviceCodeOptions struct {
type AcquireTokenByAuthCodeOptions struct {
Code string
CodeChallenge string
RedirectURI string
Copy link
Contributor

Choose a reason for hiding this comment

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

@jmprieur can you please comment on this? I explicitly removed this in #68 per your request.

Copy link
Author

Choose a reason for hiding this comment

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

I am not the original requester of that change, although our handles look similar. In my case, I was trying to use a token-fetch as an explicit call back to MS instead of implicit-token flow. As per the documentation, implicit token on auth-code flow is less secure and they recommend webapps fetch it back from MS. When we call back, this redirectURI is required, and matching original auth request.

Copy link
Contributor

@jhendrixMSFT jhendrixMSFT Dec 7, 2020

Choose a reason for hiding this comment

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

The recommendation is for apps to use the https://login.microsoftonline.com/common/oauth2/nativeclient reply URL, this is what I did when testing the change and it worked for me. See the conversation here. I'm far from an expert here though so somebody from the MSAL team needs to comment further.

MSAL for other languages doesn't expose a redirect URI parameter.

Copy link
Author

Choose a reason for hiding this comment

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

@jmprieur I don't quite understand this statement that you made in #68

but MSAL stops the redirect

My use-case is a webapp that needs to redirect a user to MS auth servers and then back to the site. It would be what you consider a confidential-app and I am specifically choosing not to use 'implicit-token' checkbox in the App settings since that is not recommended.

After the user accepts the consent, the browser needs to be redirected back to the site, so I do need to supply a real redirect-url in addition to make it match with one of the configured urls on the app settings. If you are saying MS will redirect back to my real site even if I specify login.microsoftonline.com, then I am mistaken, I have not tried that.

Now the specific fix is about making it configurable, so that I can pass the same value back when I fetch the token.
My app is not opensource, but it is very similar to your sample

First place I need to use the redirect-url
https://github.com/AzureAD/microsoft-authentication-library-for-go/blob/dev/test/devapps/confidential_auth_code_sample.go#L29

Second place I need to use the redirect-url (this fix)
https://github.com/AzureAD/microsoft-authentication-library-for-go/blob/dev/test/devapps/confidential_auth_code_sample.go#L61

Copy link
Contributor

Choose a reason for hiding this comment

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

After discussion we do need to add this back. However we shouldn't place this in the options struct as it makes it appear optional when it should be user-specified (falling back to a default value is incorrect). Can you please move this out of the options struct and make it a parameter so it's clear the caller must supply a value?

README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@jhendrixMSFT jhendrixMSFT left a comment

Choose a reason for hiding this comment

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

Get confirmation that adding the redirectURI back is ok.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 7, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@harikb harikb requested a review from jhendrixMSFT December 9, 2020 17:52
@jhendrixMSFT
Copy link
Contributor

@harikb I've asked an MSAL expert to review this change.

Copy link
Contributor

@jhendrixMSFT jhendrixMSFT left a comment

Choose a reason for hiding this comment

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

Make RedirectURI a param

@@ -129,4 +129,5 @@ type AcquireTokenByDeviceCodeOptions struct {
type AcquireTokenByAuthCodeOptions struct {
Code string
CodeChallenge string
RedirectURI string
Copy link
Contributor

Choose a reason for hiding this comment

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

After discussion we do need to add this back. However we shouldn't place this in the options struct as it makes it appear optional when it should be user-specified (falling back to a default value is incorrect). Can you please move this out of the options struct and make it a parameter so it's clear the caller must supply a value?

Copy link
Contributor

@sangonzal sangonzal left a comment

Choose a reason for hiding this comment

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

Overall looks good, thanks for contributing. I've changed the location of AcquireTokenByAuthCodeOptions in #104 so it's clear that its shared in between public clients and confidential clients. Once the change when the RedirectUri == "" is made, it should be ready to be merged.

authParams.Redirecturi = p.RedirectURI
}
if authParams.Redirecturi == "" { // set it to default if it is still not set
authParams.Redirecturi = "https://login.microsoftonline.com/common/oauth2/nativeclient"
Copy link
Contributor

Choose a reason for hiding this comment

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

If RedirectUri == "", lets return an error stating that this is not a valid value. We should not default to "https://login.microsoftonline.com/common/oauth2/nativeclient" as embedded browsers are not yet supported in MSAL Go.

Copy link
Contributor

Choose a reason for hiding this comment

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

I propose making this a parameter so it's clear the caller must supply a value. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yes good point. So instead of going in the options struct, it should be in the parameters for both public client auth code and confidential client auth code

Copy link
Author

@harikb harikb Dec 10, 2020

Choose a reason for hiding this comment

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

If I make RedirectURI required/argument, I need to figure out what to do in tests like these https://github.com/AzureAD/microsoft-authentication-library-for-go/blob/dev/msal/public_client_application_test.go#L80

I will work on it, but it will take a bit of time. I don't yet know how those mocks work. Thanks

@jhendrixMSFT
Copy link
Contributor

Superseded by #188

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