Skip to content

Commit

Permalink
feat: allow koa context argument in idFactory and secretFactory
Browse files Browse the repository at this point in the history
resolves #455
  • Loading branch information
panva committed Jan 26, 2020
1 parent df12141 commit 76aa942
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ Function used to generate random client identifiers during dynamic client regist

_**default value**_:
```js
function idFactory() {
function idFactory(ctx) {
return nanoid();
}
```
Expand Down Expand Up @@ -1432,7 +1432,7 @@ Function used to generate random client secrets during dynamic client registrati

_**default value**_:
```js
function secretFactory() {
function secretFactory(ctx) {
return base64url.encodeBuffer(crypto.randomBytes(64)); // 512 base64url random bits
}
```
Expand Down
6 changes: 3 additions & 3 deletions lib/actions/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module.exports = {
const { oidc: { provider } } = ctx;
const { idFactory, secretFactory } = instance(provider).configuration('features.registration');
const properties = {};
const clientId = idFactory();
const clientId = idFactory(ctx);

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

if (secretRequired) {
Object.assign(properties, {
client_secret: secretFactory(),
client_secret: secretFactory(ctx),
client_secret_expires_at: 0,
});
} else {
Expand Down Expand Up @@ -225,7 +225,7 @@ module.exports = {

if (secretRequired) {
Object.assign(properties, {
client_secret: secretFactory(),
client_secret: secretFactory(ctx),
client_secret_expires_at: 0,
});
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ const DEFAULTS = {
* description: Function used to generate random client identifiers during dynamic
* client registration
*/
idFactory: function idFactory() {
idFactory: function idFactory(ctx) { // eslint-disable-line no-unused-vars
return nanoid();
},

Expand All @@ -997,7 +997,7 @@ const DEFAULTS = {
* description: Function used to generate random client secrets during dynamic
* client registration
*/
secretFactory: function secretFactory() {
secretFactory: function secretFactory(ctx) { // eslint-disable-line no-unused-vars
return base64url.encodeBuffer(crypto.randomBytes(64)); // 512 base64url random bits
},
},
Expand Down
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,8 @@ export interface Configuration {
policies?: {
[key: string]: (ctx: KoaContextWithOIDC, metadata: ClientMetadata) => CanBePromise<void | undefined>;
};
idFactory?: () => string;
secretFactory?: () => string;
idFactory?: (ctx: KoaContextWithOIDC) => string;
secretFactory?: (ctx: KoaContextWithOIDC) => string;
};

registrationManagement?: {
Expand Down

0 comments on commit 76aa942

Please sign in to comment.