Browse Source

wip to Core

pull/1/head
Rob Colbert 3 years ago
parent
commit
94a2bd26cb
  1. 10
      app/controllers/admin/core-node.js
  2. 2
      app/models/oauth2-authorization-code.js
  3. 2
      app/models/oauth2-client.js
  4. 10
      app/services/oauth2.js
  5. 1
      config/site.js

10
app/controllers/admin/core-node.js

@ -48,7 +48,15 @@ class CoreNodeController extends SiteController {
const CORE_SCHEME = process.env.DTP_CORE_AUTH_SCHEME || 'https'; const CORE_SCHEME = process.env.DTP_CORE_AUTH_SCHEME || 'https';
res.locals.siteConfig = Object.assign({ }, this.dtp.config.site); res.locals.siteConfig = Object.assign({ }, this.dtp.config.site);
res.locals.siteConfig.coreAuth.redirectUri = `${CORE_SCHEME}://${this.dtp.config.site.domain}/auth/core/${res.locals.core._id}/welcome`;
if (req.body.callbackUri) {
res.locals.siteConfig.coreAuth.callbackUrl = `${CORE_SCHEME}://${this.dtp.config.site.domain}${req.body.callbackUri}`;
this.log.info('registering with custom callback URL', { callbackUrl: res.locals.siteConfig.coreAuth.callbackUrl });
} else {
const callbackUri = `/auth/core/${res.locals.core._id}/callback`;
res.locals.siteConfig.coreAuth.callbackUrl = `${CORE_SCHEME}://${this.dtp.config.site.domain}${callbackUri}`;
this.log.info('registering with standard callback URL', { callbackUrl: res.locals.siteConfig.coreAuth.callbackUrl });
}
try { try {
res.locals.txConnect = await coreNodeService.sendRequest(res.locals.core, { res.locals.txConnect = await coreNodeService.sendRequest(res.locals.core, {

2
app/models/oauth2-authorization-code.js

@ -13,7 +13,7 @@ const OAuth2AuthorizationCodeSchema = new Schema({
clientId: { type: Schema.ObjectId, required: true, index: 1 }, clientId: { type: Schema.ObjectId, required: true, index: 1 },
redirectUri: { type: String, required: true }, redirectUri: { type: String, required: true },
user: { type: Schema.ObjectId, required: true, index: 1 }, user: { type: Schema.ObjectId, required: true, index: 1 },
scope: { type: [String], required: true }, scopes: { type: [String], required: true },
}); });
module.exports = mongoose.model('OAuth2AuthorizationCode', OAuth2AuthorizationCodeSchema); module.exports = mongoose.model('OAuth2AuthorizationCode', OAuth2AuthorizationCodeSchema);

2
app/models/oauth2-client.js

@ -20,7 +20,7 @@ const OAuth2ClientSchema = new Schema({
}, },
secret: { type: String, required: true }, secret: { type: String, required: true },
scopes: { type: [String], required: true }, scopes: { type: [String], required: true },
redirectUri: { type: String, required: true }, callbackUrl: { type: String, required: true },
}); });
OAuth2ClientSchema.index({ OAuth2ClientSchema.index({

10
app/services/oauth2.js

@ -119,10 +119,10 @@ class OAuth2Service extends SiteService {
var code = uuidv4(); var code = uuidv4();
var ac = new OAuth2AuthorizationCode({ var ac = new OAuth2AuthorizationCode({
code, code,
clientId: client.id, clientId: client._id,
redirectUri, redirectUri,
user: user.id, user: user._id,
scope: ares.scope, scopes: client.scopes,
}); });
await ac.save(); await ac.save();
return done(null, code); return done(null, code);
@ -178,7 +178,7 @@ class OAuth2Service extends SiteService {
clientDefinition.secret = generatePassword(PASSWORD_LEN, false); clientDefinition.secret = generatePassword(PASSWORD_LEN, false);
clientDefinition.coreAuth.scopes = clientDefinition.coreAuth.scopes.map((scope) => striptags(scope)); clientDefinition.coreAuth.scopes = clientDefinition.coreAuth.scopes.map((scope) => striptags(scope));
clientDefinition.coreAuth.redirectUri = striptags(clientDefinition.coreAuth.redirectUri); clientDefinition.coreAuth.callbackUrl = striptags(clientDefinition.coreAuth.callbackUrl);
/* /*
* Use an upsert to either update or create the OAuth2 client record for the * Use an upsert to either update or create the OAuth2 client record for the
@ -203,7 +203,7 @@ class OAuth2Service extends SiteService {
'site.company': clientDefinition.company, 'site.company': clientDefinition.company,
secret: clientDefinition.secret, secret: clientDefinition.secret,
scopes: clientDefinition.coreAuth.scopes, scopes: clientDefinition.coreAuth.scopes,
redirectUri: clientDefinition.coreAuth.redirectUri, callbackUrl: clientDefinition.coreAuth.callbackUrl,
}, },
}, },
{ {

1
config/site.js

@ -12,6 +12,5 @@ module.exports = {
company: process.env.DTP_SITE_COMPANY || 'Digital Telepresence, LLC', company: process.env.DTP_SITE_COMPANY || 'Digital Telepresence, LLC',
coreAuth: { coreAuth: {
scopes: ['account-read', 'event-write'], scopes: ['account-read', 'event-write'],
redirectUri: `/auth/core/callback`,
}, },
}; };
Loading…
Cancel
Save