You have no items in your shopping cart.

Saturday, April 27, 2024 8:48:06 AM

How to detect it was a Social Login

Posted: 8 months ago

#13546 Quote

irina.a

Posted: 8 months ago

#13546 Quote
Hi, we want to add Social Login plugin for Nop 4.6 to our website.

I have configured Google OAuth and I can login successfully. However I can't figure out how to detect if the current user has logged in through normal Username and Password or through Social Login.

Use case - only users that have logged in through Social Login are able to access a specific website section.

User logs in using Social Login (Google)
User tries to access a specific website section.
User is allowed access.

User logs in using Username and Password.
User tries to access a specific website section.
User is Forbidden to access it.

I am trying to implement a CustomAuthorizeAttribute that is able to check the current user's logged in method.

Can you guide me what to use for that?
The ExternalAuthentication cookie doesn't seem to be set. And I saw no Claim like ClaimTypes.AuthenticationMethod indicating the current login method used.

Thank you.

Posted: 8 months ago

#13547 Quote

Support

Posted: 8 months ago

#13547 Quote
The customer account is linked to the ExternalAuthenticationRecord

Posted: 8 months ago

#13548 Quote

irina.a

Posted: 8 months ago

#13548 Quote
Hi,
I've seen the accounts are linked.

But that does not help me to detect every time an user logs in, whether they have logged in using their username and password, or using Google authentication.

For an user with a linked account, what can I use to detect at runtime if the user  has used it's Username + password to login, or it's Google account.
Thank you.

Posted: 8 months ago

#13549 Quote

Support

Posted: 8 months ago

#13549 Quote
I have understood you.
You want to know if the user uses Google Sing In or Nopcommerce Login.
You can create the plugin and check if the customer was SignIn  from nopcommerce login and save the information about it in the cookies/or in the table.
By default nopcommerce doesn't have this feature.

Posted: 7 months ago

#13550 Quote

irina.a

Posted: 7 months ago

#13550 Quote
Thank you, I'll investigate what can be done.
It would have been easier if the Social Login plugin would have set the ClaimTypes.AuthenticationMethod indicating the current login method used.

Posted: 7 months ago

#13551 Quote

Support

Posted: 7 months ago

#13551 Quote
I'll add it.
Open the native Facebook OAuth plugin and show me the place when you want to add it.

Posted: 7 months ago

#13552 Quote

irina.a

Posted: 7 months ago

#13552 Quote
I decided to implement a custom Google login plugin instead of using SocialLogin plugin.

It will set the  "http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod" in "ExternalAuthenticationParameters->Claims" array.
When "ExternalAuthenticationParameters" is passed to "IExternalAuthenticationService" methods, I'll be able to detect if the external login type was Google.

Posted: 7 months ago

#13553 Quote

Support

Posted: 7 months ago

#13553 Quote
Upgrade the plugin and check this claim for Google OAuth
          ClaimActions.MapJsonKey(ClaimTypes.AuthenticationMethod, "GoogleOAuth");

Powered by nopCommerce

Copyright © 2023 FoxNetSoft. All rights reserved