Browse Source

more updates for Core

pull/1/head
Rob Colbert 3 years ago
parent
commit
1d6c377b84
  1. 28
      app/services/core-node.js
  2. 5
      app/services/oauth2.js
  3. 13
      app/views/welcome/core-home.pug

28
app/services/core-node.js

@ -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);
}

5
app/services/oauth2.js

@ -95,9 +95,14 @@ class OAuth2Service extends SiteService {
try {
const client = await OAuth2Client.findOne({ clientID });
if (!client) {
this.log.alert('OAuth2 client not found', { clientID });
return done(null, false);
}
if (client.redirectUri !== redirectUri) {
this.log.alert('OAuth2 client redirect URI mismatch', {
redirectUri,
officialUri: client.redirectUri,
});
return done(null, false);
}
return done(null, client, client.redirectUri);

13
app/views/welcome/core-home.pug

@ -3,20 +3,19 @@ block content
section.uk-section.uk-section-default
.uk-container
h1.uk-text-center Select Core
p.uk-text-center #{site.name} is connected with the following Core Communities.
.uk-margin-large
h1.uk-text-center Select Community
p.uk-text-center #{site.name} is connected with the following Core Communities.
section.uk-section.uk-section-secondary
.uk-container
div(uk-grid).uk-flex-center
each core in connectedCores
div(class="uk-width-1-1 uk-width-1-2@m uk-width-1-3@l")
//- pre= JSON.stringify(connectedCores, null, 2)
a(href=`/auth/core/${core._id}`).uk-display-block.uk-link-text
.uk-tile.uk-tile-secondary.uk-padding-small
div(uk-grid).uk-grid
.uk-tile.uk-tile-default.uk-padding-small.uk-border-small
div(uk-grid).uk-grid-small.uk-flex-middle
.uk-width-auto
img(src=`http://${core.meta.domain}/img/icon/dtp-core.svg`, style="width: 32px; height: auto;")
img(src=`http://${core.meta.domain}/img/icon/dtp-core.svg`, style="width: 48px; height: auto;")
.uk-width-expand
h4.uk-margin-remove= core.meta.name
.uk-text-small.uk-text-muted= core.meta.description
Loading…
Cancel
Save