CPW
CPW

Reputation: 83

Azure Active Directory Reply URL redirecting to root

I am trying to implement authentication using Azure AD. In the application setting I am setting the Reply URLs as https://example.com/myapp/login.aspx. When I login it redirects me to https://example.com and not specified URL https://example.com/myapp/login.aspx

How can I make sure that it redirects at proper URL? Following is the code for Startup.

    public void Configuration(IAppBuilder app)
{
    app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

    app.UseCookieAuthentication(new CookieAuthenticationOptions());

    app.UseOpenIdConnectAuthentication(
        new OpenIdConnectAuthenticationOptions
        {
            ClientId = ConfigurationManager.AppSettings["owin:ClientId"].ToString(),
            Authority = "https://login.microsoftonline.com/yz5036e3-2951-4c11-af4d-da019fa6a57d",
            RedirectUri = ConfigurationManager.AppSettings["RedirectUri"].ToString()
        });
}

Upvotes: 1

Views: 1716

Answers (3)

Mangesh Gosavi
Mangesh Gosavi

Reputation: 91

sorry for the delayed reply after redirectUrl add below -

navigateToLoginRequestUrl= false

Hope this will help

Upvotes: 0

CPW
CPW

Reputation: 83

In my case website was under virtual directory (converted in application). For login URL e.g. http://example.com/myapp/login.aspx, it was redirecting user to http://example.com. If I set RedirectUri as myapp/AfterLogin.aspx, it worked.

HttpContext.Current.GetOwinContext().Authentication.Challenge(
            new AuthenticationProperties { RedirectUri = "myapp/AfterLogin.aspx", },
            OpenIdConnectAuthenticationDefaults.AuthenticationType);

Upvotes: 4

vibronet
vibronet

Reputation: 7394

How do you trigger the sign in flow? If you are following the samples and initiating the sign in by invoking Challenge as shown in https://github.com/Azure-Samples/active-directory-dotnet-webapp-openidconnect/blob/master/WebApp-OpenIDConnect-DotNet/Controllers/AccountController.cs, you might want to make sure that the RedirectUri in the AuthenticationProperties points to the URL you ultimately (as in, AFTER auth) want to land on. I know, it's incredibly confusing - the RedirectUri property in the OIDC options point to the redirect you want to use in the auth protocol, the one on which you want to receive the auth token- and the one in the AuthenticationProperties is local URL you want to be redirected to after your exchange with the identity provider successfully concluded. The proerties have the same name for historical reasons.

Upvotes: 6

Related Questions