I have a problem with my asp .net webapp Im developing right now. I added the possibilty to login with a microsoft account. But I have the problem, that it doesn't take my custom redirect url. In my Azure Ad application the redirect url is configured to /Profile, but the request redirect url it gets from my login button is everytime /signin-microsoft
My Authentication in my startup.cs looks like this
services.AddAuthentication("Cookies")
.AddCookie(opt =>
{
opt.Cookie.Name = "AuthCookie";
})
.AddMicrosoftAccount(opt => {
opt.SignInScheme = "Cookies";
opt.AuthorizationEndpoint = _configuration["AzureAd:AuthorizationEndpoint"];
opt.TokenEndpoint = _configuration["AzureAd:TokenEndpoint"];
opt.ClientId = _configuration["AzureAd:ClientId"];
opt.ClientSecret = _configuration["AzureAd:ClientSecret"];
});
I dont know if this is important but my used options in applicationsettings are:
"AzureAd": {
"ClientId": "<clientId>",
"ClientSecret": "<clientSecret>",
"AuthorizationEndpoint":"https://login.microsoftonline.com/<tenantId>/oauth2/v2.0/authorize",
"TokenEndpoint": "https://login.microsoftonline.com/<tenantId>/oauth2/v2.0/token"
}
Ofc i entered the correct IDs in this
My Login Controller:
[HttpGet("microsoft")]
public async Task<ActionResult>Login(string RedirectUri)
{
AuthenticationProperties props = new AuthenticationProperties
{
RedirectUri = RedirectUri
};
return Challenge(props, MicrosoftAccountDefaults.AuthenticationScheme);
}
And my login button:
<NotAuthorized>
<li class="nav-item">
<a class="nav-link" href="Login/microsoft?RedirectUri=/Profile">
Login
</a>
</li>
</NotAuthorized>
As you can see the Redirect paramenter should be /profile and I set it also in the Authentication Properties to this value, but when i click the login button the url is always:
https://login.microsoftonline.com/%5C\<tenantId>/oauth2/v2.0/authorize...&redirect_uri=https%3A%2F%2Flocalhost%3A5000%2Fsignin-microsoft&...
So why doesnt it take /Profile as redirect Url?
It is expected that the redirect uri parameter is localhost:5000/Profile