Home GetExternalLoginInfo() returning null
Reply: 1

GetExternalLoginInfo() returning null

ryana
1#
ryana Published in 2018-01-12 17:18:44Z

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("openid");
        myObj.Scope.Add("email");
       // myObj.Scope.Add("User.Read");
        app.UseMicrosoftAccountAuthentication(myObj);

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

[HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    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:

  [AllowAnonymous]
    public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
    {
       var loginInfo = await  
   AuthenticationManager.GetExternalLoginInfoAsync();
    //...
    }
ryana
2#
ryana Reply to 2018-01-13 11:59:54Z

ok solved. the solution i provided earlier in my question works for an application registered on https://apps.dev.microsoft.com/ . when i registered my app on AzureAD it had to be done in a different way following this method: https://docs.microsoft.com/en-us/azure/active-directory/develop/guidedsetups/active-directory-aspnetwebapp

You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO