Open Closed

Social login buttons are not visible. #4952


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

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


26 Answer(s)
  • 0
    alper created

    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] social-auth.jpg

  • 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?

  • 0
    alper created

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

  • 0
    affern created

    alper: 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;

  • 0
    aaron created

    Did you select a tenant on the Login page?

  • 0
    affern created

    aaron: Did you select a tenant on the Login page?

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

  • 0
    aaron created

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

  • 0
    affern created

    aaron: 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.

  • 0
    aaron created

    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

  • 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.

  • 0
    aaron created

    You can refer to this commit: 0c71eef

  • 0
    affern created

    aaron: 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.

  • 0
    aaron created

    Then you need this commit too: b0b7919

  • 0
    affern created

    aaron: 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

  • 0
    aaron created

    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.

  • 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 :(

  • 0
    affern created

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

  • 0
    aaron created

    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.

  • 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.

  • 0
    aaron created

    Both resolve/inject the same singleton instance.

  • 0
    affern created

    And TokenAuthController has not been changed since version 5.0.0?

  • 0
    aaron created

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

  • 0
    affern created

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

  • 0
    ismcagdas created

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

  • 0
    affern created

    ismcagdas: @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 (https://aspnetzero.com/Documents/Extend ... ty-to-user) it does'nt explain how we add properties for register page and to ExternalAuthUserInfo for social logins.

  • 0
    ismcagdas created

    Hi @affern,

    Thank you for finding the problem. You can create a new class and add it as the second parameter for https://github.com/aspnetzero/aspnet-ze ... er.cs#L342.

    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.