Skip to content

Commit

Permalink
fix: avoid duplicate strategy verify callback method
Browse files Browse the repository at this point in the history
  • Loading branch information
Paramesh Kamarthi committed Oct 26, 2023
1 parent 77bc871 commit f7c63dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export type ProviderOptionsType = {
export const affinidiPassport = passport

export const affinidiProvider = async (app: any, options: ProviderOptionsType) => {
const { client, strategy, sessionKey } = await AffinidiStrategy(options)

//setting default
options = {
verifyCallback: (req: any, tokenSet: TokenSet, userinfo: unknown, done: Function) => {
return done(null, tokenSet.claims())
Expand All @@ -46,6 +45,7 @@ export const affinidiProvider = async (app: any, options: ProviderOptionsType) =
},
...options,
}
const { client, strategy, sessionKey } = await AffinidiStrategy(options)

passport.use(options.id, strategy)

Expand Down
11 changes: 2 additions & 9 deletions src/strategy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Issuer, Strategy, TokenSet } from 'openid-client'
import { Issuer, Strategy } from 'openid-client'
import { ProviderOptionsType } from '.'

export default async function AffinidiStrategy(options: ProviderOptionsType) {
Expand All @@ -25,16 +25,9 @@ export default async function AffinidiStrategy(options: ProviderOptionsType) {
token_endpoint_auth_method: 'client_secret_post',
})

const defaultVerifyCallback = (req: any, tokenSet: TokenSet, userinfo: unknown, done: Function) => {
return done(null, tokenSet.claims())
}

return {
client,
sessionKey,
strategy: new Strategy(
{ client, sessionKey, passReqToCallback: true },
options.verifyCallback || defaultVerifyCallback,
),
strategy: new Strategy({ client, sessionKey, passReqToCallback: true }, options.verifyCallback),
}
}

0 comments on commit f7c63dd

Please sign in to comment.