-
Notifications
You must be signed in to change notification settings - Fork 0
PRO-8013: comprehensive solution to support atypical passport strategies #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| ### Working with passport strategies that expect different arguments to the `verify` callback | ||
|
|
||
| All passport strategies expect us to provide a `verify` callback. By default, `@apostrophecms/passport-bridge` passes its `findOrCreateUser` function as the `verify` callback, which works for many strategies including `passport-oauth2`, `passport-github2` and `passport-gitlab2`. For other strategies, you can pass an explicit `verify` option which will remap the strategy `verify` method with `@apostrophecms/passport-bridge` `findOrCreateUser` method. | ||
| All passport strategies expect us to provide a `verify` callback. By default, `@apostrophecms/passport-bridge` passes its `findOrCreateUser` function as the `verify` callback, which works for many strategies including `passport-oauth2`, `passport-github2` and `passport-gitlab2`. For other strategies, you can pass an explicit `verify` option which will remap the strategy `verify` method to our `@apostrophecms/passport-bridge` `findOrCreateUser` method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some wording improvements regarding verify, I didn't change it.
|
|
||
| That function accepts the normal verify callback from the passport bridge module, and returns an alternative function which accepts `req`, plus the arguments that are typical for `passport-auth0` or the strategy of your choice, and then invokes the normal verify callback with the arguments it expects, returning the result. | ||
|
|
||
| ### Working with `oidc-client` and other passport strategies that don't follow typical patterns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the juicy new feature.
|
|
||
| for (const strategy of self.options.strategies) { | ||
| const spec = klona(strategy); | ||
| for (let spec of self.options.strategies) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
freeing up the variable name strategy for the actual strategy object.
| // sensibly. But we can do it by making a dummy strategy object now | ||
| const dummy = new Strategy({ | ||
| callbackURL: 'https://dummy/test', | ||
| const dummy = await factory({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this edge case will rarely be used with a factory function, but must be thorough
| self.strategies[spec.name] = strategy; | ||
| self.apos.login.passport.use(strategy); | ||
| if (strategy._oauth2) { | ||
| // This will only work with strategies that actually have an _oauth2 object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not everything is oauth2 based. Oops. A bug fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this we get a crash with strategies that can't support automatic token refresh. Which isn't even important unless you're reusing the tokens for API calls.
haroun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are tiny request changes in the doc, the rest is ok
Co-authored-by: haroun <[email protected]>
Co-authored-by: haroun <[email protected]>
This has been tested:
apostrophecms/starter-kit-assembly-essentials#130
apostrophecms/starter-kit-essentials#75