Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@benningfield-group/amc-sso

Package Overview
Dependencies
Maintainers
6
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@benningfield-group/amc-sso - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

2

AMC.SSO.js
(function(angular) {
'use strict';
angular.module('amc-auth', ['ngCookies', 'ngSanitize', 'bgi']);
angular.module('AMC.SSO', ['ngCookies', 'ngSanitize', 'bgi']);
})(window.angular);

@@ -1,1 +0,1 @@

"use strict";function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();!function(a){a.module("amc-auth",["ngCookies","ngSanitize","bgi"])}(window.angular),function(a){function b(){function a(){return{clientID:c,authEndpoint:d,loginRedirectUri:e,refreshRedirectUri:f}}var b=this,c=void 0,d=void 0,e=void 0,f=void 0;b.setClientID=function(a){c=a},b.setAuthEndpoint=function(a){d=a},b.setLoginRedirectUri=function(a){e=a},b.setRefreshRedirectUri=function(a){f=a},b.$get=[a]}a.module("amc-auth").provider("amc_authConfig",[b])}(window.angular),function(a){function b(a,b,c,d){var e="__AUTHTOKEN",f=3e5;return new(function(){function g(){_classCallCheck(this,g),this._expInterval=null}return _createClass(g,[{key:"setAuthToken",value:function(c){var g=d.decode(c),h=new Date(g.exp-f);a.put(e,c,{expires:h}),this._doPoll(),this._expInterval=b(this._doPoll.bind(this),6e4)}},{key:"destroyAuthToken",value:function(){this._expInterval&&b.cancel(this._expInterval),a.remove(e)}},{key:"getAuthToken",value:function(){return a.get(e)}},{key:"getTokenPayload",value:function(){var a=this.getAuthToken();return a?d.decode(a):null}},{key:"getTimeUntilExpiration",value:function(){var a=this.getTokenPayload(),b=0;return a&&(b=a.exp-f-(new Date).getTime())<0&&(b=0),b}},{key:"_doPoll",value:function(){var a=this.getTimeUntilExpiration();c.$broadcast("amc-auth.LOGIN_EXPIRATION_POLL",a),0===a&&(c.$broadcast("amc-auth.LOGOUT"),this.destroyAuthToken())}}]),g}())}a.module("amc-auth").factory("amc_authCookieSvc",b),b.$inject=["$cookies","$interval","$rootScope","amc_tokenizer"]}(window.angular),function(a){function b(a,b,c,d,e,f,g){var h="amc-auth-nonce",i="amc-auth-state";return function(){function j(){_classCallCheck(this,j)}return _createClass(j,[{key:"buildAuthURL",value:function(a){var e=[],f=b.generateRandomString(30),j=b.generateRandomString(30),k=d.authEndpoint+"/api/OpenID/Authorization?";return c.setObject(h,f),c.setObject(i,j),e.push("scope=openid"),e.push("response_type=id_token"),e.push("client_id="+encodeURIComponent(d.clientID)),e.push("redirect_uri="+encodeURIComponent(a)),e.push("nonce="+encodeURIComponent(g(f))),e.push("state="+encodeURIComponent(j)),k+=e.join("&")}},{key:"handleAuthResponse",value:function(b){var d=b.split("#")[1].split("&").reduce(function(a,b){return b=b.split("="),a[b[0]]=b[1],a},{});if(d.error)a.$broadcast("amc-auth.LOGIN_ERROR",new Error(d.error));else{var j=d.state,k=d.id_token,l=c.getObject(i),m=f.decode(k),n=m.nonce,o=c.getObject(h);if(c.removeObject(i),c.removeObject(h),!l||j!==l)return void a.$broadcast("amc-auth.LOGIN_FAILURE",new Error("Invalid state."));if(!o||n!==g(o))return void a.$broadcast("amc-auth.LOGIN_FAILURE",new Error("Invalid nonce."));e.setAuthToken(k),a.$broadcast("amc-auth.LOGIN_SUCCESS",m)}}}]),j}()}a.module("amc-auth").factory("amc_AuthSvc",["$rootScope","bgi_RandomSvc","bgi_storageSvc","amc_authConfig","amc_authCookieSvc","amc_tokenizer","amc_sha256",b])}(window.angular),function(a){function b(a,b,c,d,e){return new(function(){function f(c){_classCallCheck(this,f),this.authSvc=c||new e,0===a.location.href.indexOf(d.loginRedirectUri)&&b.hash()&&this._handleAuthResponse()}return _createClass(f,[{key:"goAuth",value:function(b){a.location.href=b}},{key:"renewClientAuthToken",value:function(){function b(){e.authSvc.handleAuthResponse(f.contentWindow.location.href),g.resolve(),f.remove()}var e=this,f=a.document.createElement("iframe"),g=c.defer();return f.style.display="none",f.onload=b,f.src=this.authSvc.buildAuthURL(d.refreshRedirectUri),a.document.body.appendChild(f),g.promise}},{key:"_handleAuthResponse",value:function(){this.authSvc.handleAuthResponse("#"+b.hash()),b.hash("")}}]),f}())}a.module("amc-auth").factory("amc_browserAuthStrategy",b),b.$inject=["$window","$location","$q","amc_authConfig","amc_AuthSvc"]}(window.angular),function(a){function b(a){if(!a.jwt_decode)throw new Error("jwt_decode is required to be on window. Install it by running: bower install jwt-decode --save");return a.jwt_decode}a.module("amc-auth").factory("amc_jwtDecode",["$window",b])}(window.angular),function(a){function b(a,b,c){return function(){function d(a,b){_classCallCheck(this,d),this.authStrat=a,this.authSvc=b||new c}return _createClass(d,[{key:"login",value:function(){this.authStrat.goAuth(this.authSvc.buildAuthURL(a.loginRedirectUri))}},{key:"isLoggedIn",value:function(){return!!b.getAuthToken()}}]),d}()}a.module("amc-auth").factory("amc_LoginSvc",b),b.$inject=["amc_authConfig","amc_authCookieSvc","amc_AuthSvc"]}(window.angular),function(a){function b(a,b,c,d,e){var f=c.trustAsResourceUrl(d.authEndpoint+"/api/Logout");return function(){function c(){_classCallCheck(this,c)}return _createClass(c,[{key:"logout",value:function(){return a.jsonp(f).then(function(a){return e.destroyAuthToken(),b.$broadcast("amc-auth.LOGOUT"),a})}}]),c}()}a.module("amc-auth").factory("amc_LogoutSvc",b),b.$inject=["$http","$rootScope","$sce","amc_authConfig","amc_authCookieSvc"]}(window.angular),function(a){function b(a,b,c,d,e){return new(function(){function f(b){_classCallCheck(this,f),this.authSvc=b||new e,this._wndRef=null,this._defer=null,a.handleOpenURL=this._handleOpenURL.bind(this)}return _createClass(f,[{key:"goAuth",value:function(b){return this._defer=c.defer(),this._wndRef=a.cordova.InAppBrowser.open(b,"_blank","location=no,toolbar=no"),this._defer.promise}},{key:"renewClientAuthToken",value:function(){var b=this.authSvc.buildAuthURL(d.loginRedirectUri);return this._defer=c.defer(),this._wndRef=a.cordova.InAppBrowser.open(b,"_blank","location=no,toolbar=no,hidden=yes"),this._defer.promise}},{key:"_handleOpenURL",value:function(a){var c=this;b(function(){c._wndRef&&(c._wndRef.close(),c._wndRef=null,c._defer.resolve(),0===a.indexOf(d.loginRedirectUri)&&c.authSvc.handleAuthResponse(a))},0)}}]),f}())}a.module("amc-auth").factory("amc_mobileAuthStrategy",b),b.$inject=["$window","$timeout","$q","amc_authConfig","amc_AuthSvc"]}(window.angular),function(a){function b(a,b,c,d){var e=c.trustAsResourceUrl(d.authEndpoint+"/api/Login/Refresh");return function(){function c(a){_classCallCheck(this,c),this.authStrat=a}return _createClass(c,[{key:"renewAuthToken",value:function(){var c=this;return a.jsonp(e).then(function(){return c.authStrat.renewClientAuthToken()}).then(function(){b.$broadcast("amc-auth.AUTH_RENEWED")})}}]),c}()}a.module("amc-auth").factory("amc_RefreshTokenSvc",b),b.$inject=["$http","$rootScope","$sce","amc_authConfig"]}(window.angular),function(){function a(a){if(!a.sha256)throw new Error("sha256 is required to be on window. Install it by running: bower install --save js-sha256");return a.sha256}angular.module("amc-auth").factory("amc_sha256",["$window",a])}(),function(a){function b(a){return new(function(){function b(){_classCallCheck(this,b)}return _createClass(b,[{key:"decode",value:function(b){if(!b)throw new Error("No auth token supplied.");try{return a(b)}catch(c){throw new Error("Failed to decode token.")}}},{key:"getExpiration",value:function(a){return new Date(1e3*this.decode(a).exp)}},{key:"isExpired",value:function(a){return this.getExpiration(a)<new Date}}]),b}())}a.module("amc-auth").factory("amc_tokenizer",["amc_jwtDecode",b])}(window.angular);
"use strict";function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();!function(a){a.module("AMC.SSO",["ngCookies","ngSanitize","bgi"])}(window.angular),function(a){function b(){function a(){return{clientID:c,authEndpoint:d,loginRedirectUri:e,refreshRedirectUri:f}}var b=this,c=void 0,d=void 0,e=void 0,f=void 0;b.setClientID=function(a){c=a},b.setAuthEndpoint=function(a){d=a},b.setLoginRedirectUri=function(a){e=a},b.setRefreshRedirectUri=function(a){f=a},b.$get=[a]}a.module("AMC.SSO").provider("amc_authConfig",[b])}(window.angular),function(a){function b(a,b,c,d){var e="__AUTHTOKEN",f=3e5;return new(function(){function g(){_classCallCheck(this,g),this._expInterval=null}return _createClass(g,[{key:"setAuthToken",value:function(c){var g=d.decode(c),h=new Date(g.exp-f);a.put(e,c,{expires:h}),this._doPoll(),this._expInterval=b(this._doPoll.bind(this),6e4)}},{key:"destroyAuthToken",value:function(){this._expInterval&&b.cancel(this._expInterval),a.remove(e)}},{key:"getAuthToken",value:function(){return a.get(e)}},{key:"getTokenPayload",value:function(){var a=this.getAuthToken();return a?d.decode(a):null}},{key:"getTimeUntilExpiration",value:function(){var a=this.getTokenPayload(),b=0;return a&&(b=a.exp-f-(new Date).getTime())<0&&(b=0),b}},{key:"_doPoll",value:function(){var a=this.getTimeUntilExpiration();c.$broadcast("AMC.SSO.LOGIN_EXPIRATION_POLL",a),0===a&&(c.$broadcast("AMC.SSO.LOGOUT"),this.destroyAuthToken())}}]),g}())}a.module("AMC.SSO").factory("amc_authCookieSvc",b),b.$inject=["$cookies","$interval","$rootScope","amc_tokenizer"]}(window.angular),function(a){function b(a,b,c,d,e,f,g){var h="AMC.SSO-nonce",i="AMC.SSO-state";return function(){function j(){_classCallCheck(this,j)}return _createClass(j,[{key:"buildAuthURL",value:function(a){var e=[],f=b.generateRandomString(30),j=b.generateRandomString(30),k=d.authEndpoint+"/api/OpenID/Authorization?";return c.setObject(h,f),c.setObject(i,j),e.push("scope=openid"),e.push("response_type=id_token"),e.push("client_id="+encodeURIComponent(d.clientID)),e.push("redirect_uri="+encodeURIComponent(a)),e.push("nonce="+encodeURIComponent(g(f))),e.push("state="+encodeURIComponent(j)),k+=e.join("&")}},{key:"handleAuthResponse",value:function(b){var d=b.split("#")[1].split("&").reduce(function(a,b){return b=b.split("="),a[b[0]]=b[1],a},{});if(d.error)a.$broadcast("AMC.SSO.LOGIN_ERROR",new Error(d.error));else{var j=d.state,k=d.id_token,l=c.getObject(i),m=f.decode(k),n=m.nonce,o=c.getObject(h);if(c.removeObject(i),c.removeObject(h),!l||j!==l)return void a.$broadcast("AMC.SSO.LOGIN_FAILURE",new Error("Invalid state."));if(!o||n!==g(o))return void a.$broadcast("AMC.SSO.LOGIN_FAILURE",new Error("Invalid nonce."));e.setAuthToken(k),a.$broadcast("AMC.SSO.LOGIN_SUCCESS",m)}}}]),j}()}a.module("AMC.SSO").factory("amc_AuthSvc",["$rootScope","bgi_RandomSvc","bgi_storageSvc","amc_authConfig","amc_authCookieSvc","amc_tokenizer","amc_sha256",b])}(window.angular),function(a){function b(a,b,c,d,e){return new(function(){function f(c){_classCallCheck(this,f),this.authSvc=c||new e,0===a.location.href.indexOf(d.loginRedirectUri)&&b.hash()&&this._handleAuthResponse()}return _createClass(f,[{key:"goAuth",value:function(b){a.location.href=b}},{key:"renewClientAuthToken",value:function(){function b(){e.authSvc.handleAuthResponse(f.contentWindow.location.href),g.resolve(),f.remove()}var e=this,f=a.document.createElement("iframe"),g=c.defer();return f.style.display="none",f.onload=b,f.src=this.authSvc.buildAuthURL(d.refreshRedirectUri),a.document.body.appendChild(f),g.promise}},{key:"_handleAuthResponse",value:function(){this.authSvc.handleAuthResponse("#"+b.hash()),b.hash("")}}]),f}())}a.module("AMC.SSO").factory("amc_browserAuthStrategy",b),b.$inject=["$window","$location","$q","amc_authConfig","amc_AuthSvc"]}(window.angular),function(a){function b(a){if(!a.jwt_decode)throw new Error("jwt_decode is required to be on window. Install it by running: bower install jwt-decode --save");return a.jwt_decode}a.module("AMC.SSO").factory("amc_jwtDecode",["$window",b])}(window.angular),function(a){function b(a,b,c){return function(){function d(a,b){_classCallCheck(this,d),this.authStrat=a,this.authSvc=b||new c}return _createClass(d,[{key:"login",value:function(){this.authStrat.goAuth(this.authSvc.buildAuthURL(a.loginRedirectUri))}},{key:"isLoggedIn",value:function(){return!!b.getAuthToken()}}]),d}()}a.module("AMC.SSO").factory("amc_LoginSvc",b),b.$inject=["amc_authConfig","amc_authCookieSvc","amc_AuthSvc"]}(window.angular),function(a){function b(a,b,c,d,e){var f=c.trustAsResourceUrl(d.authEndpoint+"/api/Logout");return function(){function c(){_classCallCheck(this,c)}return _createClass(c,[{key:"logout",value:function(){return a.jsonp(f).then(function(a){return e.destroyAuthToken(),b.$broadcast("AMC.SSO.LOGOUT"),a})}}]),c}()}a.module("AMC.SSO").factory("amc_LogoutSvc",b),b.$inject=["$http","$rootScope","$sce","amc_authConfig","amc_authCookieSvc"]}(window.angular),function(a){function b(a,b,c,d,e){return new(function(){function f(b){_classCallCheck(this,f),this.authSvc=b||new e,this._wndRef=null,this._defer=null,a.handleOpenURL=this._handleOpenURL.bind(this)}return _createClass(f,[{key:"goAuth",value:function(b){return this._defer=c.defer(),this._wndRef=a.cordova.InAppBrowser.open(b,"_blank","location=no,toolbar=no"),this._defer.promise}},{key:"renewClientAuthToken",value:function(){var b=this.authSvc.buildAuthURL(d.loginRedirectUri);return this._defer=c.defer(),this._wndRef=a.cordova.InAppBrowser.open(b,"_blank","location=no,toolbar=no,hidden=yes"),this._defer.promise}},{key:"_handleOpenURL",value:function(a){var c=this;b(function(){c._wndRef&&(c._wndRef.close(),c._wndRef=null,c._defer.resolve(),0===a.indexOf(d.loginRedirectUri)&&c.authSvc.handleAuthResponse(a))},0)}}]),f}())}a.module("AMC.SSO").factory("amc_mobileAuthStrategy",b),b.$inject=["$window","$timeout","$q","amc_authConfig","amc_AuthSvc"]}(window.angular),function(a){function b(a,b,c,d){var e=c.trustAsResourceUrl(d.authEndpoint+"/api/Login/Refresh");return function(){function c(a){_classCallCheck(this,c),this.authStrat=a}return _createClass(c,[{key:"renewAuthToken",value:function(){var c=this;return a.jsonp(e).then(function(){return c.authStrat.renewClientAuthToken()}).then(function(){b.$broadcast("AMC.SSO.AUTH_RENEWED")})}}]),c}()}a.module("AMC.SSO").factory("amc_RefreshTokenSvc",b),b.$inject=["$http","$rootScope","$sce","amc_authConfig"]}(window.angular),function(){function a(a){if(!a.sha256)throw new Error("sha256 is required to be on window. Install it by running: bower install --save js-sha256");return a.sha256}angular.module("AMC.SSO").factory("amc_sha256",["$window",a])}(),function(a){function b(a){return new(function(){function b(){_classCallCheck(this,b)}return _createClass(b,[{key:"decode",value:function(b){if(!b)throw new Error("No auth token supplied.");try{return a(b)}catch(c){throw new Error("Failed to decode token.")}}},{key:"getExpiration",value:function(a){return new Date(1e3*this.decode(a).exp)}},{key:"isExpired",value:function(a){return this.getExpiration(a)<new Date}}]),b}())}a.module("AMC.SSO").factory("amc_tokenizer",["amc_jwtDecode",b])}(window.angular);
(function(angular) {
'use strict';
angular.module('AMC.SSO.Demo', ['amc-auth'])
angular.module('AMC.SSO.Demo', ['AMC.SSO'])
.config(['amc_authConfigProvider', configAuth]);
/**
* Configure the amc-auth app.
* Configure the AMC.SSO app.
*/

@@ -10,0 +10,0 @@ function configAuth(authConfigProvider) {

@@ -45,3 +45,3 @@ (function(angular) {

$rootScope.$on('amc-auth.LOGIN_EXPIRATION_POLL', function(e, exp) {
$rootScope.$on('AMC.SSO.LOGIN_EXPIRATION_POLL', function(e, exp) {
vm.timeToExp = exp;

@@ -48,0 +48,0 @@ });

{
"name": "@benningfield-group/amc-sso",
"version": "0.0.1",
"version": "0.0.2",
"description": "AMC single sign-on app.",

@@ -5,0 +5,0 @@ "main": "AMC.SSO.js",

(function(angular) {
'use strict';
angular.module('amc-auth')
angular.module('AMC.SSO')
.provider('amc_authConfig', [AuthSvcProvider]);

@@ -6,0 +6,0 @@

(function(angular) {
'use strict';
angular.module('amc-auth')
angular.module('AMC.SSO')
.factory('amc_authCookieSvc', authCookieSvcProducer);

@@ -97,7 +97,7 @@

// a "no activity for x minutes" screen, or refresh their token.
$rootScope.$broadcast('amc-auth.LOGIN_EXPIRATION_POLL', expiresIn);
$rootScope.$broadcast('AMC.SSO.LOGIN_EXPIRATION_POLL', expiresIn);
// When the session expires, log out.
if (expiresIn === 0) {
$rootScope.$broadcast('amc-auth.LOGOUT');
$rootScope.$broadcast('AMC.SSO.LOGOUT');
this.destroyAuthToken();

@@ -104,0 +104,0 @@ }

(function(angular) {
'use strict';
angular.module('amc-auth')
angular.module('AMC.SSO')
.factory('amc_AuthSvc', [

@@ -19,4 +19,4 @@ '$rootScope',

const NONCE_NAME = 'amc-auth-nonce';
const STATE_NAME = 'amc-auth-state';
const NONCE_NAME = 'AMC.SSO-nonce';
const STATE_NAME = 'AMC.SSO-state';

@@ -73,3 +73,3 @@ class AuthSvc {

if (hashParams.error) {
$rootScope.$broadcast('amc-auth.LOGIN_ERROR', new Error(hashParams.error));
$rootScope.$broadcast('AMC.SSO.LOGIN_ERROR', new Error(hashParams.error));
}

@@ -91,3 +91,3 @@ else {

if (!localState || state !== localState) {
$rootScope.$broadcast('amc-auth.LOGIN_FAILURE', new Error('Invalid state.'));
$rootScope.$broadcast('AMC.SSO.LOGIN_FAILURE', new Error('Invalid state.'));
return;

@@ -99,3 +99,3 @@ }

if (!localNonce || nonce !== sha256(localNonce)) {
$rootScope.$broadcast('amc-auth.LOGIN_FAILURE', new Error('Invalid nonce.'));
$rootScope.$broadcast('AMC.SSO.LOGIN_FAILURE', new Error('Invalid nonce.'));
return;

@@ -108,3 +108,3 @@ }

// Set up the login.
$rootScope.$broadcast('amc-auth.LOGIN_SUCCESS', idPayload);
$rootScope.$broadcast('AMC.SSO.LOGIN_SUCCESS', idPayload);
}

@@ -111,0 +111,0 @@ }

(function(angular) {
'use strict';
angular.module('amc-auth')
angular.module('AMC.SSO')
.factory('amc_browserAuthStrategy', browserAuthStrategyProducer);

@@ -6,0 +6,0 @@

(function(angular) {
'use strict';
angular.module('amc-auth')
angular.module('AMC.SSO')
.factory('amc_jwtDecode', ['$window', jwtDecodeProducer]);

@@ -6,0 +6,0 @@

(function(angular) {
'use strict';
angular.module('amc-auth')
angular.module('AMC.SSO')
.factory('amc_LoginSvc', loginSvcProducer);

@@ -6,0 +6,0 @@

(function(angular) {
'use strict';
angular.module('amc-auth')
angular.module('AMC.SSO')
.factory('amc_LogoutSvc', logoutSvcProducer);

@@ -30,3 +30,3 @@

authCookieSvc.destroyAuthToken();
$rootScope.$broadcast('amc-auth.LOGOUT');
$rootScope.$broadcast('AMC.SSO.LOGOUT');
return resp;

@@ -33,0 +33,0 @@ });

(function(angular) {
'use strict';
angular.module('amc-auth')
angular.module('AMC.SSO')
.factory('amc_mobileAuthStrategy', mobileAuthStrategyProducer);

@@ -6,0 +6,0 @@

(function(angular) {
'use strict';
angular.module('amc-auth')
angular.module('AMC.SSO')
.factory('amc_RefreshTokenSvc', refreshTokenSvcProducer);

@@ -44,3 +44,3 @@

.then(function() {
$rootScope.$broadcast('amc-auth.AUTH_RENEWED');
$rootScope.$broadcast('AMC.SSO.AUTH_RENEWED');
});

@@ -47,0 +47,0 @@ }

(function() {
'use strict';
angular.module('amc-auth')
angular.module('AMC.SSO')
.factory('amc_sha256', ['$window', sha256Producer]);

@@ -6,0 +6,0 @@

(function(angular) {
'use strict';
angular.module('amc-auth')
angular.module('AMC.SSO')
.factory('amc_tokenizer', ['amc_jwtDecode', tokenizerProducer]);

@@ -6,0 +6,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc