1 | /*
|
2 |
|
3 | ----------------------------------------------------------------------------
|
4 | | qewd-ripple: QEWD-based Middle Tier for Ripple OSI |
|
5 | | |
|
6 | | Copyright (c) 2016-17 Ripple Foundation Community Interest Company |
|
7 | | All rights reserved. |
|
8 | | |
|
9 | | http://rippleosi.org |
|
10 | | Email: code.custodian@rippleosi.org |
|
11 | | |
|
12 | | Author: Rob Tweed, M/Gateway Developments Ltd |
|
13 | | |
|
14 | | Licensed under the Apache License, Version 2.0 (the "License"); |
|
15 | | you may not use this file except in compliance with the License. |
|
16 | | You may obtain a copy of the License at |
|
17 | | |
|
18 | | http://www.apache.org/licenses/LICENSE-2.0 |
|
19 | | |
|
20 | | Unless required by applicable law or agreed to in writing, software |
|
21 | | distributed under the License is distributed on an "AS IS" BASIS, |
|
22 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
23 | | See the License for the specific language governing permissions and |
|
24 | | limitations under the License. |
|
25 | ----------------------------------------------------------------------------
|
26 |
|
27 | 8 March 2017
|
28 |
|
29 | */
|
30 |
|
31 |
|
32 | var createSession = require('../sessions/create');
|
33 | var authenticate = require('../sessions/authenticate');
|
34 |
|
35 | /*
|
36 |
|
37 | function authenticate(messageObj) {
|
38 | var cookie = messageObj.headers.cookie;
|
39 | if (!cookie) return {error: true};
|
40 |
|
41 | var pieces = cookie.split(';');
|
42 | var token;
|
43 | pieces.forEach(function(piece) {
|
44 | if (piece.indexOf('JSESSIONID') !== -1) {
|
45 | token = piece.split('JSESSIONID=')[1];
|
46 | }
|
47 | });
|
48 |
|
49 | if (!token) {error: true};
|
50 | //console.log('token = ' + token);
|
51 | var status = this.sessions.authenticate(token);
|
52 | //console.log('status: ' + JSON.stringify(status));
|
53 | return status;
|
54 | }
|
55 |
|
56 | */
|
57 |
|
58 |
|
59 | function user(messageObj, finished) {
|
60 |
|
61 | var status = authenticate.call(this, messageObj);
|
62 | var session;
|
63 | var reload = false;
|
64 | if (status.error) {
|
65 | // no session yet established for client
|
66 | // or previous session expired
|
67 |
|
68 | // create a new session
|
69 |
|
70 | console.log('*** auth0/token.js - creating new session');
|
71 | session = createSession.call(this);
|
72 | session.authenticated = true;
|
73 | // the UI will need to be reloaded now to avoid timing issues
|
74 | reload = true;
|
75 | }
|
76 | else {
|
77 | session = status.session;
|
78 | }
|
79 |
|
80 |
|
81 | finished({error: {token: session.token, reload: reload}});
|
82 | return;
|
83 | }
|
84 |
|
85 | module.exports = user;
|