auth0 / custom-social-connections

http://auth0.github.io/custom-oauth2-dashboard
MIT License
29 stars 30 forks source link

Improve example code for `fetchUserProfile` stub #27

Open jamietanna opened 6 years ago

jamietanna commented 6 years ago

✏️ Changes

Improve example code for fetchUserProfile stub

πŸ“· Screenshots

If there were visual changes to the application with this change, please include before and after screenshots here. If it has animation, please use screen capture software like to make a gif.

πŸ”— References

N/A

🎯 Testing

  1. Browse to Custom Social Connections
  2. Click + New Connection
  3. Verify that Fetch User Profile Script is set to the updated value

πŸš€ Deployment

This change can be merged at any time.

🎑 Rollout

In order to verify that the deployment was successful we will need to verify that the example code is created as per steps in Testing.

πŸ”₯ Rollback

We will rollback if the changes introduce breaking JavaScript example code.

πŸ“„ Procedure

This will be done via a git revert on the merge commit that introduces this changes.

πŸ–₯ Appliance

Note to reviewers: ensure that this change is compatible with the Appliance.

fyockm commented 6 years ago

@jamietanna thanks for you submission! I would love to take this one step further with an example. Maybe something like this (untested)?

        fetchUserProfile: [
                          'function(accessToken, ctx, cb) {',
                          '  // TODO: call OAuth2 API with the `accessToken` and set the user\'s `profile`',
                          '  var url = 'https://oauth2provider.com/oauth/authorize; // replace with actual url',
                          '  request.get(url, {',
                          '    headers: { Authorization: \'Bearer \' + accessToken }',
                          '    json: true',
                          '  }, function(err, resp, profile) {',
                          '    if (err) return cb(err);',
                          '    if (resp.statusCode !== 200) return cb(new Error('StatusCode: ' + resp.statusCode));',
                          '    profile.user_id = profile.id;',
                          '    cb(null, profile);',
                          '   });',
                          '}'
                          ].join('\n')
jamietanna commented 6 years ago

Great idea @fyockm, I'll try and update with a better example this weekend!

fyockm commented 5 years ago

@jamietanna are you still interested in updating this PR?

jamietanna commented 3 years ago

Apologies @fyockm, I've amended now :+1:

fyockm commented 3 years ago

πŸ‘‹ hey @jamietanna! great to see you come back to this PR. thanks for updating- the change LGTM.

that said, ownership of this repo has changed here at Auth0 and have alerted the new team.