|
|
@ -49,7 +49,7 @@ class CoreNodeService extends SiteService { |
|
|
|
} |
|
|
|
|
|
|
|
async attachExpressRoutes (router) { |
|
|
|
const cores = await this.getConnectedCores(); |
|
|
|
const cores = await this.getConnectedCores(null, true); |
|
|
|
cores.forEach((core) => { |
|
|
|
const coreAuthStrategyName = this.getCoreAuthStrategyName(core); |
|
|
|
const coreAuthUri = `/core/${core._id}`; |
|
|
@ -64,11 +64,19 @@ class CoreNodeService extends SiteService { |
|
|
|
}); |
|
|
|
router.get( |
|
|
|
coreAuthUri, |
|
|
|
(req, res, next) => { |
|
|
|
this.log.debug('Core auth request', { coreAuthStrategyName, clientId: core.oauth.clientId }); |
|
|
|
return next(); |
|
|
|
}, |
|
|
|
passport.authenticate(coreAuthStrategyName), |
|
|
|
); |
|
|
|
|
|
|
|
router.get( |
|
|
|
coreAuthCallbackUri, |
|
|
|
(req, res, next) => { |
|
|
|
this.log.debug('Core auth callback'); |
|
|
|
return next(); |
|
|
|
}, |
|
|
|
passport.authenticate(coreAuthStrategyName, { failureRedirect: '/' }), |
|
|
|
async (req, res) => { |
|
|
|
// req.login(user, (error) => {
|
|
|
@ -87,20 +95,19 @@ class CoreNodeService extends SiteService { |
|
|
|
const { coreNode: coreNodeService } = this.dtp.services; |
|
|
|
const AUTH_SCHEME = coreNodeService.getCoreRequestScheme(); |
|
|
|
|
|
|
|
const coreAuthStrategyName = this.getCoreAuthStrategyName(core); |
|
|
|
const authorizationHost = `${core.address.host}:${core.address.port}`; |
|
|
|
const authorizationURL = `${AUTH_SCHEME}://${authorizationHost}/oauth2/authorize`; |
|
|
|
const tokenURL = `${AUTH_SCHEME}://${authorizationHost}/oauth2/token`; |
|
|
|
const callbackURL = `${AUTH_SCHEME}://${process.env.DTP_SITE_DOMAIN}/auth/core/callback`; |
|
|
|
|
|
|
|
const oauthOptions = { |
|
|
|
clientID: core.oauth.clientId, |
|
|
|
clientSecret: core.oauth.clientSecret, |
|
|
|
authorizationURL, tokenURL, callbackURL, |
|
|
|
}; |
|
|
|
|
|
|
|
const coreAuthStrategyName = this.getCoreAuthStrategyName(core); |
|
|
|
const coreAuthStrategy = new OAuth2Strategy( |
|
|
|
oauthOptions, |
|
|
|
{ |
|
|
|
authorizationURL, |
|
|
|
tokenURL, |
|
|
|
clientID: core.oauth.clientId.toString(), |
|
|
|
clientSecret: core.oauth.clientSecret, |
|
|
|
callbackURL, |
|
|
|
}, |
|
|
|
async (accessToken, refreshToken, profile, cb) => { |
|
|
|
this.log.info('Core login', { |
|
|
|
name: core.meta.name, |
|
|
@ -118,6 +125,7 @@ class CoreNodeService extends SiteService { |
|
|
|
name: coreAuthStrategyName, |
|
|
|
host: core.address.host, |
|
|
|
port: core.address.port, |
|
|
|
clientID: core.oauth.clientId.toString(), |
|
|
|
}); |
|
|
|
passport.use(coreAuthStrategyName, coreAuthStrategy); |
|
|
|
} |
|
|
|