GetExternalLoginInfoAsync returns null for AddMicrosoftAccount

Viewed 21

In my program I have

builder.Services.AddAuthentication().AddMicrosoftAccount(microsoftOptions =>
{
    microsoftOptions.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
    microsoftOptions.ClientId = "...";
    microsoftOptions.ClientSecret = "...";

    microsoftOptions.AuthorizationEndpoint = "https://login.microsoftonline.com/.../oauth2/v2.0/authorize";
    microsoftOptions.TokenEndpoint = "https://login.microsoftonline.com/.../oauth2/v2.0/token";

    microsoftOptions.Scope.Add("openid");
    microsoftOptions.Scope.Add("profile");
    microsoftOptions.Scope.Add("email");
});

And I've set it up in Azure.

The new login button appears on the /Identity/Account/Login page and the login process proceeds. The callback URL seems to have to be /signin-microsoft, but it proceeds to Identity/Account/ExternalLoginCallback, where I was expecting to obtain a claims identity from which I could set up the local user account.

However,

var info = await _signInManager.GetExternalLoginInfoAsync();

returns null.

In the .Request I can see a cookie names idsrv.external but the .User has no claims.

What is wrong? This should work!

1 Answers

Changing

microsoftOptions.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;

to

microsoftOptions.SignInScheme = "Identity.External";

has made it work. Fuck knows why. Pretty disappoinding that the default value is broken.

Related