Fixing some issues with dynamically supporting multiple SSO providers

This commit is contained in:
kevgliss 2015-12-27 17:54:11 -05:00
parent 38b48604f3
commit a7decc1948
7 changed files with 160 additions and 152 deletions

View File

@ -231,7 +231,6 @@ class Ping(Resource):
class Google(Resource):
def __init__(self):
self.reqparse = reqparse.RequestParser()
super(Google, self).__init__()
@ -271,34 +270,32 @@ class Google(Resource):
class Providers(Resource):
def get(self):
active_providers = dict()
active_providers = []
for provider in current_app.config.get("ACTIVE_PROVIDERS"):
provider = provider.lower()
if provider == "google":
active_providers["google"] = {
active_providers.append({
'name': 'google',
'clientId': current_app.config.get("GOOGLE_CLIENT_ID"),
'url': api.url_for(Google)
}
})
elif provider == "ping":
active_providers["oauth2"] = {
active_providers.append({
'name': current_app.config.get("PING_NAME"),
'url': api.url_for(Ping),
'redirectUri': '', # TODO
'url': current_app.config.get('PING_REDIRECT_URI'),
'redirectUri': current_app.config.get("PING_REDIRECT_URI"),
'clientId': current_app.config.get("PING_CLIENT_ID"),
'responseType': 'code',
'scope': ['openid', 'email', 'profile', 'address'],
'scopeDelimeter': ' ',
'authorizationEndpoint': '', # TODO
'requiredUrlParams': ['scope']
}
'authorizationEndpoint': current_app.config.get("PING_AUTH_ENDPOINT"),
'requiredUrlParams': ['scope'],
'type': '2.0'
})
return active_providers

View File

@ -1,5 +1,6 @@
'use strict';
(function() {
var lemur = angular
.module('lemur', [
'ui.router',
@ -17,29 +18,43 @@ var lemur = angular
'ngLetterAvatar',
'angular-clipboard',
'ngFileSaver'
])
.config(function ($stateProvider, $urlRouterProvider, $authProvider, AuthenticationService) {
$urlRouterProvider.otherwise('/welcome');
]);
fetchData().then(bootstrapApplication);
function fetchData() {
var initInjector = angular.injector(['ng']);
var $http = initInjector.get('$http');
return $http.get('http://localhost:8000/api/1/auth/providers').then(function(response) {
lemur.constant('providers', response.data);
}, function(errorResponse) {
// Handle error case
});
}
function bootstrapApplication() {
angular.element(document).ready(function() {
angular.bootstrap(document, ["lemur"]);
});
}
lemur.config(function ($stateProvider, $urlRouterProvider, $authProvider, providers) {
$urlRouterProvider.otherwise('/welcome');
$stateProvider
.state('welcome', {
url: '/welcome',
templateUrl: 'angular/welcome/welcome.html'
});
AuthenticationService.get_providers().then(function (active_providers) {
var provider_names = [];
for (var key in active_providers) {
if (active_providers.hasOwnProperty(key)) {
provider_names.push(key);
}
}
for (var i=0; i < provider_names.length; i++) {
$authProvider[provider_names[i]](active_providers[provider_names[i]]);
}
_.each(providers, function(provider) {
if ($authProvider.hasOwnProperty(provider.name)) {
$authProvider[provider.name] = provider;
} else {
$authProvider.oauth2(provider);
}
});
});
lemur.service('MomentService', function () {
this.diffMoment = function (start, end) {
@ -137,3 +152,6 @@ lemur.factory('LemurRestangular', function (Restangular, $location, $auth) {
lemur.run(['$templateCache', function ($templateCache) {
$templateCache.put('ng-table/pager.html', '<div class="ng-cloak ng-table-pager"> <div ng-if="params.settings().counts.length" class="ng-table-counts btn-group pull-left"> <button ng-repeat="count in params.settings().counts" type="button" ng-class="{\'active\':params.count()==count}" ng-click="params.count(count)" class="btn btn-default"> <span ng-bind="count"></span> </button></div><div class="pull-right"><ul style="margin: 0; padding: 0;" class="pagination ng-table-pagination"> <li ng-class="{\'disabled\': !page.active}" ng-repeat="page in pages" ng-switch="page.type"> <a ng-switch-when="prev" ng-click="params.page(page.number)" href="">&laquo;</a> <a ng-switch-when="first" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="page" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="more" ng-click="params.page(page.number)" href="">&#8230;</a> <a ng-switch-when="last" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="next" ng-click="params.page(page.number)" href="">&raquo;</a> </li> </ul> </div></div>');
}]);
}());

View File

@ -8,11 +8,12 @@ angular.module('lemur')
controller: 'LoginController'
});
})
.controller('LoginController', function ($rootScope, $scope, AuthenticationService, UserService) {
.controller('LoginController', function ($rootScope, $scope, AuthenticationService, UserService, providers) {
$scope.login = AuthenticationService.login;
$scope.authenticate = AuthenticationService.authenticate;
$scope.logout = AuthenticationService.logout;
$scope.get_providers = AuthenticationService.get_providers;
$scope.providers = providers;
UserService.getCurrentUser().then(function (user) {
$scope.currentUser = user;

View File

@ -3,8 +3,8 @@
<div class="login">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<button class="btn btn-block btn-default" ng-repeat="(key, value) in get_providers()" ng-click="authenticate(key)">
Login with {{key}}
<button class="btn btn-block btn-default" ng-repeat="(key, value) in providers" ng-click="authenticate(value.name)">
Login with {{ value.name }}
</button>
</div>
</div>

View File

@ -6,10 +6,6 @@ angular.module('lemur')
.service('AuthenticationService', function ($location, $rootScope, AuthenticationApi, UserService, toaster, $auth) {
var AuthenticationService = this;
AuthenticationService.get_providers = function () {
return AuthenticationApi.one('providers').get();
};
AuthenticationService.login = function (username, password) {
AuthenticationApi.customPOST({'username': username, 'password': password}, 'login')
.then(

View File

@ -32,7 +32,7 @@
<!-- endbuild -->
</head>
<body ng-app="lemur" ng-csp>
<body ng-csp>
<toaster-container></toaster-container>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>

View File

@ -54,8 +54,6 @@ class User(db.Model):
"""
if self.password:
return bcrypt.check_password_hash(self.password, password)
else:
return False
def hash_password(self):
"""
@ -66,8 +64,6 @@ class User(db.Model):
if self.password:
self.password = bcrypt.generate_password_hash(self.password)
return self.password
else:
return None
@property
def is_admin(self):