1 | function fetchUser() {
|
2 | $.ajax({
|
3 | url: '/api/user',
|
4 | success: function(result) {
|
5 |
|
6 |
|
7 | console.log('User results: ' + JSON.stringify(result));
|
8 |
|
9 | $('#title').text('User Data');
|
10 | $('#content').text(JSON.stringify(result, null, 2));
|
11 |
|
12 | }
|
13 | });
|
14 | }
|
15 |
|
16 |
|
17 | $(document).ready(function() {
|
18 |
|
19 |
|
20 |
|
21 | var auth0 = new Auth0({
|
22 | domain: 'rippleosi.eu.auth0.com',
|
23 | clientID: 'Ghi91Wk1PERQjxIN5ili6rssnl4em8In',
|
24 | callbackURL: 'http://139.59.187.100/auth0/token',
|
25 | responseType: 'code'
|
26 | });
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | $.ajax({
|
32 | url: "/api/initialise",
|
33 | success: function(result) {
|
34 | console.log('response from middle tier: ' + JSON.stringify(result));
|
35 |
|
36 | if (result.token) {
|
37 |
|
38 |
|
39 | document.cookie = "JSESSIONID=" + result.token;
|
40 | location.reload();
|
41 | return;
|
42 | }
|
43 |
|
44 | if (result.redirectTo === 'auth0') {
|
45 | console.log('running in UAT mode, so now login via auth0');
|
46 |
|
47 | auth0.login({
|
48 | connections: ['Username-Password-Authentication', 'google-oauth2', 'twitter'],
|
49 | });
|
50 | return;
|
51 |
|
52 | }
|
53 |
|
54 | if (result.ok) {
|
55 | console.log('Cookie was for a valid session, so fetch the simulated user');
|
56 | fetchUser();
|
57 | }
|
58 |
|
59 | }
|
60 |
|
61 | });
|
62 |
|
63 |
|
64 | $('#logoutBtn').on('click', function(e) {
|
65 | auth0.logout();
|
66 | });
|
67 |
|
68 |
|
69 | });
|
70 |
|
71 |
|