Skip to content

AccountController implementing MicrosoftIdentity/Account/xxx endpoints does not honour redirectUrlΒ #760

Closed

Description

@rollandjb

Which version of Microsoft Identity Web are you using?
Note that to get help, you need to run the latest version.
Microsoft Identity Web 1.2.0

Where is the issue?

  • Web app
    • Sign-in users
    • Sign-in users and call web APIs
  • Web API
    • Protected web APIs (validating tokens)
    • Protected web APIs (validating scopes)
    • Protected web APIs call downstream web APIs
  • Token cache serialization
    • In-memory caches
    • Session caches
    • Distributed caches
  • Other (please describe)

Is this a new or an existing app?
This is an app in development

Repro

<a href="MicrosoftIdentity/Account/SignIn?redirectUrl=yyy">Sign In</a>

Expected behavior
Clicking on the link should take me to the page at yyy

Actual behavior
Takes me to the route of the application, /

Possible solution
Set the redirectUrl property of AuthenticationProperties to the incoming query value

[HttpGet("{scheme?}/{redirectUrl?}")]
        public IActionResult SignIn([FromRoute] string scheme, [FromQuery] string redirectUrl)
        {
            scheme ??= OpenIdConnectDefaults.AuthenticationScheme;
            // var redirectUrl = Url.Content("~/");
            return Challenge(
                new AuthenticationProperties { RedirectUrl = redirectUrl ?? Url.Content("~/") },
                scheme);
        }

All endpoints should honour redirectUrl

Additional context / logs / screenshots

This will allow clients to use MicrosoftIdentity/Account/xxx endpoints and land the user on desired page.

Activity

  1. jmprieur commented on Nov 12, 2020

    @jmprieur
    Collaborator

    Thanks for the heads-up rollandjb

  2. self-assigned this
    on Nov 13, 2020
  3. rollandjb commented on Nov 13, 2020

    @rollandjb
    Author
  4. jmprieur commented on Nov 13, 2020

    @jmprieur
    Collaborator

    rollandjb I tried to repro this bug, but cannot.
    Using https://github.com/AzureAD/microsoft-identity-web/tree/master/tests/B2CWebAppCallsWebApi, and signing out each time, I'm always redirected to the page where the sign-in was triggered.

    Do you have repro steps? Do you want to force another redirect URL?

  5. rollandjb commented on Nov 14, 2020

    @rollandjb
    Author

    Jean-Marc Prieur (@jmprieur)

    I don't know ASP.NET Core web apps well enough to know how the page url is being remembered.

    In the case of a SPA hosted on the web app, one would need to specify the redirectUrl as a query parameter:

    <a href="/MicrosoftIdentity/Account/SignIn?redirectUrl=/pages/products">Sign In</a>
    

    AuthentcationProperties provides the mechanism to specify such a location using the RedirectUri property. It would be helpful if the /MicrosoftIdentity/Account/ controller would support that.

    The alternative is for me to implement my own endpoints. I would have to reroute those that are hard coded into the AzureADB2COpenIdConnectEventHandlers to my implementations. This is totally doable; it just seems better to use the built-in ones.

    What do you think?

  6. removed this from the 1.3.1 milestone on Nov 17, 2020
  7. 6 remaining items

  8. jennyf19 commented on May 26, 2021

    @jennyf19
    Collaborator

    Darragh Jones (@darraghjones) rollandjb fix has been merged into master. will be in next release.

  9. jmprieur commented on Jun 2, 2021

    @jmprieur
    Collaborator
  10. AndreyZ1 commented on Jun 9, 2021

    @AndreyZ1

    Jean-Marc Prieur (@jmprieur) hey here, could you help me, please, I just updated version but seems it's not working, am I doing something wrong?

    <a asp-area="MicrosoftIdentity" asp-route-redirectUri="@Model.ReturnUrl" asp-controller="Account" asp-action="SignIn">Sign in with Microsoft</a>

  11. jmprieur commented on Jun 9, 2021

    @jmprieur
    Collaborator

    AndreyZ1 : I'm not sure about the asp-route-redirectUri notation (I'm not familiar with it). Where is it documented?

    We used:

    <a href="/MicrosoftIdentity/Account/SignIn?redirectUri=/TodoList">Sign In</a>

    Maybe make sure that @Model.ReturnUrl starts by a / ?

  12. AndreyZ1 commented on Jun 9, 2021

    @AndreyZ1

    Jean-Marc Prieur (@jmprieur) Just tried to use hardcoded link
    <a href="/MicrosoftIdentity/Account/SignIn?redirectUri=/TodoList">Sign In</a>
    and it still not working. Do I have to enable something in Startup.cs configuration or somewhere else to make it working?

  13. jmprieur commented on Jun 9, 2021

    @jmprieur
    Collaborator

    No AndreyZ1
    The devapp with which this was tested is here:

    <li><a href="/MicrosoftIdentity/Account/SignIn?redirectUri=/TodoList">Sign In</a></li>

    just update Microsoft.Identity.Web and Microsoft.Identity.Web.UI

  14. AndreyZ1 commented on Jun 9, 2021

    @AndreyZ1

    Jean-Marc Prieur (@jmprieur) thank you a lot for help, I updated only Microsoft.Identity.Web and forgot about Microsoft.Identity.Web.UI.

  15. jmprieur commented on Jun 9, 2021

    @jmprieur
    Collaborator

    Thanks for the update, AndreyZ1
    Does it work with the asp-route-redirectUri="@Model.ReturnUrl" form?

  16. AndreyZ1 commented on Jun 9, 2021

    @AndreyZ1

    Jean-Marc Prieur (@jmprieur) yes, without any problems.

  17. jeevanthespark commented on Jul 26, 2022

    @jeevanthespark

    I am not sure what was fixed in earlier builds but I still can't make it work. The code is very simple as given below.

    <form method="get" asp-area="MicrosoftIdentity" asp-controller="Account" asp-action="SignIn" asp-route-redirectUri="/Claims">
                    <button type="submit" class="btn btn-primary">Sign In</button>
    </form>
    

    Can anyone please help to fix the issue?

  18. jmprieur commented on Jul 27, 2022

    @jmprieur
    Collaborator

    Jeevan K R (@jeevanthespark) : did you try with:

    <li><a href="/MicrosoftIdentity/Account/SignIn?redirectUri=/Claims">Sign In</a></li> 
  19. jeevanthespark commented on Jul 27, 2022

    @jeevanthespark

    Yes, I did. It is now redirecting but there are other issues. Initially, there were a couple of issues identified on my code.

    1. app.MapControllers wasn't added since no documentation explains it needs to be added to middleware. Could you please update the documentation?
    2. Form redirect returns a post request and on get request I get the below error from /MicrosoftIdentity/Account/Error

    OpenIdConnectAuthenticationHandler: message.State is null or empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions