Search code examples
asp.net-core-mvcasp.net-identity-3.net-core-rc2microsoft-account

MVC Core RC2, External login via Microsoft Account


After moving my project to MVC Core RC2 I can't login via external Microsoft Account... Everything other works fine including login via Google Account.

It works perfectly on RC1 and nothing change directly in this part of my code after moving to RC2, of course I use new middleware - moreover I have updated authentication packages to RC3 and still have the same problem.

I'm pretty sure about my project/references/packages/etc. because I create new/clean project after installing RC2.

Here is my code form Startup.cs

...

app.UseIdentity();

// External Authentication
app.UseGoogleAuthentication(new GoogleOptions
{
     ClientId = Configuration["Authentication:Google:ClientId"],
     ClientSecret = Configuration["Authentication:Google:ClientSecret"],
     AutomaticAuthenticate = false
});

app.UseMicrosoftAccountAuthentication(new MicrosoftAccountOptions
{
     ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"],
     ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"],
     AutomaticAuthenticate = false
});

...

After first login I can see standard question about permission:

MS Account Permission

and next I have an error:

An unhandled exception occurred while processing the request.

Exception: OAuth token endpoint failure: Status: BadRequest;Headers: Pragma: no-cache
 x-ms-request-id: 5d12a6bf-2178-42bc-9e51-7aa73b1d6c9e
 client-request-id: 05f7532f-0075-438f-80e4-efd85b641bde
 x-ms-gateway-service-instanceid: ESTSFE_IN_131
 X-Content-Type-Options: nosniff
 Strict-Transport-Security: max-age=31536000; includeSubDomains
 Cache-Control: no-store, no-cache
 P3P: CP="DSP CUR OTPi IND OTRi ONL FIN"
 Set-Cookie: x-ms-gateway-slice=productiona; path=/; secure; HttpOnly, stsservicecookie=ests; path=/
 Server: Microsoft-IIS/8.5
 X-Powered-By: ASP.NET
 Date: Fri, 03 Jun 2016 23:11:55 GMT
 ;Body: {"error":"invalid_request","error_description":"AADSTS90019: No tenant-identifying information found in either the request or implied by any provided credentials.\r\nTrace ID: 5d12a6bf-2178-42bc-9e51-7aa73b1d6c9e\r\nCorrelation ID: 05f7532f-0075-438f-80e4-efd85b641bde\r\nTimestamp: 2016-06-03 23:11:56Z","error_codes":[90019],"timestamp":"2016-06-03 23:11:56Z","trace_id":"5d12a6bf-2178-42bc-9e51-7aa73b1d6c9e","correlation_id":"05f7532f-0075-438f-80e4-efd85b641bde"};

Unknown location

AggregateException: Unhandled remote failure.

Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.<HandleRemoteCallbackAsync>d__5.MoveNext()

Each next attempt to login gives the same error (but without asking for permission).

What can be wrong ?

Thanks in advance for any advice.


Solution

  • As it's important for me, I have opened issue #866 on GitHub: External login via Microsoft Account failed on RC2/RC3

    I will keep this thread updated ;)


    Update:

    Like @Tratcher wrote:

    MicrosoftAccount was moved to the new v2 endpoints which requires re-registering your application Active Drectory v2 App Registration


    It's solution in my case. After registering new App on My applications portal, everything works fine.

    Thanks Tratcher.