Patreon Custom Social Connection Sample: Basics

Having seen a few developers ask about how to configure a Custom Social Connection for Patreon in Auth0 in various forums, I decided to try this out recently and found it to work with a bit of finagling of the Fetch User Profile Script. While this isn’t a full tutorial, here’s what I did in a nutshell and a starting sample of the code you’ll need to fetch the user profile successfully.

Patreon Client

First start by creating a Patreon Client for your account following Patreon’s docs (API Reference). You don’t need to publish this Client. You’ll want to use https://<yourtenant>.auth0.com/login/callback as your Redirect URI in the Client settings. Note that you’ll need the Client ID and Client Secret and some URIs from the docs next when you configure the Custom Social Connection in Auth0.

Auth0 Custom Social Connection

You’ll then create a new Social Connection in your Auth0 tenant, and you’ll find Create Custom at the very bottom of the list. You’ll need to configure a few fields with the urls from Patreon’s docs: for me at time of writing with Patreon v2 API the following works:

Authorization url: https://www.patreon.com/oauth2/authorize
Token url: https://www.patreon.com/api/oauth2/token

Client ID and Client Secret: from your Patreon Client

Fetch User Profile Script:

    function(accessToken, ctx, cb) {
    request.get('https://www.patreon.com/api/oauth2/api/current_user', {
        headers: {
          'authorization': 'Bearer ' + accessToken
        }
      }, function(e, r, b) {
        if (e) return cb(e);
        if (r.statusCode !== 200) return cb(new Error('StatusCode: ' + r.statusCode));
        const patreonProfile = JSON.parse(b);
        const profile = {
          user_id: patreonProfile.data.id,
          ... patreonProfile.data.attributes,
        };
        cb(null, profile);
      });
    }

Save this and hit Try Connection, and it should work for you. Happy coding!

2 Likes

Thanks for sharing that with the rest of community @nick.wade !

1 Like