Skip to content

Commit eae387e

Browse files
committed
Use /api/v1/user for obtaining user info (0.0.2)
1 parent 26e4e0e commit eae387e

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/strategy.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import APIError from './apiError'
55

66
const STRATEGY_NAME = 'netlify'
77
const PROVIDER_NAME = 'netlify'
8-
const USER_PROFILE_URL = 'https://api.netlify.com/api/v1/users'
8+
const USER_PROFILE_URL = 'https://api.netlify.com/api/v1/user'
99
const AUTHORIZATION_URL = 'https://app.netlify.com/authorize'
1010
const TOKEN_URL = 'https://api.netlify.com/oauth/token'
1111

@@ -50,13 +50,10 @@ export default class Strategy extends OAuth2Strategy {
5050
} catch (_) {
5151
return done(new Error('Failed to parse user profile (invalid JSON)'))
5252
}
53-
if (!Array.isArray(json)) {
54-
return done(new Error('Failed to read user profile data, expected array'))
55-
}
56-
const profile = parseUserProfile(json[0])
53+
const profile = parseUserProfile(json)
5754
profile.provider = PROVIDER_NAME
5855
profile._raw = _body
59-
profile._json = json[0]
56+
profile._json = json
6057
done(null, profile)
6158
})
6259
}

test/__mocks__/oauth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports.OAuth2 = () => {
66
get: (url: string, accessToken: string, callback: any): void => {
77
callback(
88
null,
9-
'[{"id": "1234", "full_name": "Test", "email": "[email protected]", "avatar_url": null}]',
9+
'{"id": "1234", "full_name": "Test", "email": "[email protected]", "avatar_url": null}',
1010
undefined
1111
)
1212
}

test/passport-netlify.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('Strategy', () => {
3535
strategy.userProfile('jibberishAccessToken', done)
3636
expect(theProfile).toEqual({
3737
_json: { avatar_url: null, email: '[email protected]', full_name: 'Test', id: '1234' },
38-
_raw: '[{"id": "1234", "full_name": "Test", "email": "[email protected]", "avatar_url": null}]',
38+
_raw: '{"id": "1234", "full_name": "Test", "email": "[email protected]", "avatar_url": null}',
3939
displayName: 'Test',
4040
emails: [{ value: '[email protected]' }],
4141
id: '1234',

0 commit comments

Comments
 (0)