Skip to content
This repository was archived by the owner on Feb 26, 2020. It is now read-only.

Commit f4866bb

Browse files
committed
Commit for Azure deploy
1 parent 654abe2 commit f4866bb

3 files changed

Lines changed: 24 additions & 24 deletions

File tree

node-server/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Don't commit this file to your public repos
22
exports.creds = {
33
mongoose_auth_local: 'mongodb://localhost/tasklist', // Your mongo auth uri goes here
4-
openid_configuration: 'https://login.microsoftonline.com/common/.well-known/openid-configuration', // For using Microsoft you should never need to change this.
5-
openid_keys: 'https://login.microsoftonline.com/common/discovery/keys', // For using Microsoft you should never need to change this. If asbsent will attempt to get from openid_configuration
4+
openid_configuration: 'https://login.microsoftonline.com/hypercubeb2c.onmicrosoft.com/.well-known/openid-configuration?p=b2c_1_B2CSI', // For using Microsoft you should never need to change this.
5+
openid_keys: 'https://login.microsoftonline.com/common/discovery/keys' // For using Microsoft you should never need to change this. If asbsent will attempt to get from openid_configuration
66
}

node-server/lib/oidc_strategy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ var decoded = jws.decode(token);
144144
var PEMkey = this.metadata.generateOidcPEM(decoded.header.x5t);
145145
}
146146
else if (decoded.header.kid) {
147-
var PEMkey = this.metadata.generateOidcPEM(decoded.header.x5t);
147+
var PEMkey = this.metadata.generateOidcPEM(decoded.header.kid);
148148
}
149149
else { throw new TypeError('We did not reveive a token we know how to validate');
150150
}

node-server/server.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
var path = require('path');
2626
var util = require('util');
2727
var assert = require('assert-plus');
28+
var mongoose = require('mongoose/');
2829
var bunyan = require('bunyan');
2930
var getopt = require('posix-getopt');
3031
var restify = require('restify');
3132
var getopt = require('posix-getopt');
3233
var config = require('./config');
3334

34-
var config = {
35+
var options = {
3536
// The URL of the metadata document for your app. We will put the keys for token validation from the URL found in the jwks_uri tag of the in the metadata.
3637
metadataurl: config.creds.openid_configuration
3738

@@ -52,14 +53,14 @@
5253

5354

5455

55-
try { // MongoDB setup
56+
// MongoDB setup
5657

5758
/**
5859
* Setup some configuration
5960
*/
60-
var mongoose = require('mongoose/');
61+
6162
var serverPort = process.env.PORT || 8888;
62-
var serverURI = ( process.env.PORT ) ? config.creds.mongoose_auth_mongohq : config.creds.mongoose_auth_local;
63+
var serverURI = (process.env.PORT) ? config.creds.mongoose_auth_mongohq : config.creds.mongoose_auth_local;
6364

6465

6566
/**
@@ -89,13 +90,7 @@ var TaskSchema = new Schema({
8990
mongoose.model('Task', TaskSchema);
9091
var Task = mongoose.model('Task');
9192

92-
}
93-
94-
catch(err) {
9593

96-
log.warn("MongoDB error. Did you intall MongoDB?" + err);
97-
98-
}
9994

10095
/**
10196
*
@@ -325,14 +320,19 @@ var server = restify.createServer({
325320
};
326321

327322

328-
var oidcStrategy = new OIDCBearerStrategy(config,
323+
var oidcStrategy = new OIDCBearerStrategy(options,
329324
function(token, done) {
330325
log.info('verifying the user');
331326
log.info(token, 'was the token retreived');
332327
findById(token.sub, function (err, user) {
333328
if (err) { return done(err); }
334-
if (!user) { return done(null, false);
335-
log.info('user not found'); }
329+
330+
if (!user) {
331+
// "Auto-registration"
332+
log.info('User was added automatically as they were new. Their sub is: ', token.sub)
333+
users.push(token);
334+
return done(null, token);
335+
}
336336
return done(null, user, token);
337337
});
338338
}
@@ -344,14 +344,14 @@ var server = restify.createServer({
344344

345345
server.get('/tasks', passport.authenticate('oidc-bearer', { session: false }), listTasks);
346346
server.get('/tasks', passport.authenticate('oidc-bearer', { session: false }), listTasks);
347-
server.get('/tasks/:owner', getTask);
348-
server.head('/tasks/:owner', getTask);
349-
server.post('/tasks/:owner/:task', createTask);
350-
server.post('/tasks', createTask);
351-
server.del('/tasks/:owner/:task', removeTask);
352-
server.del('/tasks/:owner', removeTask);
353-
server.del('/tasks', removeTask);
354-
server.del('/tasks', removeAll, function respond(req, res, next) { res.send(204); next(); });
347+
server.get('/tasks/:owner', passport.authenticate('oidc-bearer', { session: false }), getTask);
348+
server.head('/tasks/:owner', passport.authenticate('oidc-bearer', { session: false }), getTask);
349+
server.post('/tasks/:owner/:task', passport.authenticate('oidc-bearer', { session: false }), createTask);
350+
server.post('/tasks', passport.authenticate('oidc-bearer', { session: false }), createTask);
351+
server.del('/tasks/:owner/:task', passport.authenticate('oidc-bearer', { session: false }), removeTask);
352+
server.del('/tasks/:owner', passport.authenticate('oidc-bearer', { session: false }), removeTask);
353+
server.del('/tasks', passport.authenticate('oidc-bearer', { session: false }), removeTask);
354+
server.del('/tasks', passport.authenticate('oidc-bearer', { session: false }), removeAll, function respond(req, res, next) { res.send(204); next(); });
355355

356356

357357
// Register a default '/' handler

0 commit comments

Comments
 (0)