From 94a2bd26cbfb1006aa3f12a27182fa3376afec92 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 5 Jul 2022 10:59:51 -0400 Subject: [PATCH] wip to Core --- app/controllers/admin/core-node.js | 10 +++++++++- app/models/oauth2-authorization-code.js | 2 +- app/models/oauth2-client.js | 2 +- app/services/oauth2.js | 10 +++++----- config/site.js | 1 - 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/core-node.js b/app/controllers/admin/core-node.js index e10b0d1..da8d196 100644 --- a/app/controllers/admin/core-node.js +++ b/app/controllers/admin/core-node.js @@ -48,7 +48,15 @@ class CoreNodeController extends SiteController { const CORE_SCHEME = process.env.DTP_CORE_AUTH_SCHEME || 'https'; 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 { res.locals.txConnect = await coreNodeService.sendRequest(res.locals.core, { diff --git a/app/models/oauth2-authorization-code.js b/app/models/oauth2-authorization-code.js index 028c11e..40708a3 100644 --- a/app/models/oauth2-authorization-code.js +++ b/app/models/oauth2-authorization-code.js @@ -13,7 +13,7 @@ const OAuth2AuthorizationCodeSchema = new Schema({ clientId: { type: Schema.ObjectId, required: true, index: 1 }, redirectUri: { type: String, required: true }, user: { type: Schema.ObjectId, required: true, index: 1 }, - scope: { type: [String], required: true }, + scopes: { type: [String], required: true }, }); module.exports = mongoose.model('OAuth2AuthorizationCode', OAuth2AuthorizationCodeSchema); \ No newline at end of file diff --git a/app/models/oauth2-client.js b/app/models/oauth2-client.js index 2591404..b534d0d 100644 --- a/app/models/oauth2-client.js +++ b/app/models/oauth2-client.js @@ -20,7 +20,7 @@ const OAuth2ClientSchema = new Schema({ }, secret: { type: String, required: true }, scopes: { type: [String], required: true }, - redirectUri: { type: String, required: true }, + callbackUrl: { type: String, required: true }, }); OAuth2ClientSchema.index({ diff --git a/app/services/oauth2.js b/app/services/oauth2.js index bc547c4..d5d14d4 100644 --- a/app/services/oauth2.js +++ b/app/services/oauth2.js @@ -119,10 +119,10 @@ class OAuth2Service extends SiteService { var code = uuidv4(); var ac = new OAuth2AuthorizationCode({ code, - clientId: client.id, + clientId: client._id, redirectUri, - user: user.id, - scope: ares.scope, + user: user._id, + scopes: client.scopes, }); await ac.save(); return done(null, code); @@ -178,7 +178,7 @@ class OAuth2Service extends SiteService { clientDefinition.secret = generatePassword(PASSWORD_LEN, false); 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 @@ -203,7 +203,7 @@ class OAuth2Service extends SiteService { 'site.company': clientDefinition.company, secret: clientDefinition.secret, scopes: clientDefinition.coreAuth.scopes, - redirectUri: clientDefinition.coreAuth.redirectUri, + callbackUrl: clientDefinition.coreAuth.callbackUrl, }, }, { diff --git a/config/site.js b/config/site.js index 884f979..63247c4 100644 --- a/config/site.js +++ b/config/site.js @@ -12,6 +12,5 @@ module.exports = { company: process.env.DTP_SITE_COMPANY || 'Digital Telepresence, LLC', coreAuth: { scopes: ['account-read', 'event-write'], - redirectUri: `/auth/core/callback`, }, }; \ No newline at end of file