fix(oauth2): Fix crash when profile fields are missing (#5850)
Some checks failed
Build & run tests / Node 18 (push) Has been cancelled
Build & run tests / Node 20 (push) Has been cancelled
Build & run tests / Node 22 (push) Has been cancelled
Lint / Lint files (push) Has been cancelled

Co-authored-by: Lautaro Alvarez <lautaro@grava.digital>
This commit is contained in:
Lautaro Alvarez 2024-11-01 11:21:10 -03:00 committed by GitHub
parent 0f06adb9c7
commit 4fdab806a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 24 deletions

View file

@ -20,7 +20,7 @@ class OAuth2CustomStrategy extends Strategy {
userProfile (accessToken, done) {
this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
let json
let json, profile
if (err) {
return done(new InternalOAuthError('Failed to fetch user profile', err))
@ -33,7 +33,11 @@ class OAuth2CustomStrategy extends Strategy {
}
checkAuthorization(json, done)
const profile = parseProfile(json)
try {
profile = parseProfile(json)
} catch (ex) {
return done('Failed to identify user profile information', null)
}
profile.provider = 'oauth2'
done(null, profile)
@ -97,7 +101,7 @@ function checkAuthorization (data, done) {
OAuth2CustomStrategy.prototype.userProfile = function (accessToken, done) {
this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
let json
let json, profile
if (err) {
return done(new InternalOAuthError('Failed to fetch user profile', err))
@ -110,7 +114,11 @@ OAuth2CustomStrategy.prototype.userProfile = function (accessToken, done) {
}
checkAuthorization(json, done)
const profile = parseProfile(json)
try {
profile = parseProfile(json)
} catch (ex) {
return done('Failed to identify user profile information', null)
}
profile.provider = 'oauth2'
done(null, profile)