Skip to content

Commit 76aa942

Browse files
committed
feat: allow koa context argument in idFactory and secretFactory
resolves #455
1 parent df12141 commit 76aa942

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

docs/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ Function used to generate random client identifiers during dynamic client regist
12921292

12931293
_**default value**_:
12941294
```js
1295-
function idFactory() {
1295+
function idFactory(ctx) {
12961296
return nanoid();
12971297
}
12981298
```
@@ -1432,7 +1432,7 @@ Function used to generate random client secrets during dynamic client registrati
14321432

14331433
_**default value**_:
14341434
```js
1435-
function secretFactory() {
1435+
function secretFactory(ctx) {
14361436
return base64url.encodeBuffer(crypto.randomBytes(64)); // 512 base64url random bits
14371437
}
14381438
```

lib/actions/registration.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module.exports = {
9393
const { oidc: { provider } } = ctx;
9494
const { idFactory, secretFactory } = instance(provider).configuration('features.registration');
9595
const properties = {};
96-
const clientId = idFactory();
96+
const clientId = idFactory(ctx);
9797

9898
const rat = new provider.RegistrationAccessToken({ clientId });
9999
ctx.oidc.entity('RegistrationAccessToken', rat);
@@ -108,7 +108,7 @@ module.exports = {
108108

109109
if (secretRequired) {
110110
Object.assign(properties, {
111-
client_secret: secretFactory(),
111+
client_secret: secretFactory(ctx),
112112
client_secret_expires_at: 0,
113113
});
114114
} else {
@@ -225,7 +225,7 @@ module.exports = {
225225

226226
if (secretRequired) {
227227
Object.assign(properties, {
228-
client_secret: secretFactory(),
228+
client_secret: secretFactory(ctx),
229229
client_secret_expires_at: 0,
230230
});
231231
} else {

lib/helpers/defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ const DEFAULTS = {
987987
* description: Function used to generate random client identifiers during dynamic
988988
* client registration
989989
*/
990-
idFactory: function idFactory() {
990+
idFactory: function idFactory(ctx) { // eslint-disable-line no-unused-vars
991991
return nanoid();
992992
},
993993

@@ -997,7 +997,7 @@ const DEFAULTS = {
997997
* description: Function used to generate random client secrets during dynamic
998998
* client registration
999999
*/
1000-
secretFactory: function secretFactory() {
1000+
secretFactory: function secretFactory(ctx) { // eslint-disable-line no-unused-vars
10011001
return base64url.encodeBuffer(crypto.randomBytes(64)); // 512 base64url random bits
10021002
},
10031003
},

types/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,8 @@ export interface Configuration {
886886
policies?: {
887887
[key: string]: (ctx: KoaContextWithOIDC, metadata: ClientMetadata) => CanBePromise<void | undefined>;
888888
};
889-
idFactory?: () => string;
890-
secretFactory?: () => string;
889+
idFactory?: (ctx: KoaContextWithOIDC) => string;
890+
secretFactory?: (ctx: KoaContextWithOIDC) => string;
891891
};
892892

893893
registrationManagement?: {

0 commit comments

Comments
 (0)