How to use external login provider with custom user store RRS feed

  • Question

  • User-1204646426 posted

    Hello, I am developing an ASP.NET MVC 5 Web application that allows user to authenticate using an external provider and .NET User Identity.

    In Internet there are a lot of information teaching how to enable external login providers, but none teaches how to actually authenticate the user in the system when login returns to the MVC site. All information I have found assumes developer is using the default ASP.NET identity user store, so it tells nothing about what to do next.

    For example, in Google, when user selects the Google account, the call returns to the site and run the method FindAsync of the custom user store, but, after that, how can I actually log the user in?

    This is one my attempts to retrieve the user e-mail (in the custom user store class):

        public Task<T> FindAsync(UserLoginIn fo login)
            var info = AuthenticationManager.GetExternalLoginInfoAsync().Result;
            var emailClaim = externalIdentity.Result.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email);

    But GetExternalLoginInfoAsync does not belong to AuthenticationManager object.

    I have read that Microsoft.AspNet.Identity.Owin should be included, but in my case, that NuGet package is already included, and of course, the corresponding using statement is present in the code.

    I have seen that the callback function in AccountController does contain the user e-mail and username coming from the external provider but it calls the Find method of SigningManager only with part of the information containing a provider key and provider name. That causes the Find method of custom user store to have a parameter I showed in the question . I can solve it by replacing the SigningManager method, but I think that is not the correct way to manage it.

    Any help, please?

    Monday, November 30, 2020 12:59 PM

All replies

  • User-939850651 posted

    Hi jstuardo,

    But GetExternalLoginInfoAsync does not belong to AuthenticationManager object.

    What does it mean? Did you quote the wrong dependency?

    If you need to use external authentication, then you need the application id and secret key (Example: clientId&clientSecret) provided by a third party to work properly.

    You could also refer to this document for more details.

    Best regards,

    Xudong Peng

    Tuesday, December 1, 2020 11:07 AM
  • User753101303 posted


    And in your code what is AuthenticationManager? AFAIK it should be returned from be an object returned from https://docs.microsoft.com/en-us/previous-versions/aspnet/mt152055(v=vs.113)

    Tuesday, December 8, 2020 12:00 PM