-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathidkeyauth.js
33 lines (27 loc) · 1.4 KB
/
idkeyauth.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
'use strict';
const configs = require('../configurations'),
helpers = require('../helpers'),
express = require('express'),
router = express.Router();
module.exports = function (appContext) {
/* GET /idkeyauth
* This route is used to initiate the ID/Key Authentication workflow.
*/
router.get('/idkeyauth', function(req, res) {
const callbackTarget = helpers.getIdKeyRedirectUri(req);
const getTokensUrl = appContext.createUrlForAuthentication(configs.instanceScheme + '//' + configs.instanceUrl, configs.instancePort, callbackTarget);
res.redirect(getTokensUrl);
});
/* GET /idkeycallback
* Once the user has accepted the terms for this application using the ID/Key Authentication
* workflow they will be redirected back to this route. The returned UserKey and UserId is then saved
* in a cookie so that later requests can be signed using the user's context.
*/
router.get('/idkeycallback', function(req, res) {
const callbackRoute = req.url;
const userContext = appContext.createUserContext(configs.instanceScheme + '//' + configs.instanceUrl, configs.instancePort, callbackRoute);
res.cookie(configs.cookieName, { userKey: userContext.userKey, userId: userContext.userId }, configs.cookieOptions);
res.redirect('/?authenticationType=idkeyauth');
});
return router;
};