Mercurial > lada > lada-client
comparison app.js @ 608:7fd9350eacf9 openid
Add client side openID authentication handling
If the client is not authenticated it will be redirected
to the identity provider provided by the lada-server in the
error message. The lada-server keeps track of the association
and verifies the openID parameters sent by the client
in the X-OPENID-PARAMS header
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 12 Mar 2015 17:39:16 +0100 |
parents | 80077aeaa9ed |
children | 3e91716f5862 |
comparison
equal
deleted
inserted
replaced
607:80077aeaa9ed | 608:7fd9350eacf9 |
---|---|
25 | 25 |
26 // Setting up translations. This is done using a ext-plgin which can be | 26 // Setting up translations. This is done using a ext-plgin which can be |
27 // found on https://github.com/elmasse/Ext.i18n.Bundle | 27 // found on https://github.com/elmasse/Ext.i18n.Bundle |
28 requires: [ | 28 requires: [ |
29 'Lada.override.Table', | 29 'Lada.override.Table', |
30 'Lada.override.RestProxy', | |
30 'Lada.override.RowEditor', | 31 'Lada.override.RowEditor', |
31 'Ext.i18n.Bundle', | 32 'Ext.i18n.Bundle', |
32 'Ext.layout.container.Column', | 33 'Ext.layout.container.Column', |
33 'Lada.store.Datenbasis', | 34 'Lada.store.Datenbasis', |
34 'Lada.store.Messeinheiten', | 35 'Lada.store.Messeinheiten', |
55 // file which sets ob the viewport. | 56 // file which sets ob the viewport. |
56 autoCreateViewport: true, | 57 autoCreateViewport: true, |
57 | 58 |
58 // Start the application. | 59 // Start the application. |
59 launch: function() { | 60 launch: function() { |
61 var queryString = document.location.href.split('?')[1]; | |
62 if (queryString) { | |
63 Lada.openIDParams = queryString; | |
64 } | |
65 Ext.Ajax.request({ | |
66 url: 'lada-server/login?return_to=' + window.location.href, | |
67 method: 'GET', | |
68 headers: { | |
69 'X-OPENID-PARAMS': Lada.openIDParams | |
70 }, | |
71 scope: this, | |
72 success: this.onLoginSuccess, | |
73 failure: this.onLoginFailure | |
74 }); | |
75 }, | |
76 | |
77 onLoginFailure : function(response, opts) { | |
78 try { | |
79 var json = Ext.decode(response.responseText); | |
80 if (json) { | |
81 if (json.message == "699") { | |
82 /* This is the unauthorized message with the authentication | |
83 * redirect in the data */ | |
84 var authUrl = json.data; | |
85 location.href = authUrl; | |
86 return; | |
87 } | |
88 if (json.message == "698") { | |
89 /* This is general authentication error */ | |
90 Ext.MessageBox.alert('Kommunikation mit dem Login Server fehlgeschlagen', | |
91 json.data); | |
92 return; | |
93 } | |
94 } | |
95 } catch (e) { | |
96 // This is likely a 404 or some unknown error. Show general error then. | |
97 } | |
98 Ext.MessageBox.alert('Kommunikation mit dem Lada Server fehlgeschlagen', | |
99 'Es konnte keine erfolgreiche Verbindung zum lada server aufgebaut werden.'); | |
100 | |
101 }, | |
102 | |
103 onLoginSuccess: function(response, opts) { | |
104 /* Strip out the openid query params to look nicers. */ | |
105 window.history.pushState(this.name, this.name, window.location.pathname); | |
106 | |
107 /* Todo maybe parse username and such from login service response */ | |
60 Ext.create('Lada.store.Datenbasis', { | 108 Ext.create('Lada.store.Datenbasis', { |
61 storeId: 'datenbasis' | 109 storeId: 'datenbasis' |
62 }); | 110 }); |
63 Ext.create('Lada.store.Messeinheiten', { | 111 Ext.create('Lada.store.Messeinheiten', { |
64 storeId: 'messeinheiten' | 112 storeId: 'messeinheiten' |