forked from auth0/auth0-extension-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (39 loc) · 1.22 KB
/
index.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
var express = require('express');
var auth0 = require('auth0-oauth2-express');
var Webtask = require('webtask-tools');
var app = express();
var metadata = require('./webtask.json');
app.use(auth0({
scopes: 'read:connections'
}));
app.get('/', function (req, res) {
var view = [
'<html>',
' <head>',
' <title>Auth0 Extension</title>',
' <script type="text/javascript">',
' if (!sessionStorage.getItem("token")) {',
' window.location.href = "'+res.locals.baseUrl+'/login";',
' }',
' </script>',
' </head>',
' <body>',
' <p><strong>Token</strong></p>',
' <textarea rows="10" cols="100" id="token"></textarea>',
' <script type="text/javascript">',
' var token = sessionStorage.getItem("token");',
' if (token) {',
' document.getElementById("token").innerText = token;',
' }',
' </script>',
' </body>',
'</html>'
].join('\n');
res.header("Content-Type", 'text/html');
res.status(200).send(view);
});
// This endpoint would be called by webtask-gallery to dicover your metadata
app.get('/meta', function (req, res) {
res.status(200).send(metadata);
});
module.exports = app;