Home GetExternalLoginInfo() returning null
Reply: 0

GetExternalLoginInfo() returning null

user3142 Published in March 23, 2018, 10:39 pm

I have registered my mvc app with https://apps.dev.microsoft.com/ and (when on localhost),after updating all NuGet packages managed to authenticate users (using a clientid and secret) using microsoft authentication - that works fine! lets forget the time wasted to discover that I had to use https://localhost:xxxx/signin-microsoft - thought I had to supply my callback method endpoint.

Now, I had to do the same thing however authenticating users with my app registered on Azure Active Directory in the section App Registrations. Note: Users are not registered in azure but on a different domain however using microsoft authentication. I just changed the client id and secret to specify those generated on azure while registering the app. My Callback method is being accessed after signing in HOWEVER, the loginInfo object which I need to read the email of my user is NULL. I made sure i had the latest updates of packages, and i tried to search spending 3 days finding only applications which make use of tenants id, authority etc.

I just need to use individual accounts signing with microsoft authentication with an application registered on AAD (Azure active directory - registered apps section). I know it works because i've seen it working with php on other apps, but with microsoft code/libraries its not.

btw i tried adding scopes, calling synchronous to no good. I also tried inspecting the incoming data and its saying access denied and i'm pretty sure that client id and secret are ok. maybe the reply url is wrong? but any other callbacks i supply result in bad request and the callback method is at least being triggered. I also enabled "Sign Users In" and "Sign in and read users profile" permissions from azure as well. I'm running out of ideas. any help would be much appreciated. thanks

Code is the same code which is given to you when creating a new mvc web application using individual accounts i.e. In Startup.Auth.cs: i have this important part and other code

var myObj = new MicrosoftAccountAuthenticationOptions()
            ClientId = "xxx",
            ClientSecret = "xxx",

       // myObj.Scope.Add("User.Read");

In AccountController.cs i have this method which is initializing the request to microsoft

    public ActionResult ExternalLogin(string provider, string returnUrl)
        // Request a redirect to the external login provider
        return new ChallengeResult(provider, 
   Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl 

and this (part of a) method which is handling the callback response:

    public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
       var loginInfo = await  
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302918 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO