Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1601 Add support for social login #1602

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

taurgis
Copy link

@taurgis taurgis commented Dec 7, 2023

Description

Adding IDP login to the PWA Kit has gotten quite a bit of questions lately on Slack, and they say an example said more than a thousand words? Wait.... that's not the saying

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)
Screen.Recording.2023-12-06.at.14.38.53.mov

Configuration required in SLAS:

Additional redirect URLs required:

http://localhost:3000/idp-callback|https://*.mobify-storefront.com/callback|https://*.mobify-storefront.com/idp-callback

Screenshot 2023-12-07 at 15 48 54

IDP Configuration Required

Screenshot 2023-12-07 at 15 49 44

Fix linting errors

Correct imports after auto-fix by linting

Change button on registration to call login

Refactored the way the redirect URL is built up.

Refactoring: Removing unnecessary code
@taurgis taurgis requested a review from a team as a code owner December 7, 2023 14:47
*
* See https://github.com/SalesforceCommerceCloud/pwa-kit/blob/3.0.0/packages/commerce-sdk-react/src/auth/index.ts#L302
*/
auth.handleTokenResponse(tokenResponse)
Copy link
Author

@taurgis taurgis Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a workaround since this isn't part of the package. Unsure how you would like to see this handled. The reason the authentication is completely separated is because these items are part of the isomorphic SDK.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small question on this: it works only because this file is in js rather than ts and thus doesn't respect the private keyword since it's a compile time annotation, right?

Copy link
Author

@taurgis taurgis Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. This could be changed if I add this function to the Auth.js

async loginIDPUser(body: { code: string; usid: string, redirectURI: string }) {
           return await this.queueRequest(
            () => {
                const tokenBody = {
                    code: body.code,
                    usid: body.usid,
                    grant_type: 'authorization_code_pkce',
                    redirect_uri: body.redirectURI,
                    code_verifier: localStorage.getItem('codeVerifier') || '',
                    client_id: this.client.clientConfig.parameters.clientId,
                    channel_id: this.client.clientConfig.parameters.siteId
                };

                return this.client.getAccessToken({ body: tokenBody });
            },
            false
        )
    }

Copy link
Collaborator

@bfeister bfeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First off, 👏 we really appreciate contributions like this for key features!

Second, 😂 it's true. Code is worth more than 1,000 words or a picture! (sometimes)

@taurgis I'm trying to think through how this interfaces with plugin_slas. I could be wrong, but I feel like plugin_slas is where we most frequently hear complaints about lack of IDP / federated login. In plugin_slas we hook into Account-SubmitRegistration controller in SFRA. Mentioned in [this REDESIGN.md doc](https://github.com/SalesforceCommerceCloud/plugin_slas/blob/develop/REDESIGN.md - search for Account-SubmitRegistration). I wonder if this is something to be concerned about... thoughts @vcua-mobify @shethj ?

In this PR, it feels like we're sidestepping "real registration" by going directly from PWA Kit to the IDP provider. Correct me if I'm wrong, but we don't actually go through a real user registration on the SLAS side in this, do we?

And if the answer there is "no, it follows the guest slas auth flow" we end up in a situation where "real authenticated users" that come in via IDP kind of unintentionally mess around with the data because everyone appears to be a guest.

Perhaps this is ok, but also, perhaps it's not. Will require some more thought and discussion.

@taurgis
Copy link
Author

taurgis commented Dec 7, 2023

First off, 👏 we really appreciate contributions like this for key features!

Second, 😂 it's true. Code is worth more than 1,000 words or a picture! (sometimes)

@taurgis I'm trying to think through how this interfaces with plugin_slas. I could be wrong, but I feel like plugin_slas is where we most frequently hear complaints about lack of IDP / federated login. In plugin_slas we hook into Account-SubmitRegistration controller in SFRA. Mentioned in [this REDESIGN.md doc](https://github.com/SalesforceCommerceCloud/plugin_slas/blob/develop/REDESIGN.md - search for Account-SubmitRegistration). I wonder if this is something to be concerned about... thoughts @vcua-mobify @shethj ?

In this PR, it feels like we're sidestepping "real registration" by going directly from PWA Kit to the IDP provider. Correct me if I'm wrong, but we don't actually go through a real user registration on the SLAS side in this, do we?

And if the answer there is "no, it follows the guest slas auth flow" we end up in a situation where "real authenticated users" that come in via IDP kind of unintentionally mess around with the data because everyone appears to be a guest.

Perhaps this is ok, but also, perhaps it's not. Will require some more thought and discussion.

Also, this PR does not need to be merged in my eyes, but could also serve as an example to get your own internal implementation going. There are a few dependencies that will indeed warrant discussion.

@vcua-mobify
Copy link
Contributor

First, I want to echo @bfeister and say thanks for this @taurgis !

@bfeister, as you say, plugin_slas also does not have support for federated login. If we were to add support there, at a high level it would follow the same steps done here and as outlined in the SLAS documentation.

In this PR, it is a separate flow from the out of the box guest or registered login flows. It looks similar to the guest flow in that there is a call to SLAS /authorize. Good question on whether everyone will appear afterward as a guest. I would think because in the /authorize call hint is set to idp rather than guest, users will be appropriately marked as registered within SLAS but it is something to verify.

We'll also have to think about the new user registration signup case but I think that can be handled by the idp so from our perspective it might just go through the same flow as shown in this PR

Fix linting

Fix linting error

Update translations

Update pseudo translations
@unnii
Copy link

unnii commented Mar 7, 2024

Hi @taurgis
During the OAuth flow with Facebook, we only receive a code parameter in the response without a usid. Is there a recommended approach or additional step to retrieve or generate a usid after receiving the authorization code from Facebook?
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants