Skip to content

Commit

Permalink
enablePassportStrategies is now async
Browse files Browse the repository at this point in the history
  • Loading branch information
haroun committed Sep 20, 2024
1 parent 7bd97e5 commit 4a81cb0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Changelog

## Unreleased
## UNRELEASED

* Adds translation strings.
* Use `self.apos.root.import` instead of `self.apos.root.require`.
* `enablePassportStrategies` is now async.

## 1.2.0 - 2023-06-08

Expand Down Expand Up @@ -48,4 +50,3 @@ Declared stable. No code changes.
## 1.0.0-beta - 2022-01-06

Initial release for A3. Tested and working with Google and Okta. Other standard passport modules should also work, especially those based on OpenAuth.

12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module.exports = {
directory: 'modules',
modules: getBundleModuleNames()
},
init(self) {
self.enablePassportStrategies();
async init(self) {
await self.enablePassportStrategies();
},
options: {
i18n: {
Expand All @@ -18,7 +18,7 @@ module.exports = {
},
methods(self) {
return {
enablePassportStrategies() {
async enablePassportStrategies() {
self.refresh = new AuthTokenRefresh();
self.strategies = {};
if (!self.apos.baseUrl) {
Expand All @@ -28,11 +28,11 @@ module.exports = {
throw new Error('@apostrophecms/passport-bridge: you must configure the "strategies" option');
}

self.options.strategies.forEach(spec => {
for (const spec of self.options.strategies) {
// Works with npm modules that export the strategy directly, npm modules
// that export a Strategy property, and directly passing in a strategy property
// in the spec
const strategyModule = spec.module && self.apos.root.require(spec.module);
const strategyModule = spec.module && await self.apos.root.import(spec.module);
const Strategy = strategyModule ? (strategyModule.Strategy || strategyModule) : spec.Strategy;
if (!Strategy) {
throw new Error('@apostrophecms/passport-bridge: each strategy must have a "module" setting\n' +
Expand Down Expand Up @@ -67,7 +67,7 @@ module.exports = {
}, self.findOrCreateUser(spec));
self.apos.login.passport.use(self.strategies[spec.name]);
self.refresh.use(self.strategies[spec.name]);
});
};
},

// Returns the oauth2 callback URL, which must match the route
Expand Down

0 comments on commit 4a81cb0

Please sign in to comment.