Auth0 custom social connection not working with Reddit oAuth

Hey,’
I am trying to create a custom social connection for reddit. My settings are:
Auth URL: reddit.com: Log in
Client ID:
Secret:

Token URL: https://www.reddit.com/api/v1/access_token

Scope:
identity

Fetch user profile script:
function(accessToken, ctx, cb) {
request.get(‘https://oauth.reddit.com/api/v1/me’, {
headers: {
‘Authorization’: 'Bearer ’ + accessToken
}
}, function(e, r, b) {
if (e) return cb(e);
if (r.statusCode !== 200) return cb(new Error('StatusCode: ’ + r.statusCode));
var profile = JSON.parse(b).data;
profile.user_id = profile.id;
cb(null, profile);
});
}

Custom headers:
{
“Authorization”: “Basic <MY AUTH BASE 64 STRING>”

This correctly gets me to reddit authorization page and lets me allow, but fails with “invalid_grant” “Invalid authorization code”.
Which from here the docs say:
invalid_grant The code has expired or already been used Ensure that you are not attempting to re-use old code s - they are one time use.

Would the custom social connection somehow be reusing an old code? Anyone gotten this to work?

Maybe because your User-Agent header is missing? I was getting a 403 without it. I was able to create a Reddit social connection with the following:

Authorization URL:
https://www.reddit.com/api/v1/authorize

Token URL:
https://www.reddit.com/api/v1/access_token

Scope:
identity

Fetch User Profile Script:

function(accessToken, ctx, cb) {
  request.get({
    url: 'https://oauth.reddit.com/api/v1/me',
    headers: {
      'Authorization': 'Bearer ' + accessToken,
      'User-Agent': 'Auth0'
    }
  }, function(e, r, b) {
    if (e) return cb(e);
    if (r.statusCode !== 200) return cb(new Error('StatusCode: ' + r.statusCode));
    var profile = JSON.parse(b);
    profile.user_id = profile.id;
    cb(null, profile);
  });
}

Custom Headers:

{
  "Authorization": "Basic SklBNDAtUmJhSjZBRVE6eHRkTUVyUUVFb3VoaEdFSTZVV21WVnBWV2tsM2xR"
}
1 Like