another push of Core Connect to Core

master
rob 2 years ago
parent 8c16a3b00b
commit 8574f655fe

@ -14,7 +14,7 @@
"program": "${workspaceFolder:dtp-base}/dtp-webapp.js", "program": "${workspaceFolder:dtp-base}/dtp-webapp.js",
"console": "integratedTerminal", "console": "integratedTerminal",
"env": { "env": {
"HTTP_BIND_PORT": "3333" "HTTP_BIND_PORT": "3310"
} }
}, },
{ {

@ -28,6 +28,7 @@ class WelcomeController extends SiteController {
const router = express.Router(); const router = express.Router();
this.dtp.app.use('/welcome', welcomeLimiter, router); this.dtp.app.use('/welcome', welcomeLimiter, router);
router.get('/core-member', this.getWelcomeCoreMember.bind(this));
router.get('/signup/captcha', this.getSignupCaptcha.bind(this)); router.get('/signup/captcha', this.getSignupCaptcha.bind(this));
router.get('/signup', this.getSignupView.bind(this)); router.get('/signup', this.getSignupView.bind(this));
router.get('/login', this.getLoginView.bind(this)); router.get('/login', this.getLoginView.bind(this));
@ -36,6 +37,10 @@ class WelcomeController extends SiteController {
return router; return router;
} }
async getWelcomeCoreMember (req, res) {
res.render('welcome/core-member');
}
async getSignupCaptcha (req, res) { async getSignupCaptcha (req, res) {
const signupCaptcha = captcha(req.session.captcha.signup, { const signupCaptcha = captcha(req.session.captcha.signup, {
color: false, color: false,

@ -11,7 +11,7 @@ const Schema = mongoose.Schema;
const OAuth2AuthorizationCodeSchema = new Schema({ const OAuth2AuthorizationCodeSchema = new Schema({
code: { type: String, required: true, index: 1 }, code: { type: String, required: true, index: 1 },
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 }, scope: { type: [String], required: true },
}); });

@ -14,12 +14,13 @@ const OAuth2ClientSchema = new Schema({
site: { site: {
name: { type: String, required: true }, name: { type: String, required: true },
description: { type: String, required: true }, description: { type: String, required: true },
domain: { type: String, required: true }, domain: { type: String, required: true, index: 1 },
domainKey: { type: String, required: true }, domainKey: { type: String, required: true, index: 1 },
company: { type: String, required: true }, company: { type: String, required: true },
}, },
secret: { type: String, required: true }, secret: { type: String, required: true },
redirectURI: { type: String, required: true }, scopes: { type: [String], required: true },
redirectUri: { type: String, required: true },
}); });
module.exports = mongoose.model('OAuth2Client', OAuth2ClientSchema); module.exports = mongoose.model('OAuth2Client', OAuth2ClientSchema);

@ -91,29 +91,29 @@ class OAuth2Service extends SiteService {
res.render('oauth2/authorize-dialog'); res.render('oauth2/authorize-dialog');
} }
async processAuthorize (clientID, redirectURI, done) { async processAuthorize (clientID, redirectUri, done) {
try { try {
const client = await OAuth2Client.findOne({ clientID }); const client = await OAuth2Client.findOne({ clientID });
if (!client) { if (!client) {
return done(null, false); return done(null, false);
} }
if (client.redirectUri !== redirectURI) { if (client.redirectUri !== redirectUri) {
return done(null, false); return done(null, false);
} }
return done(null, client, client.redirectURI); return done(null, client, client.redirectUri);
} catch (error) { } catch (error) {
this.log.error('failed to process OAuth2 authorize', { error }); this.log.error('failed to process OAuth2 authorize', { error });
return done(error); return done(error);
} }
} }
async processGrant (client, redirectURI, user, ares, done) { async processGrant (client, redirectUri, user, ares, done) {
try { try {
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, scope: ares.scope,
}); });
@ -125,13 +125,13 @@ class OAuth2Service extends SiteService {
} }
} }
async processExchange (client, code, redirectURI, done) { async processExchange (client, code, redirectUri, done) {
try { try {
const ac = await OAuth2AuthorizationCode.findOne({ code }); const ac = await OAuth2AuthorizationCode.findOne({ code });
if (client.id !== ac.clientId) { if (client.id !== ac.clientId) {
return done(null, false); return done(null, false);
} }
if (redirectURI !== ac.redirectUri) { if (redirectUri !== ac.redirectUri) {
return done(null, false); return done(null, false);
} }
@ -172,7 +172,8 @@ class OAuth2Service extends SiteService {
client.site.company = striptags(clientDefinition.company); client.site.company = striptags(clientDefinition.company);
client.secret = generatePassword(PASSWORD_LEN, false); client.secret = generatePassword(PASSWORD_LEN, false);
client.redirectURI = clientDefinition.redirectURI; client.scopes = clientDefinition.coreAuth.redirectUri.map((scope) => striptags(scope));
client.redirectUri = striptags(clientDefinition.coreAuth.redirectUri);
await client.save(); await client.save();
@ -191,6 +192,20 @@ class OAuth2Service extends SiteService {
.lean(); .lean();
return client; return client;
} }
async getClientByDomain (domain) {
const client = await OAuth2Client
.findOne({ 'site.domain': domain })
.lean();
return client;
}
async getClientByDomainKey (domainKey) {
const client = await OAuth2Client
.findOne({ 'site.domainKey': domainKey })
.lean();
return client;
}
} }
module.exports = { module.exports = {

@ -18,7 +18,7 @@ block content
.uk-margin .uk-margin
label.uk-form-label Site Information label.uk-form-label Site Information
textarea(style="font-family: Courier New, fixed; font-size: 12px;", rows= 7, disabled).uk-textarea= JSON.stringify(site, null, 2) textarea(style="font-family: Courier New, fixed; font-size: 12px;", rows= 10, disabled).uk-textarea= JSON.stringify(site, null, 2)
.uk-margin .uk-margin
label(for="host").uk-form-label Core Host label(for="host").uk-form-label Core Host

@ -0,0 +1,8 @@
extends ../layouts/main
block content
section.uk-section.uk-section-default
.uk-container
h1 Thank You For Joining!
p #{site.name} is happy to provide our services to your community.
a(href="/").uk-button.uk-button-default Home

@ -11,7 +11,15 @@ block content
.uk-margin-medium-top .uk-margin-medium-top
div(uk-grid).uk-flex-center div(uk-grid).uk-flex-center
.uk-width-auto div(class="uk-width-1-1 uk-width-1-3@m")
a(href="/welcome/signup").uk-button.dtp-button-primary Create Account .uk-margin-small
.uk-width-auto a(href="/auth/core").uk-button.dtp-button-primary.uk-border-rounded DTP Connect
a(href="/welcome/login").uk-button.dtp-button-secondary Sign In .uk-text-small Connect using DTP Core
div(class="uk-width-1-1 uk-width-1-3@m")
.uk-margin-small
a(href="/welcome/signup").uk-button.dtp-button-secondary.uk-border-rounded Create Account
.uk-text-small Create a local account
div(class="uk-width-1-1 uk-width-1-3@m")
.uk-margin-small
a(href="/welcome/login").uk-button.dtp-button-secondary.uk-border-rounded Sign In
.uk-text-small Log in with your local account

@ -10,4 +10,8 @@ module.exports = {
domain: process.env.DTP_SITE_DOMAIN, domain: process.env.DTP_SITE_DOMAIN,
domainKey: process.env.DTP_SITE_DOMAIN_KEY, domainKey: process.env.DTP_SITE_DOMAIN_KEY,
company: process.env.DTP_SITE_COMPANY || 'Digital Telepresence, LLC', company: process.env.DTP_SITE_COMPANY || 'Digital Telepresence, LLC',
coreAuth: {
scopes: ['account-read', 'event-write'],
redirectUri: '/auth/core/callback',
},
}; };
Loading…
Cancel
Save