Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Commit

Permalink
MUMUP-2670 : Cleanup silent login step (#513)
Browse files Browse the repository at this point in the history
* cleanup login so it works okay for localhost and the like

* documentation

* add to docs home
  • Loading branch information
Tim Levett authored Aug 22, 2016
1 parent a0ce9f5 commit 06c82b2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
7 changes: 7 additions & 0 deletions angularjs-portal-home/src/main/webapp/js/login-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';
define([], function() {
return {
"loginURL" : null //null for localhost so we don't break things
//"loginURL" : "/portal/Login?silent=true&profile=bucky" //overlay will have something like this
}
});
2 changes: 1 addition & 1 deletion angularjs-portal-home/src/main/webapp/js/override.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ define(['angular'], function(angular) {
'notificationsURL' : '/web/staticFeeds/notifications.json',
'groupURL' : '/portal/api/groups',
'kvURL' : '/storage',
'loginSilentURL' : '/portal/Login?silent=true'
'loginSilentURL' : '/portal/Login?silent=true&profile=bucky'
},
'NAMES' : {
'title' : 'MyUW',
Expand Down
12 changes: 7 additions & 5 deletions angularjs-portal-home/src/main/webapp/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
require(['./config'], function(config) {
require(['./config', './js/login-config'], function(config, loginConfig) {

require.config(config);

require(['angular', 'jquery', 'my-app'], function(angular, $) {
//attempting to replicate what they did in
//Idea taken from
//https://blog.mariusschulz.com/2014/10/22/asynchronously-bootstrapping-angularjs-applications-with-server-side-data
doLogin().then(bootstrapApplication)
.catch(function(){
Expand Down Expand Up @@ -37,10 +37,10 @@ require(['./config'], function(config) {
var $rootScope = initInjector.get('$rootScope');

//login stuff
if(!lastLoginValid($sessionStorage)) {
if(loginConfig.loginURL && !lastLoginValid($sessionStorage)) {
//assume not valid, go get a username and bootstrap the user
var $http = initInjector.get("$http");
return $http.get("/portal/Login?silent=true&profile=bucky").then(function(response){
return $http.get(loginConfig.loginURL).then(function(response){
if("success" === response.data.status) {
//store some meta data for caching reason
if(!$sessionStorage.portal){
Expand All @@ -57,7 +57,9 @@ require(['./config'], function(config) {
} else {
//the cache is still valid with a valid session, carry on
var $q = initInjector.get('$q');
return $q.resolve("Login cache still valid from previous login");
return $q.resolve(loginConfig.loginURL
? "Login cache still valid from previous login"
: "Silent login not configured.");
}
}
});
Expand Down
1 change: 1 addition & 0 deletions docs/markdown/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Search over:
## Integration with uPortal
+ Overview
+ Customizations/Setup
+ [Silent Login Configuration](#/md/silent-login) - Configure angularjs-portal to do a login before bootstrapping angular.

[MyUW Developers Google Group]: https://groups.google.com/forum/#!forum/myuw-developers
[uportal-dev@]: https://groups.google.com/a/apereo.org/forum/#!forum/uportal-dev
Expand Down
5 changes: 5 additions & 0 deletions docs/markdown/silent-login.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
We needed a way to bootstrap a session in portal before fetching things from `/portal/api/*` so we came up with this silent login prestep.

If you want to configure this, override the `js/login-config.js` file and plug in your login URL that will return JSON saying "success". This works really well with shib since the login should have already happened, this just calls the standard uPortal login code, but since we are saying `silent=true` it'll just return JSON with the username instead of try to redirect the browser to the uPortal home screen.

If you want to learn more look at `main.js` in `src/main/webapp`.

0 comments on commit 06c82b2

Please sign in to comment.