Skip to content

Commit a8d51cd

Browse files
author
Steven Hammerton
committed
Add support for CAS auth
1 parent a05437e commit a8d51cd

File tree

4 files changed

+74
-11
lines changed

4 files changed

+74
-11
lines changed

src/skins/vector/skindex.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ skin['molecules.UserSelector'] = require('./views/molecules/UserSelector');
6464
skin['molecules.voip.CallView'] = require('./views/molecules/voip/CallView');
6565
skin['molecules.voip.IncomingCallBox'] = require('./views/molecules/voip/IncomingCallBox');
6666
skin['molecules.voip.VideoView'] = require('./views/molecules/voip/VideoView');
67+
skin['organisms.CasLogin'] = require('./views/organisms/CasLogin');
6768
skin['organisms.CreateRoom'] = require('./views/organisms/CreateRoom');
6869
skin['organisms.ErrorDialog'] = require('./views/organisms/ErrorDialog');
6970
skin['organisms.LeftPanel'] = require('./views/organisms/LeftPanel');
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var React = require('react');
20+
21+
var MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg');
22+
23+
module.exports = React.createClass({
24+
displayName: 'CasLogin',
25+
26+
getInitialState: function() {
27+
var splitLocation = window.location.href.split('/');
28+
return {serviceUrl: splitLocation[0] + "//" + splitLocation[2]};
29+
},
30+
31+
onCasClicked: function(ev) {
32+
var serviceRedirectUrl = this.state.serviceUrl + "/#/login/cas";
33+
var self = this;
34+
MatrixClientPeg.get().getCasServer().done(function(data) {
35+
var serverUrl = data.serverUrl + "/login?service=" + encodeURIComponent(serviceRedirectUrl);
36+
window.location.href=serverUrl
37+
}, function(error) {
38+
self.setStep("stage_m.login.cas");
39+
self.setState({errorText: 'Login failed.'});
40+
});
41+
},
42+
43+
render: function() {
44+
return (
45+
<div>
46+
<button onClick={this.onCasClicked}>Sign in with CAS</button>
47+
</div>
48+
);
49+
}
50+
});

src/skins/vector/views/templates/Login.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ module.exports = React.createClass({
141141
</form>
142142
</div>
143143
);
144+
case 'stage_m.login.cas':
145+
var CasLogin = sdk.getComponent('organisms.CasLogin');
146+
return (
147+
<CasLogin />
148+
);
144149
}
145150
},
146151

src/vector/index.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,29 @@ sdk.loadModule(require('../modules/VectorConferenceHandler'));
2323

2424
var lastLocationHashSet = null;
2525

26+
27+
function parseQueryParams(location) {
28+
var hashparts = location.hash.split('?');
29+
var params = {};
30+
if (hashparts.length == 2) {
31+
var pairs = hashparts[1].split('&');
32+
for (var i = 0; i < pairs.length; ++i) {
33+
var parts = pairs[i].split('=');
34+
if (parts.length != 2) continue;
35+
params[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
36+
}
37+
}
38+
return params
39+
}
40+
2641
// Here, we do some crude URL analysis to allow
2742
// deep-linking. We only support registration
2843
// deep-links in this example.
2944
function routeUrl(location) {
3045
if (location.hash.indexOf('#/register') == 0) {
31-
var hashparts = location.hash.split('?');
32-
var params = {};
33-
if (hashparts.length == 2) {
34-
var pairs = hashparts[1].split('&');
35-
for (var i = 0; i < pairs.length; ++i) {
36-
var parts = pairs[i].split('=');
37-
if (parts.length != 2) continue;
38-
params[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
39-
}
40-
}
41-
window.matrixChat.showScreen('register', params);
46+
window.matrixChat.showScreen('register', parseQueryParams(location));
47+
} else if (location.hash.indexOf('#/login/cas') == 0) {
48+
window.matrixChat.showScreen('cas_login', parseQueryParams(location));
4249
} else {
4350
window.matrixChat.showScreen(location.hash.substring(2));
4451
}

0 commit comments

Comments
 (0)