Skip to content
This repository was archived by the owner on Dec 24, 2019. It is now read-only.

Commit 4d51d23

Browse files
committed
add transparent relog using jsonp + CAS gateway
1 parent eed8ff0 commit 4d51d23

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

app/app.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@ angular.module('myApp', [
1313
]).
1414
config(['$routeProvider', function($routeProvider) {
1515
$routeProvider.otherwise({redirectTo: '/view1'});
16-
}]).run(function ($rootScope, $modal) {
16+
}]).run(function ($rootScope, $modal, authService, $http) {
1717

1818
// Call when the 401 response is returned by the server
1919
$rootScope.$on('event:auth-loginRequired', function(rejection) {
20-
$modal.open({ templateUrl: 'relog/relog.html', controller: 'RelogCtrl', backdrop: false });
20+
21+
// first try jsonp
22+
$http.jsonp('backend/login.php?callback=JSON_CALLBACK').then(function (resp) {
23+
authService.loginConfirmed(resp.data);
24+
}, function () {
25+
// jsonp failed,
26+
$modal.open({ templateUrl: 'relog/relog.html', controller: 'RelogCtrl', backdrop: false });
27+
});
2128
});
2229

2330
});

app/backend/login.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
require_once 'init.inc.php';
4+
5+
phpCAS::handleLogoutRequests();
6+
if (!phpCAS::checkAuthentication()) {
7+
header('HTTP/1.0 401 Unauthorized');
8+
echo 'HTTP/1.0 401 Unauthorized';
9+
exit();
10+
}
11+
12+
$user = array('id' => phpCAS::getUser());
13+
14+
if (isset($_GET["callback"])) {
15+
header('Content-type: application/javascript; charset=UTF-8');
16+
echo $_GET["callback"] . "(" . json_encode($user) . ");";
17+
} else {
18+
header('Content-type: application/json; charset=UTF-8');
19+
echo json_encode($user);
20+
}
21+
22+

0 commit comments

Comments
 (0)