Using Memberstack OIDC with Auth0

Article author
Duncan from Memberstack
  • Updated

If you’re using Auth0, you can add Memberstack as a custom social connection.

Step 1 - Memberstack Settings

Follow this tutorial to setup an SSO app integration on the Memberstack dashboard: https://docs.memberstack.com/hc/en-us/articles/8161104982043-Custom-SSO-Integrations

📌 Copy your Client ID and Client Secret from this step, you’ll need them in the next step!

Step 2 - Auth0 Settings

From your dashboard in Auth0

  1. navigate to Authentication → Social on the left sidebar
  2. Click “Social” from the submenu and from that screen
  3. Click the “+ Create Connection” button

You’ll be taken to a page called New Social Connection, scroll all the way to the bottom and select “create custom”.

Step 3 - Credentials

On the settings tab of your custom social connection, fill in the following values:

Authorization URL:https://auth.memberstack.com/authorize

Token URL: https://auth.memberstack.com/oauth/token

Scope:openid email profile

Client ID:<your client id> (from the previous step)

Client Secret:<your client secret> (from the previous step)

Fetch User Profile Script

function fetchUserProfile(accessToken, context, callback) {
  request.get(
    {
      url: 'https://auth.memberstack.com/userinfo',
      headers: {
        'Authorization': 'Bearer ' + accessToken,
      }
    },
    (err, resp, body) => {
      if (err) {
        return callback(err);
      }
      if (resp.statusCode !== 200) {
        return callback(new Error(body));
      }
      let bodyParsed;
      try {
        bodyParsed = JSON.parse(body);
      } catch (jsonError) {
        return callback(new Error(body));
      }
    
      const profile = {
        user_id: bodyParsed.sub,
        email: bodyParsed.email,
        name: bodyParsed.name,
        nickname: bodyParsed.name
      };
      callback(null, profile);
    }
  );
}

Step 4 - Testing

Test your connection by clicking “Try Connection”. Use member credentials from the Memberstack account that you created the SSO integration for. If you created a test mode SSO integration, use test mode member credentials!

You’ll see a payload of profile data with your Memberstack info if successful!

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.