Base solution for your next web application
Open Closed

Social login buttons are not visible. #4952


User avatar
0
affern created

Hello. I'm trying to enable social login buttons for Google and Facebook. I have registered my app and have my authentication keys in appsettings.json and set "IsEnabled": "true". But GetExternalAuthenticationProviders() in TokenAuthController returns 0.

I can see that ConfigureExternalAuthProviders() in GlobalOpinionsWebHostModule class is adding my providers to the list when the solution starts up.

So why can _externalAuthConfiguration.Providers in this code return 0?

[HttpGet] public List<ExternalLoginProviderInfoModel> GetExternalAuthenticationProviders() { return ObjectMapper.Map<List<ExternalLoginProviderInfoModel>>(_externalAuthConfiguration.Providers); }

Is there something I've forgotten? I'm using the Angular version.


26 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    Hi,

    The only thing you might be missing can be appsettings.production.jsonand appsettings.Staging.json Sometimes developers forget that they are on production or stating servers. And they don't configure those settings files. You can see in the below pic, I just set appsettings.json and in debugger attached mode I see the values. [attachment=0:7twiy9l8]social-auth.jpg[/attachment:7twiy9l8]

  • User Avatar
    0
    affern created

    No, I have not forgotten it.
    ConfigureExternalAuthProviders() in GlobalOpinionsWebHostModule class is adding my providers to the list when the solution starts up. It must be something else. Where is the code that fills providers in _externalAuthConfiguration.Providers?

  • User Avatar
    0
    alper created
    Support Team

    You need to be tenant to see social logins. Don't use HOST

  • User Avatar
    0
    affern created

    <cite>alper: </cite> You need to be tenant to see social logins. Don't use HOST

    I don't understand what you mean. What do you mean you need to be a tenant? When I run in debugger attached mode, _externalAuthConfiguration.Providers returns 0;

  • User Avatar
    0
    aaron created
    Support Team

    Did you select a tenant on the Login page?

  • User Avatar
    0
    affern created

    <cite>aaron: </cite> Did you select a tenant on the Login page?

    I have disabled MultiTenancy, so this is not an option.

  • User Avatar
    0
    aaron created
    Support Team

    Which version of ASP.NET Zero are you on? That was fixed in v5.1.0.

  • User Avatar
    0
    affern created

    <cite>aaron: </cite> Which version of ASP.NET Zero are you on? That was fixed in v5.1.0.

    It says v5.0.0.0 but I just upgraded all my nuget packages , and the version did'nt change.

  • User Avatar
    0
    aaron created
    Support Team

    ASP.NET Zero refers to the solution that you download, not the NuGet packages.

    How to migrate existing solution: https://github.com/aspnetzero/aspnet-zero/issues/96#issuecomment-268093697

  • User Avatar
    0
    affern created

    Was this a major bugfix or can I get the code and paste it into my solution? It is importent for me to solve this issue.

  • User Avatar
    0
    aaron created
    Support Team

    You can refer to this commit: 0c71eef

  • User Avatar
    0
    affern created

    <cite>aaron: </cite> You can refer to this commit: 0c71eef

    Thanks, but my problem is in the api side. If you read my first post I have described my problem. If I debug I don't get the same result as Alper. His solution returns a list of ExternalLoginProviders from TokenAuthController. But my solution returns zero even if I have configured my provider settings in appsettings.json.

  • User Avatar
    0
    aaron created
    Support Team

    Then you need this commit too: b0b7919

  • User Avatar
    0
    affern created

    <cite>aaron: </cite> Then you need this commit too: b0b7919

    My solution already have this code. And when I debug, I can see this code in WebHostModule work. When it starts up it adds the authentication providers to the list in ConfigureExternalAuthProviders() method. But when the method GetExternalAuthenticationProviders() in the TokenAuthController class is calling this code, it returns 0; I don't get any exceptions.

    Where is the code that is going to fill _externalAuthConfiguration.Providers in this method?

    [HttpGet] public List<ExternalLoginProviderInfoModel> GetExternalAuthenticationProviders() { return ObjectMapper.Map<List<ExternalLoginProviderInfoModel>>(_externalAuthConfiguration.Providers); }

  • User Avatar
    0
    aaron created
    Support Team

    Where is the code that is going to fill _externalAuthConfiguration.Providers in this method?

    As you have identified:

    ConfigureExternalAuthProviders() in GlobalOpinionsWebHostModule class is adding my providers to the list when the solution starts up.

  • User Avatar
    0
    affern created

    When the api-solution starts up, PostInitialize() in WebHostModule calls ConfigureExternalAuthProviders() and adds the ExternalLoginProviders to the list. But GetExternalAuthenticationProviders() in TokenAuthController does'nt get called before the Angular solution loads the login page. And then it don't hit the code in the WebHostModule.

    The interface IExternalAuthConfiguration is injected into TokenAuthController, but I can't find out how the code that resolves the mapping to this interface is :(

  • User Avatar
    0
    affern created

    @ismcagdas, maybe you can help me with this problem? :)

  • User Avatar
    0
    aaron created
    Support Team

    But GetExternalAuthenticationProviders() in TokenAuthController does'nt get called before the Angular solution loads the login page. And then it don't hit the code in the WebHostModule.

    It's called in login.service.ts.

  • User Avatar
    0
    affern created

    Yes, I know that. But what I'm trying to say is that GetExternalAuthenticationProviders() in TokenAuthController can't access the code in the WebHostModule in my solution.

  • User Avatar
    0
    aaron created
    Support Team

    Both resolve/inject the same singleton instance.

  • User Avatar
    0
    affern created

    And TokenAuthController has not been changed since version 5.0.0?

  • User Avatar
    0
    aaron created
    Support Team

    Yeah. You have access to the source code and commit history.

  • User Avatar
    0
    affern created

    It is also up to date. I have no idea what may be wrong :?

  • User Avatar
    0
    ismcagdas created
    Support Team

    @affern are you trying with a Tenant ? Becaue those buttons are not visible for Host.

  • User Avatar
    0
    affern created

    <cite>ismcagdas: </cite> @affern are you trying with a Tenant ? Becaue those buttons are not visible for Host.

    @ismcagdas, I found the cause of the bug. I have added new properties to the User class, like Gender, Birthyear, CountryId and Address. My users need to registrate these values in my registration page. In the new version the class ExternalAuthUserInfo is an AspNetZero type, so I continued with the old ExternalAuthUserInfo class and added my own properties to this the class. But this is why I get the bug. If I use the aspnetzero type it works fine. But how should I add my properties to the ExternalAuthUserInfo? From this example (<a class="postlink" href="https://aspnetzero.com/Documents/Extending-Existing-Entities#add-new-property-to-user">https://aspnetzero.com/Documents/Extend ... ty-to-user</a>) it does'nt explain how we add properties for register page and to ExternalAuthUserInfo for social logins.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @affern,

    Thank you for finding the problem. You can create a new class and add it as the second parameter for <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/master/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Core/Controllers/TokenAuthController.cs#L342">https://github.com/aspnetzero/aspnet-ze ... er.cs#L342</a>.

    You can also create a new method in UserRegistrationManager which gets your new parameters as well. It's code will be similar to existing RegisterAsync but you will set your new parmeters on user as you like.