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

Microsoft Account OAuth2 sign-on fails when redirect URL is not under the website root #203

Open
rxd2 opened this issue May 24, 2018 · 14 comments
Milestone

Comments

@rxd2
Copy link

rxd2 commented May 24, 2018

For example, https://my.site.com/signin-microsoft works but https://my.site.com/myapp/signin-microsoft does not.

GetOwinContext().Authentication.GetExternalLoginInfo() returns null. Callback URL contains error=access_denied parameter. Tracing shows Microsoft.Owin.Security.MicrosoftAccount.MicrosoftAccountAuthenticationMiddleware Error: 0 : Authentication failed messages.

This is broken in 4.0.0, starting with 3.1.0.

Reproducible both with localhost and the actual domain name.

@shahriarhusainy
Copy link

Scenario:

The application root is https://localhost/OwinFbDemo

Suppose https://localhost/OwinFbDemo/securepage is authenticated. https://localhost/OwinDemo/Auth/LoginFB points to the following action method under AuthController.cs:

public ActionResult LoginFB()
{
	HttpContext.GetOwinContext().Authentication.Challenge(new 
		Microsoft.Owin.Security.AuthenticationProperties {
			RedirectUri = "/securepage"
		}, "Facebook");
	return new HttpUnauthorizedResult();
}

The issue is that after successful login through Facebook it will redirect to https://localhost/securepage instead of https://localhost/OwinFbDemo/securepage

@Tratcher
Copy link
Member

You're able to work around it by setting RedirectUri = "/OwinFbDemo/securepage", correct?

The awkward bit is that if we fixed it anybody that had used this workaround would break.

@shahriarhusainy
Copy link

That worked. Thanks!

@rxd2
Copy link
Author

rxd2 commented Jun 1, 2018

The issue that shahriarhusainy described has obviously nothing to do with the issue I reported. Tratcher, did you have a chance to verify and/or take a look at what's going on?

Just to be clear, I don't manually set RedirectUrl. it's just that because my app is hosted not under the website root, but under virtual directory.

Thank you!

@Tratcher
Copy link
Member

Tratcher commented Jun 1, 2018

Virtual directory or sub application? They behave quite differently.

@rxd2
Copy link
Author

rxd2 commented Jun 1, 2018

Sub application, sorry

@Tratcher
Copy link
Member

The error=access_denied parameter is fishy, that would be coming from the external MSA server. It sounds like an app registration problem in MSA.

@rxd2
Copy link
Author

rxd2 commented Jun 21, 2018

Not sure what you mean by "fishy". I just created a new application, under a different microsoft account. I have exactly the same problem. Works perfectly with https://localhost:44300/signin-microsoft. Fails with https://localhost:44300/booking/signin-microsoft. Is that a limitation of MSA? What can I do to help diagnose/fix this?

@muratg
Copy link

muratg commented Oct 31, 2018

@rxd2 your issue seems to be a dup of #212, not this one.

@shahriarhusainy glad your issue is resolved, thanks @Tratcher!

Closing this one.

@muratg muratg closed this as completed Oct 31, 2018
@rxd2
Copy link
Author

rxd2 commented Oct 31, 2018

@muratg I don't agree, it's not a dup. #212 is maybe similar but not quite the same, My application does work with 4.0,0 as long as the redirect URL is a website root.

@muratg
Copy link

muratg commented Oct 31, 2018

@rxd2 please file a separate issue as your issue doesn't seem to be related to this one either.

@rxd2
Copy link
Author

rxd2 commented Oct 31, 2018

@muratg Excuse me? It is my issue, I created it. How can it possibly be not "related to this issue"?

@muratg
Copy link

muratg commented Nov 1, 2018

@rxd2 you're right, my apologies. @shahriarhusainy's issue was unrelated.

@muratg muratg reopened this Nov 1, 2018
@rxd2
Copy link
Author

rxd2 commented Nov 1, 2018

@muratg No problem, thank you!

@analogrelay analogrelay added this to the Backlog milestone Sep 18, 2019
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

No branches or pull requests

5 participants