Skip to content

Commit

Permalink
fix(model): support explicit client.id field in model methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jankapunkt committed Nov 1, 2024
1 parent c6aed50 commit 1498fbf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- added scope verification in authenticated routes
- improved internal logging
- fix bug in validation for custom models
- fix support for explicit `client.id` field

## 5.0.0
- sync support for @node-oauth/oauth2-server 5.x by
Expand Down
3 changes: 2 additions & 1 deletion lib/model/meteor-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export const saveAuthorizationCode = async (code, client, user) => {
redirectUri,
scope: code.scope,
client: {
id: client.clientId
// xxx: fix for newer oauth2-server versions
id: client.id ?? client.clientId
},
user: {
id: user.id
Expand Down
1 change: 1 addition & 0 deletions lib/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class OAuthMeteorModel {
async createClient ({ title, homepage, description, privacyLink, redirectUris, grants, clientId, secret }) {
this.log(`createClient (${redirectUris})`)
return createClient({
id: clientId, // xxx: fix for newer oauth2-server versions that explicitly check for .id presence
title,
homepage,
description,
Expand Down
10 changes: 6 additions & 4 deletions tests/oauth-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ describe('integration tests of OAuth2 workflows', function () {
authorizationCode,
expiresAt,
redirectUri: clientDoc.redirectUris[0]
}, { client_id: clientDoc.clientId }, { id: user._id })
}, clientDoc, { id: user._id })

const params = {
code: authorizationCode,
Expand All @@ -317,7 +317,7 @@ describe('integration tests of OAuth2 workflows', function () {
authorizationCode,
expiresAt,
redirectUri: clientDoc.redirectUris[0]
}, {}, { id: user._id })
}, clientDoc, { id: user._id })

const params = {
code: authorizationCode,
Expand Down Expand Up @@ -359,11 +359,13 @@ describe('integration tests of OAuth2 workflows', function () {
it('issues an access token for a valid request', async () => {
const authorizationCode = Random.id()
const expiresAt = new Date(new Date().getTime() + 30000)
await authCodeServer.model.saveAuthorizationCode({
const code = {
authorizationCode,
expiresAt,
redirectUri: clientDoc.redirectUris[0]
}, {}, { id: user._id })
}

await authCodeServer.model.saveAuthorizationCode(code, clientDoc, { id: user._id })

const params = {
code: authorizationCode,
Expand Down

0 comments on commit 1498fbf

Please sign in to comment.