|
|
@ -82,7 +82,7 @@ class OAuth2Service extends SiteService { |
|
|
|
const client = await OAuth2Client |
|
|
|
.findOne({ _id: clientId }) |
|
|
|
.lean(); |
|
|
|
this.log.debug('OAuth2 client loaded', { clientId, client }); |
|
|
|
this.log.debug('OAuth2 client loaded', { clientId }); |
|
|
|
return done(null, client); |
|
|
|
} catch (error) { |
|
|
|
this.log.error('failed to deserialize OAuth2 client', { clientId, error }); |
|
|
@ -139,6 +139,7 @@ class OAuth2Service extends SiteService { |
|
|
|
}); |
|
|
|
return done(null, false); |
|
|
|
} |
|
|
|
this.log.info('client authorization processed', { clientID }); |
|
|
|
return done(null, client, client.callbackUrl); |
|
|
|
} catch (error) { |
|
|
|
this.log.error('failed to process OAuth2 authorize', { error }); |
|
|
@ -149,6 +150,7 @@ class OAuth2Service extends SiteService { |
|
|
|
async processGrant (client, redirectUri, user, ares, done) { |
|
|
|
try { |
|
|
|
var code = uuidv4(); |
|
|
|
|
|
|
|
var ac = new OAuth2AuthorizationCode({ |
|
|
|
code, |
|
|
|
client: client._id, |
|
|
@ -157,6 +159,8 @@ class OAuth2Service extends SiteService { |
|
|
|
scopes: client.scopes, |
|
|
|
}); |
|
|
|
await ac.save(); |
|
|
|
|
|
|
|
this.log.info('OAuth2 grant processed', { clientID: client._id, scopes: client.scopes }); |
|
|
|
return done(null, code); |
|
|
|
} catch (error) { |
|
|
|
this.log.error('failed to process OAuth2 grant', { error }); |
|
|
@ -178,7 +182,6 @@ class OAuth2Service extends SiteService { |
|
|
|
}, |
|
|
|
]); |
|
|
|
|
|
|
|
this.log.debug('process OAuth2 exchange', { client, code, redirectUri }); |
|
|
|
if (!client._id.equals(ac.client._id)) { |
|
|
|
this.log.alert('OAuth2 client ID mismatch', { provided: client.id, onfile: ac.client._id }); |
|
|
|
return done(null, false); |
|
|
@ -197,7 +200,7 @@ class OAuth2Service extends SiteService { |
|
|
|
}); |
|
|
|
await at.save(); |
|
|
|
|
|
|
|
this.log.debug('OAuth2 grant exchanged for token', { client, code, token: at.token }); |
|
|
|
this.log.info('OAuth2 grant exchanged for token', { clientID: client._id }); |
|
|
|
return done(null, token); |
|
|
|
} catch (error) { |
|
|
|
this.log.error('failed to process OAuth2 exchange', { error }); |
|
|
|