-
Notifications
You must be signed in to change notification settings - Fork 235
/
app.js
64 lines (45 loc) · 1.5 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var express = require('express');
var app = express();
var jwt = require('express-jwt');
var SECRET = 'A92LWsdBgH6legaUm8U3uyJ7n1bdEik7WvO8nQab9LlHTtnawpRx8d-HPqW0b2g-';
var AUDIENCE = 'DyG9nCwIEofSy66QM3oo5xU6NFs3TmvT';
var authenticate = jwt({
secret: new Buffer(SECRET, 'base64'),
audience: AUDIENCE
});
app.use(express.logger());
app.use('/', express.static(__dirname + '/'));
app.use('/api', authenticate);
app.get('/api/protected', function (req, res) {
res.send(200, 'This API Rocks!');
});
/** For custom signup example **/
var Auth0 = require('auth0');
var request = require('request');
var extend = require("xtend");
var api = new Auth0({
domain: 'contoso.auth0.com',
clientID: 'DyG9nCwIEofSy66QM3oo5xU6NFs3TmvT',
clientSecret: SECRET
});
var CONNECTION = 'Username-Password-Authentication';
var https = require('https');
app.use(express.bodyParser());
app.use('/custom-signup', function (req, res) {
api._getAccessToken(function (err, token) {
if (err) {
console.log('Error fetching access token: ' + err);
}
var data = extend(req.body, {connection: CONNECTION, email_verified: false});
request.post({url: 'https://contoso.auth0.com/api/users/?access_token=' + token, json: data}, function (e, r, body) {
if (r.statusCode === 200) {
res.send(200);
return;
}
res.send(r.statusCode, body);
});
});
});
/** ------------------------ **/
app.listen(1337);
console.log('listening on port http://localhost:1337');