forked from clkao/auth0-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (40 loc) · 1.25 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
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 extend = require('xtend');
var api = new Auth0({
domain: 'contoso.auth0.com',
clientID: 'DyG9nCwIEofSy66QM3oo5xU6NFs3TmvT',
clientSecret: SECRET
});
var CONNECTION = 'Username-Password-Authentication';
app.use(express.bodyParser());
app.use('/custom-signup', function (req, res) {
var data = extend(req.body, {connection: CONNECTION, email_verified: false});
api.createUser(data, function (err) {
if (err) {
console.log('Error creating user: ' + err);
res.send(500, err);
return;
}
res.send(200);
return;
});
});
/** ------------------------ **/
app.listen(1337);
console.log('listening on port http://localhost:1337');