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.
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.
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.
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.
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.
not everything is oauth2 based. Oops. A bug fix.
There was a problem hiding this comment.
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.
There are tiny request changes in the doc, the rest is ok
Co-authored-by: haroun <1765606+haroun@users.noreply.github.com>
Co-authored-by: haroun <1765606+haroun@users.noreply.github.com>
This has been tested:
apostrophecms/starter-kit-assembly-essentials#130
apostrophecms/starter-kit-essentials#75