-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathfiretodo-enterprise-ldap.js
55 lines (47 loc) · 1.95 KB
/
firetodo-enterprise-ldap.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
/**
* The zero-factor enterprise LDAP back-end used in the Firetodo example. The
* roles and details are kept on your trusted server, signed, passed to the
* client, which then uses it in an auth() call to Firebase. The token is
* verified by the Firebase backend using the shared secret key.
*
* This node process is running at http://misc.firebase.com:22222 which is
* what firetodo.js is configured to look at. If you want to run this on
* your own machine, be sure to fetch the latest version of
* https://static.firebase.com/v0/firebase-token-generator.js and change the
* URL in firetodo.js. You'll need node v0.6.3+.
*/
var users = {
// Alice is the only manager in the system
alice: { username: 'alice', manager: true },
bob: { username: 'bob', manager: false},
carol: { username: 'carol', manager: false}
};
var guest = { username: 'guest', manager: false };
var url = require('url');
var http = require('http');
var FirebaseTokenGenerator = require("./firebase-token-generator-node.js");
var tokenGenerator = new FirebaseTokenGenerator(
'FIXME --- Your Firebase namespace secret ---FIXME'
);
http.createServer(function(req, res) {
try {
// Grab the query parameters.
var query = url.parse(req.url, true).query;
// By default, return the guest user.
var returnedUser = guest;
if (query != null && query.user != null && users[query.user] != null) {
// ... otherwise, use the super secret enterprise LDAP from above.
returnedUser = users[query.user];
}
// Create the Firebase auth token for the payload that we would like
// Firebase to treat as trusted.
var token = tokenGenerator.createToken(returnedUser);
// Send the signed token back to the client.
res.writeHead(200, {
'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*'
});
res.end(JSON.stringify({firebaseAuthToken: token}));
} catch(err) {
console.log(err);
};
}).listen(22222, "127.0.0.1");