Vrunda Thacker
Vrunda Thacker

Reputation: 118

How to enable Cognito single sign-on between a Wordpress site and React app?

I have a WordPress Website that currently uses its own authentication. I am building a new web app on React which would be on its sub-domain.

I will be using AWS Cognito for authentication.

Now I want to enable a single sign-on between the Wordpress site and the React App via Cognito. i.e user logs in to the Wordpress site and when he navigates to the react app, he does not have to login again.

Please suggest how to achieve this.

Upvotes: 2

Views: 1690

Answers (1)

Rogi I.
Rogi I.

Reputation: 127

I am going through the exact same process right now. It's not simple, but from what I gather it is doable. There are some things you must reconcile first:

  1. You will need to set up a cognito user pool to house all of your user configurations going forward. You should set it up with the attributes and roles you currently use in WP, and to allow SSO.

  2. Your existing WP users will need to be imported into the Cognito User Pool. You will not be able to import their passwords unfortunately, so you will need to notify them to reset the passwords (I suggest sending them to the cognito hosted login page if you want to use a federated login with social providers such as facebook, google, apple, etc. - LinkedIn is a bit of a pain as it uses Auth0 but still doable).

  3. For the login integration, you will need to choose whether to use AWS AMPLIFY or just the JavaScript SDK. Several coders tried to convince me to use Amplify, but I felt the sdk was much cleaner. Especially for the Node.js as there arfe several packages you can use as well as the amazon docs ... https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html

  4. For the Wordpress, this is a bit more tedious. There is, AFAICT, one plugin made by miniOrange that allows you to directly integrate an app pool, but the free functionality is limited, the docs are outdated and obscure, and I generally don't have a good feeling about their longevity. Nonetheless, I am using it for now.

  5. Now for the fun part. Unifying the login between sites requires the use of Cognito's JWT tokens (JSON web tokens) to pass between sites. There are a number of docs that AWS offers, but none were clear to me, so I have resolved to hire someone to set these up. Here is a primer on that: https://itnext.io/aws-cognito-example-using-react-ui-and-node-js-rest-apis-part-3-jwt-secured-rest-apis-e56d336ce306

I know this is not a complete answer, but hopefully it saves you some time.

Upvotes: 1

Related Questions