Skip to content

Commit 2b8acd5

Browse files
authored
Merge pull request #29 from dynamic-labs/jesse/mfa-scopes
chore: update readme to include example for handling MFA scope
2 parents a3cb5d7 + 0b79ff9 commit 2b8acd5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,31 @@ passport.use(new DynamicStrategy(options, (payload, done) => {
6161
}
6262
```
6363
64+
#### Verify Scopes
65+
66+
It's important to note that a JWT token can include scopes. The most common scope is when a token requires additional authentication such as MFA. In this event we may not want to fully verify, and ruturn false if the token has the `requiresAdditionalAuth` scope.
67+
68+
Example:
69+
70+
```typescript
71+
passport.use(new DynamicStrategy(options, (payload, done) => {
72+
try {
73+
const user = {
74+
id: payload.sub,
75+
scopes: payload.scopes
76+
}
77+
78+
if (user && !user.scopes.includes('requiresAdditionalAuth')) {
79+
return done(null, user)
80+
} else {
81+
return done(null, false)
82+
}
83+
} catch (err) {
84+
return done(err, false);
85+
}
86+
}
87+
```
88+
6489
### Protecting an endpoint with the strategy
6590
6691
First define a function that calls `passport.authenticate` with the strategy name (in our case, `dynamicStrategy`)

0 commit comments

Comments
 (0)