Skip to content

Commit

Permalink
Changed user data endpoint to /decode and fixed let not hoisted issue
Browse files Browse the repository at this point in the history
  • Loading branch information
SayakMukhopadhyay committed Mar 3, 2019
1 parent e53eeb9 commit 2d1a8d8
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ util.inherits(Strategy, OAuth2Strategy);
* Retrieve user profile from Frontier.
*
* This function constructs a normalized profile.
* Along with the properties returned from /users/@me, properties returned include:
* - `connections` Connections data if you requested this scope
* - `guilds` Guilds data if you requested this scope
* Along with the properties returned from /me, properties returned include:
* - `iss` The identifier for the identity provider who issued the token
* - `iat` Issued at claim as a `Date`
* - `exp` The token expiry as a `Date`
* - `fetchedAt` When the data was fetched as a `Date`
* - `accessToken` The access token used to fetch the (may be useful for refresh)
*
Expand All @@ -59,23 +60,26 @@ util.inherits(Strategy, OAuth2Strategy);
* @access protected
*/
Strategy.prototype.userProfile = function (accessToken, done) {
this._oauth2.get('https://auth.frontierstore.net/me', accessToken, function (err, body, res) {
this._oauth2.get('https://auth.frontierstore.net/decode', accessToken, function (err, body, res) {
if (err) {
return done(new InternalOAuthError('Failed to fetch the user profile.', err))
}

try {
let parsedData = JSON.parse(body);

let profile = parsedData.usr; // has the /me endpoint response
profile.iss = parsedData.iss;
profile.iat = new Date(parsedData.iat * 1000);
profile.exp = new Date(parsedData.exp * 1000);
profile.provider = 'frontier';
profile.accessToken = accessToken;

profile.fetchedAt = new Date();
return done(null, profile)
} catch (e) {
return done(new Error('Failed to parse the user profile.'));
}

let profile = parsedData; // has the /me endpoint response
profile.provider = 'frontier';
profile.accessToken = accessToken;

profile.fetchedAt = new Date();
return done(null, profile)
});
};

Expand Down

0 comments on commit 2d1a8d8

Please sign in to comment.