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

auth0-angular

Package Overview
Dependencies
Maintainers
5
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auth0-angular - npm Package Compare versions

Comparing version 4.2.1 to 4.2.2

98

build/auth0-angular.js
/**
* Angular SDK to use with Auth0
* @version v4.2.0 - 2016-05-31
* @version v4.2.2 - 2016-06-09
* @link https://auth0.com

@@ -10,3 +10,3 @@ * @author Martin Gontovnikas

angular.module('auth0', ['auth0.service', 'auth0.utils', 'auth0.directives'])
.run(["auth", function(auth) {
.run(['auth', function(auth) {
auth.hookEvents();

@@ -26,2 +26,3 @@ }]);

* */
angular.module('auth0.utils', [])

@@ -58,3 +59,3 @@ .provider('authUtils', function() {

this.$get = ["$rootScope", "$q", function($rootScope, $q) {
this.$get = ['$rootScope', '$q', function($rootScope, $q) {
var authUtils = {};

@@ -178,3 +179,3 @@ angular.extend(authUtils, Utils);

angular.module('auth0.service', ['auth0.utils'])
.provider('auth', ["authUtilsProvider", function(authUtilsProvider) {
.provider('auth', ['authUtilsProvider', function(authUtilsProvider) {
var defaultOptions = {

@@ -188,2 +189,3 @@ callbackOnLocationHash: true

signin: 'login',
signinOnly: 'signinOnly',
signup: 'signup',

@@ -206,2 +208,3 @@ reset: 'changePassword',

signin: 'show',
signinOnly: 'showSignin',
signup: 'showSignup',

@@ -221,3 +224,3 @@ reset: 'showReset',

* DESCRIPTION: Get a method from the libraries
*
*
* INPUT: method name (string), library name (string)

@@ -237,3 +240,3 @@ * OUTPUT: String

* DESCRIPTION: Get a config from the libraries
*
*
* INPUT: config name (string), library name (string)

@@ -250,5 +253,5 @@ * OUTPUT: String

*
* DESCRIPTION: Returns a constructor: Defaults to a function if provided.
* DESCRIPTION: Returns a constructor: Defaults to a function if provided.
* Defaults to a Lock if library is included and function is not provided
*
*
* INPUT: function

@@ -293,3 +296,3 @@ * OUTPUT: object

* DESCRIPTION: Configures provider with provided options
*
*
* INPUT: option (object) and constructor

@@ -303,3 +306,5 @@ *

this.loginUrl = options.loginUrl;
this.loginUrlParams = options.loginUrlParams;
this.loginState = options.loginState;
this.loginStateParams = options.loginStateParams;
this.clientID = options.clientID || options.clientId;

@@ -342,3 +347,3 @@ var domain = options.domain;

this.$get = ["$rootScope", "$q", "$injector", "$window", "$location", "authUtils", "$http",
this.$get = ['$rootScope', '$q', '$injector', '$window', '$location', 'authUtils', '$http',
function($rootScope, $q, $injector, $window, $location, authUtils, $http) {

@@ -362,5 +367,12 @@ var auth = {

// SignIn
var onSigninOk = function(idToken, accessToken, state, refreshToken, profile, isRefresh) {
idToken = idToken || profile.idToken;
accessToken = accessToken || profile.accessToken;
state = state || profile.state;
refreshToken = refreshToken || profile.refreshToken;
var profilePromise = auth.getProfile(idToken);

@@ -389,5 +401,5 @@

if (config.loginUrl) {
$location.path(config.loginUrl);
$location.path(config.loginUrl, config.loginUrlParams);
} else if (config.loginState) {
$injector.get('$state').go(config.loginState);
$injector.get('$state').go(config.loginState, config.loginStateParams);
} else {

@@ -434,3 +446,3 @@ callHandler('forbidden');

function(){
$location.path(config.loginUrl);
$location.path(config.loginUrl, config.loginUrlParams);
}

@@ -448,2 +460,3 @@ );

verifyRoute(

@@ -461,3 +474,3 @@ (to.data && to.data.requiresLogin),

function() {
$injector.get('$state').go(config.loginState);
$injector.get('$state').go(config.loginState, config.loginStateParams);
}

@@ -468,2 +481,4 @@ );

/*jshint latedef: nofunc */
function verifyRoute(requiresLogin, e, getState, redirectToLogin) {

@@ -522,4 +537,4 @@ if (!auth.isAuthenticated && !auth.refreshTokenPromise) {

}
)
}
);
};

@@ -535,4 +550,4 @@ var unLinkAccount = function(primaryJWT, user_id, secondaryProvider, secondaryUserId){

}
)
}
);
};

@@ -613,2 +628,8 @@ auth.hookEvents = function() {

var successFn = !successCallback ? null : function(profile, idToken, accessToken, state, refreshToken) {
idToken = idToken || profile.idToken;
accessToken = accessToken || profile.accessToken;
state = state || profile.state;
refreshToken = refreshToken || profile.refreshToken;
if (!idToken && !angular.isUndefined(options.loginAfterSignup) && !options.loginAfterSignup) {

@@ -637,2 +658,32 @@ successCallback();

auth.signinOnly = function(options, successCallback, errorCallback, libName) {
options = options || {};
checkHandlers(options, successCallback, errorCallback);
options = getInnerLibraryConfigField('parseOptions', libName)(options);
var signinMethod = getInnerLibraryMethod('signinOnly', libName);
var successFn = !successCallback ? null : function(profile, idToken, accessToken, state, refreshToken) {
if (!idToken && !angular.isUndefined(options.loginAfterSignup) && !options.loginAfterSignup) {
successCallback();
} else {
onSigninOk(idToken, accessToken, state, refreshToken, profile).then(function(profile) {
if (successCallback) {
successCallback(profile, idToken, accessToken, state, refreshToken);
}
});
}
};
var errorFn = !errorCallback ? null : function(err) {
callHandler('loginFailure', { error: err });
if (errorCallback) {
errorCallback(err);
}
};
var signinCall = authUtils.callbackify(signinMethod, successFn, errorFn , innerAuth0libraryConfiguration[libName || config.lib].library());
signinCall(options);
};
/*

@@ -678,3 +729,3 @@ *

* DESCRIPTION: Link multiple accounts (e.g: FB, Twitter, Google)
*
*
* INPUT: primaryJWT (string): Initial JWT assigned to User,

@@ -730,3 +781,3 @@ * primaryProfile (object): Primary account user profile,

* DESCRIPTION: Unlink linked accounts
*
*
* INPUT: primaryJWT (string): Initial JWT assigned to User,

@@ -736,3 +787,3 @@ * user_id (string): Primary account user id,

* secondaryUserId: Secondary account user id
*
*
* OUTPUT: Promise

@@ -753,3 +804,3 @@ *

* DESCRIPTION: Performs forgot your password flow
*
*
* INPUT: config options (object), Callbacks

@@ -827,6 +878,7 @@ *

angular.module('auth0.directives', ['auth0.service']);
angular.module('auth0.directives')
.directive('ifUser', ["$rootScope", function($rootScope){
.directive('ifUser', ['$rootScope', function($rootScope){
return {

@@ -833,0 +885,0 @@ link: function(scope, element){

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

angular.module("auth0",["auth0.service","auth0.utils","auth0.directives"]).run(["auth",function(a){a.hookEvents()}]),angular.module("auth0.utils",[]).provider("authUtils",function(){var a={capitalize:function(a){return a?a.charAt(0).toUpperCase()+a.substring(1).toLowerCase():null},fnName:function(a){var b=a.toString();return b=b.substr("function ".length),b=b.substr(0,b.indexOf("(")),b?b.trim():b}};angular.extend(this,a),this.$get=["$rootScope","$q",function(b,c){var d={};return angular.extend(d,a),d.safeApply=function(a){var c=b.$root.$$phase;"$apply"===c||"$digest"===c?a&&"function"==typeof a&&a():b.$apply(a)},d.callbackify=function(a,b,c,e){return angular.isFunction(a)?function(f){f=Array.prototype.slice.call(arguments);var g=function(a,d,e){return a?void(c&&c(a)):(e=Array.prototype.slice.call(arguments,1),void(b&&b.apply(null,e)))};(b||c)&&f.push(d.applied(g)),a.apply(e,f)}:void 0},d.promisify=function(a,b){return angular.isFunction(a)?function(e){e=Array.prototype.slice.call(arguments);var f=c.defer(),g=function(a,b,c){return a?void f.reject(a):(c=Array.prototype.slice.call(arguments,1),void f.resolve(c.length>1?c:b))};return e.push(d.applied(g)),a.apply(b,e),f.promise.spread=f.promise.spread||function(a,b){return f.promise.then(function(b){return Array.isArray(b)?a.apply(null,b):a(b)},b)},f.promise}:void 0},d.applied=function(a){return function(b,c){b=b,c=c;var e=arguments;d.safeApply(function(){a.apply(null,e)})}},d}]}),angular.module("auth0.service",["auth0.utils"]).provider("auth",["authUtilsProvider",function(a){function b(a,b){b=b||f.lib;var c=g[b].library();return c[g[b][a]]}function c(a,b){return b=b||f.lib,g[b][a]}function d(b){if(b)return{lib:a.fnName(b),constructor:b};if(null!=window.Auth0Lock)return{lib:"Auth0Lock",constructor:window.Auth0Lock};if(null!=window.Auth0)return{lib:"Auth0",constructor:window.Auth0};if("undefined"!=typeof Auth0Widget)throw new Error("Auth0Widget is not supported with this version of auth0-angularanymore. Please try with an older one");throw new Error("Cannot initialize Auth0Angular. Auth0Lock or Auth0 must be available")}var e={callbackOnLocationHash:!0},f=this,g={Auth0:{signin:"login",signup:"signup",reset:"changePassword",validateUser:"validateUser",library:function(){return f.auth0js},parseOptions:function(a){var b=angular.copy(a);return b.authParams&&(angular.extend(b,b.authParams),delete b.authParams),b}},Auth0Lock:{signin:"show",signup:"showSignup",reset:"showReset",library:function(){return f.auth0lib},parseOptions:function(a){return angular.copy(a)}}};this.init=function(a,b){if(!a)throw new Error("You must set options when calling init");this.loginUrl=a.loginUrl,this.loginState=a.loginState,this.clientID=a.clientID||a.clientId;var c=a.domain;this.domain=c,this.sso=a.sso;var f=d(b);this.lib=f.lib,"Auth0Lock"===f.lib?(this.auth0lib=new f.constructor(this.clientID,c,angular.extend(e,a)),this.auth0js=this.auth0lib.getClient(),this.isLock=!0):(this.auth0lib=new f.constructor(angular.extend(e,a)),this.auth0js=this.auth0lib,this.isLock=!1),this.initialized=!0},this.eventHandlers={},this.on=function(a,b){this.eventHandlers[a]||(this.eventHandlers[a]=[]),this.eventHandlers[a].push(b)};var h=["loginSuccess","loginFailure","logout","forbidden","authenticated"];angular.forEach(h,function(b){f["add"+a.capitalize(b)+"Handler"]=function(a){f.on(b,a)}}),this.$get=["$rootScope","$q","$injector","$window","$location","authUtils","$http",function(a,d,e,h,i,j,k){function l(){f.loginUrl?i.path(f.loginUrl):f.loginState?e.get("$state").go(f.loginState):p("forbidden")}function m(a,b,c,d){n.isAuthenticated||n.refreshTokenPromise||(f.sso?(a&&b.preventDefault(),f.auth0js.getSSOData(j.applied(function(e,f){if(f.sso){var g={popup:!1,callbackOnLocationHash:!0,connection:f.lastUsedConnection.name,authParams:{state:c()}};p("ssoLogin",{loginOptions:g}),n.signin(g,null,null,"Auth0")}else a&&(b.preventDefault(),d())}))):a&&(b.preventDefault(),d()))}var n={isAuthenticated:!1};a.isAuthenticated=!1;var o=function(a){return f.eventHandlers[a]},p=function(b,c){a.$broadcast("auth0."+b,c),angular.forEach(o(b)||[],function(a){e.invoke(a,n,c)})},q=function(b,c,d,e,f,g){var h=n.getProfile(b),i={idToken:b,accessToken:c,state:d,refreshToken:e,profile:f,isAuthenticated:!0};return a.isAuthenticated=!0,angular.extend(n,i),p(g?"authenticated":"loginSuccess",angular.extend({profilePromise:h},i)),h};a.$on("$locationChangeStart",function(){if(f.initialized){var a=f.auth0lib.parseHash(h.location.hash);return!n.isAuthenticated&&a&&(a.idToken||a.id_token)?void q(a.idToken||a.id_token,a.accessToken||a.access_token,a.state,a.refreshToken||a.refresh_token):void 0}}),a.$on("auth0.forbiddenRequest",function(){l()}),f.loginUrl&&a.$on("$routeChangeStart",function(a,b){f.initialized&&m(b.$$route&&b.$$route.requiresLogin,a,function(){return JSON.stringify({redirect_to:{path:i.path()}})},function(){i.path(f.loginUrl)})}),f.loginState&&a.$on("$stateChangeStart",function(a,b,c){f.initialized&&m(b.data&&b.data.requiresLogin,a,function(){return JSON.stringify({redirect_to:{state:b.name,params:c}})},function(){e.get("$state").go(f.loginState)})}),n.config=f;var r=function(a,b){var c=o("loginSuccess");if(!(b||a.username||a.email||c&&0!==c.length))throw new Error("You must define a loginSuccess handler if not using popup mode or not doing ro call because that means you are doing a redirect")},s=function(a,b,c){var d=c.user_id;return k({method:"POST",url:"https://"+f.domain+"/api/v2/users/"+d+"/identities",headers:{Authorization:"Bearer "+a},data:{link_with:b}})},t=function(a,b,c,d){return k({method:"DELETE",url:"https://"+f.domain+"/api/v2/users/"+b+"/identities/"+c+"/"+d,headers:{Authorization:"Bearer "+a}})};return n.hookEvents=function(){},n.init=angular.bind(f,f.init),n.getToken=function(a){a=a||{scope:"openid"},a.id_token||a.refresh_token||(a.id_token=n.idToken);var b=j.promisify(f.auth0js.getDelegationToken,f.auth0js);return b(a)},n.refreshIdToken=function(a){var b=j.promisify(f.auth0js.refreshToken,f.auth0js);return n.refreshTokenPromise=b(a||n.refreshToken).then(function(a){return a.id_token})["finally"](function(){n.refreshTokenPromise=null}),n.refreshTokenPromise},n.renewIdToken=function(a){var b=j.promisify(f.auth0js.renewIdToken,f.auth0js);return b(a||n.idToken).then(function(a){return a.id_token})},n.signin=function(a,d,e,h){a=a||{},r(a,d,e),a=c("parseOptions",h)(a);var i=b("signin",h),k=d?function(b,c,e,f,g){c||angular.isUndefined(a.loginAfterSignup)||a.loginAfterSignup?q(c,e,f,g,b).then(function(a){d&&d(a,c,e,f,g)}):d()}:null,l=e?function(a){p("loginFailure",{error:a}),e&&e(a)}:null,m=j.callbackify(i,k,l,g[h||f.lib].library());m(a)},n.signup=function(a,d,e){a=a||{},r(a,d,e),a=c("parseOptions")(a);var g=d?function(b,c,e,f,g){angular.isUndefined(a.auto_login)||a.auto_login?q(c,e,f,g,b).then(function(a){d&&d(a,c,e,f,g)}):d()}:null,h=e?function(a){p("loginFailure",{error:a}),e&&e(a)}:null,i=f.auth0lib,k=j.callbackify(b("signup"),g,h,i);k(a)},n.linkAccount=function(a,d,e,h,i,k){var l={popup:!0};if(!a||!d)throw new Error("Available token and profile is needed to link to another");if(!e.connection)throw new Error("Connection type (eg: facebook, github) is required to link account");e=e||{},r(e,h,i),angular.extend(e,l),e=c("parseOptions",k)(e);var m=b("signin",k),n=function(b,c){s(a,c,d).then(function(a){h(a)},function(a){i(a)})},o=function(a){i&&i(a)},p=j.callbackify(m,n,o,g[k||f.lib].library());p(e)},n.unLinkAccount=function(a,b,c,d){if(!(a&&b&&c&&d))throw new Error("All the arguments are required to unlink. Please refer to documentation for the arguments");return t(a,b,c,d)},n.reset=function(a,d,e){a=a||{},a=c("parseOptions")(a);var g=f.auth0lib,h=j.callbackify(b("reset"),d,e,g);h(a)},n.validateUser=function(a,d,e){a=a||{},a=c("parseOptions")(a);var g=f.auth0lib,h=j.callbackify(b("validateUser"),d,e,g);h(a)},n.signout=function(){n.isAuthenticated=!1,n.profile=null,n.profilePromise=null,n.idToken=null,n.state=null,n.accessToken=null,n.tokenPayload=null,a.isAuthenticated=!1,p("logout")},n.authenticate=function(a,b,c,d,e){return q(b,c,d,e,a,!0)},n.getProfile=function(a){var b=j.promisify(f.auth0lib.getProfile,f.auth0lib);return n.profilePromise=b(a||n.idToken),n.profilePromise.then(function(a){return n.profile=a,a})},n.hide=function(a){f.auth0lib.hide(a)},n}]}]),angular.module("auth0.directives",["auth0.service"]),angular.module("auth0.directives").directive("ifUser",["$rootScope",function(a){return{link:function(b,c){a.$watch("isAuthenticated",function(a){a?c.removeClass("ng-hide"):c.addClass("ng-hide")})}}}]);
angular.module("auth0",["auth0.service","auth0.utils","auth0.directives"]).run(["auth",function(a){a.hookEvents()}]),angular.module("auth0.utils",[]).provider("authUtils",function(){var a={capitalize:function(a){return a?a.charAt(0).toUpperCase()+a.substring(1).toLowerCase():null},fnName:function(a){var b=a.toString();return b=b.substr("function ".length),b=b.substr(0,b.indexOf("(")),b?b.trim():b}};angular.extend(this,a),this.$get=["$rootScope","$q",function(b,c){var d={};return angular.extend(d,a),d.safeApply=function(a){var c=b.$root.$$phase;"$apply"===c||"$digest"===c?a&&"function"==typeof a&&a():b.$apply(a)},d.callbackify=function(a,b,c,e){return angular.isFunction(a)?function(f){f=Array.prototype.slice.call(arguments);var g=function(a,d,e){return a?void(c&&c(a)):(e=Array.prototype.slice.call(arguments,1),void(b&&b.apply(null,e)))};(b||c)&&f.push(d.applied(g)),a.apply(e,f)}:void 0},d.promisify=function(a,b){return angular.isFunction(a)?function(e){e=Array.prototype.slice.call(arguments);var f=c.defer(),g=function(a,b,c){return a?void f.reject(a):(c=Array.prototype.slice.call(arguments,1),void f.resolve(c.length>1?c:b))};return e.push(d.applied(g)),a.apply(b,e),f.promise.spread=f.promise.spread||function(a,b){return f.promise.then(function(b){return Array.isArray(b)?a.apply(null,b):a(b)},b)},f.promise}:void 0},d.applied=function(a){return function(b,c){b=b,c=c;var e=arguments;d.safeApply(function(){a.apply(null,e)})}},d}]}),angular.module("auth0.service",["auth0.utils"]).provider("auth",["authUtilsProvider",function(a){function b(a,b){b=b||f.lib;var c=g[b].library();return c[g[b][a]]}function c(a,b){return b=b||f.lib,g[b][a]}function d(b){if(b)return{lib:a.fnName(b),constructor:b};if(null!=window.Auth0Lock)return{lib:"Auth0Lock",constructor:window.Auth0Lock};if(null!=window.Auth0)return{lib:"Auth0",constructor:window.Auth0};if("undefined"!=typeof Auth0Widget)throw new Error("Auth0Widget is not supported with this version of auth0-angularanymore. Please try with an older one");throw new Error("Cannot initialize Auth0Angular. Auth0Lock or Auth0 must be available")}var e={callbackOnLocationHash:!0},f=this,g={Auth0:{signin:"login",signinOnly:"signinOnly",signup:"signup",reset:"changePassword",validateUser:"validateUser",library:function(){return f.auth0js},parseOptions:function(a){var b=angular.copy(a);return b.authParams&&(angular.extend(b,b.authParams),delete b.authParams),b}},Auth0Lock:{signin:"show",signinOnly:"showSignin",signup:"showSignup",reset:"showReset",library:function(){return f.auth0lib},parseOptions:function(a){return angular.copy(a)}}};this.init=function(a,b){if(!a)throw new Error("You must set options when calling init");this.loginUrl=a.loginUrl,this.loginUrlParams=a.loginUrlParams,this.loginState=a.loginState,this.loginStateParams=a.loginStateParams,this.clientID=a.clientID||a.clientId;var c=a.domain;this.domain=c,this.sso=a.sso;var f=d(b);this.lib=f.lib,"Auth0Lock"===f.lib?(this.auth0lib=new f.constructor(this.clientID,c,angular.extend(e,a)),this.auth0js=this.auth0lib.getClient(),this.isLock=!0):(this.auth0lib=new f.constructor(angular.extend(e,a)),this.auth0js=this.auth0lib,this.isLock=!1),this.initialized=!0},this.eventHandlers={},this.on=function(a,b){this.eventHandlers[a]||(this.eventHandlers[a]=[]),this.eventHandlers[a].push(b)};var h=["loginSuccess","loginFailure","logout","forbidden","authenticated"];angular.forEach(h,function(b){f["add"+a.capitalize(b)+"Handler"]=function(a){f.on(b,a)}}),this.$get=["$rootScope","$q","$injector","$window","$location","authUtils","$http",function(a,d,e,h,i,j,k){function l(){f.loginUrl?i.path(f.loginUrl,f.loginUrlParams):f.loginState?e.get("$state").go(f.loginState,f.loginStateParams):p("forbidden")}function m(a,b,c,d){n.isAuthenticated||n.refreshTokenPromise||(f.sso?(a&&b.preventDefault(),f.auth0js.getSSOData(j.applied(function(e,f){if(f.sso){var g={popup:!1,callbackOnLocationHash:!0,connection:f.lastUsedConnection.name,authParams:{state:c()}};p("ssoLogin",{loginOptions:g}),n.signin(g,null,null,"Auth0")}else a&&(b.preventDefault(),d())}))):a&&(b.preventDefault(),d()))}var n={isAuthenticated:!1};a.isAuthenticated=!1;var o=function(a){return f.eventHandlers[a]},p=function(b,c){a.$broadcast("auth0."+b,c),angular.forEach(o(b)||[],function(a){e.invoke(a,n,c)})},q=function(b,c,d,e,f,g){b=b||f.idToken,c=c||f.accessToken,d=d||f.state,e=e||f.refreshToken;var h=n.getProfile(b),i={idToken:b,accessToken:c,state:d,refreshToken:e,profile:f,isAuthenticated:!0};return a.isAuthenticated=!0,angular.extend(n,i),p(g?"authenticated":"loginSuccess",angular.extend({profilePromise:h},i)),h};a.$on("$locationChangeStart",function(){if(f.initialized){var a=f.auth0lib.parseHash(h.location.hash);return!n.isAuthenticated&&a&&(a.idToken||a.id_token)?void q(a.idToken||a.id_token,a.accessToken||a.access_token,a.state,a.refreshToken||a.refresh_token):void 0}}),a.$on("auth0.forbiddenRequest",function(){l()}),f.loginUrl&&a.$on("$routeChangeStart",function(a,b){f.initialized&&m(b.$$route&&b.$$route.requiresLogin,a,function(){return JSON.stringify({redirect_to:{path:i.path()}})},function(){i.path(f.loginUrl,f.loginUrlParams)})}),f.loginState&&a.$on("$stateChangeStart",function(a,b,c){f.initialized&&m(b.data&&b.data.requiresLogin,a,function(){return JSON.stringify({redirect_to:{state:b.name,params:c}})},function(){e.get("$state").go(f.loginState,f.loginStateParams)})}),n.config=f;var r=function(a,b){var c=o("loginSuccess");if(!(b||a.username||a.email||c&&0!==c.length))throw new Error("You must define a loginSuccess handler if not using popup mode or not doing ro call because that means you are doing a redirect")},s=function(a,b,c){var d=c.user_id;return k({method:"POST",url:"https://"+f.domain+"/api/v2/users/"+d+"/identities",headers:{Authorization:"Bearer "+a},data:{link_with:b}})},t=function(a,b,c,d){return k({method:"DELETE",url:"https://"+f.domain+"/api/v2/users/"+b+"/identities/"+c+"/"+d,headers:{Authorization:"Bearer "+a}})};return n.hookEvents=function(){},n.init=angular.bind(f,f.init),n.getToken=function(a){a=a||{scope:"openid"},a.id_token||a.refresh_token||(a.id_token=n.idToken);var b=j.promisify(f.auth0js.getDelegationToken,f.auth0js);return b(a)},n.refreshIdToken=function(a){var b=j.promisify(f.auth0js.refreshToken,f.auth0js);return n.refreshTokenPromise=b(a||n.refreshToken).then(function(a){return a.id_token})["finally"](function(){n.refreshTokenPromise=null}),n.refreshTokenPromise},n.renewIdToken=function(a){var b=j.promisify(f.auth0js.renewIdToken,f.auth0js);return b(a||n.idToken).then(function(a){return a.id_token})},n.signin=function(a,d,e,h){a=a||{},r(a,d,e),a=c("parseOptions",h)(a);var i=b("signin",h),k=d?function(b,c,e,f,g){c=c||b.idToken,e=e||b.accessToken,f=f||b.state,g=g||b.refreshToken,c||angular.isUndefined(a.loginAfterSignup)||a.loginAfterSignup?q(c,e,f,g,b).then(function(a){d&&d(a,c,e,f,g)}):d()}:null,l=e?function(a){p("loginFailure",{error:a}),e&&e(a)}:null,m=j.callbackify(i,k,l,g[h||f.lib].library());m(a)},n.signinOnly=function(a,d,e,h){a=a||{},r(a,d,e),a=c("parseOptions",h)(a);var i=b("signinOnly",h),k=d?function(b,c,e,f,g){c||angular.isUndefined(a.loginAfterSignup)||a.loginAfterSignup?q(c,e,f,g,b).then(function(a){d&&d(a,c,e,f,g)}):d()}:null,l=e?function(a){p("loginFailure",{error:a}),e&&e(a)}:null,m=j.callbackify(i,k,l,g[h||f.lib].library());m(a)},n.signup=function(a,d,e){a=a||{},r(a,d,e),a=c("parseOptions")(a);var g=d?function(b,c,e,f,g){angular.isUndefined(a.auto_login)||a.auto_login?q(c,e,f,g,b).then(function(a){d&&d(a,c,e,f,g)}):d()}:null,h=e?function(a){p("loginFailure",{error:a}),e&&e(a)}:null,i=f.auth0lib,k=j.callbackify(b("signup"),g,h,i);k(a)},n.linkAccount=function(a,d,e,h,i,k){var l={popup:!0};if(!a||!d)throw new Error("Available token and profile is needed to link to another");if(!e.connection)throw new Error("Connection type (eg: facebook, github) is required to link account");e=e||{},r(e,h,i),angular.extend(e,l),e=c("parseOptions",k)(e);var m=b("signin",k),n=function(b,c){s(a,c,d).then(function(a){h(a)},function(a){i(a)})},o=function(a){i&&i(a)},p=j.callbackify(m,n,o,g[k||f.lib].library());p(e)},n.unLinkAccount=function(a,b,c,d){if(!(a&&b&&c&&d))throw new Error("All the arguments are required to unlink. Please refer to documentation for the arguments");return t(a,b,c,d)},n.reset=function(a,d,e){a=a||{},a=c("parseOptions")(a);var g=f.auth0lib,h=j.callbackify(b("reset"),d,e,g);h(a)},n.validateUser=function(a,d,e){a=a||{},a=c("parseOptions")(a);var g=f.auth0lib,h=j.callbackify(b("validateUser"),d,e,g);h(a)},n.signout=function(){n.isAuthenticated=!1,n.profile=null,n.profilePromise=null,n.idToken=null,n.state=null,n.accessToken=null,n.tokenPayload=null,a.isAuthenticated=!1,p("logout")},n.authenticate=function(a,b,c,d,e){return q(b,c,d,e,a,!0)},n.getProfile=function(a){var b=j.promisify(f.auth0lib.getProfile,f.auth0lib);return n.profilePromise=b(a||n.idToken),n.profilePromise.then(function(a){return n.profile=a,a})},n.hide=function(a){f.auth0lib.hide(a)},n}]}]),angular.module("auth0.directives",["auth0.service"]),angular.module("auth0.directives").directive("ifUser",["$rootScope",function(a){return{link:function(b,c){a.$watch("isAuthenticated",function(a){a?c.removeClass("ng-hide"):c.addClass("ng-hide")})}}}]);

@@ -49,3 +49,3 @@ ## Linking Accounts

auth.signin({
connection: 'google-oauth2'
connection: 'google-oauth2',
authParams: {

@@ -60,6 +60,7 @@ access_token: auth.accessToken

}, 'Auth0');
};
$scope.linkTwitter = function () {
auth.signin({
connection: 'twitter'
connection: 'twitter',
authParams: {

@@ -74,2 +75,3 @@ access_token: auth.accessToken

}, 'Auth0');
};
```

@@ -120,2 +122,2 @@

});
```
```

@@ -46,3 +46,11 @@ # Storing information

if (!auth.isAuthenticated) {
auth.authenticate(store.get('profile'), token);
auth.authenticate(store.get('profile'), token).then(function (profile) {
console.log("Logged in via refresh token and got profile");
console.log(profile);
// Successful login, now redirect to secured content.
}, function (err) { });;
}

@@ -49,0 +57,0 @@ } else {

@@ -6,3 +6,3 @@ {

"author": "Martin Gontovnikas",
"version": "4.2.1",
"version": "4.2.2",
"main": "index.js",

@@ -19,3 +19,3 @@ "devDependencies": {

"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-jshint": "^0.12.0",
"grunt-contrib-uglify": "~0.2.4",

@@ -37,4 +37,3 @@ "grunt-contrib-watch": "~0.2.0",

"mocha": "^1.18.2",
"phantomjs": "^1.9.0",
"phantomjs-prebuilt": "^2.1.7",
"phantomjs": "^2.1.3",
"protractor": "^0.21.0",

@@ -41,0 +40,0 @@ "selenium-webdriver": "^2.41.0",

angular.module('auth0', ['auth0.service', 'auth0.utils', 'auth0.directives'])
.run(["auth", function(auth) {
.run(['auth', function(auth) {
auth.hookEvents();
}]);
angular.module('auth0.directives')
.directive('ifUser', ["$rootScope", function($rootScope){
.directive('ifUser', ['$rootScope', function($rootScope){
return {

@@ -5,0 +5,0 @@ link: function(scope, element){

angular.module('auth0.service', ['auth0.utils'])
.provider('auth', ["authUtilsProvider", function(authUtilsProvider) {
.provider('auth', ['authUtilsProvider', function(authUtilsProvider) {
var defaultOptions = {

@@ -12,2 +12,3 @@ callbackOnLocationHash: true

signin: 'login',
signinOnly: 'signinOnly',
signup: 'signup',

@@ -30,2 +31,3 @@ reset: 'changePassword',

signin: 'show',
signinOnly: 'showSignin',
signup: 'showSignup',

@@ -45,3 +47,3 @@ reset: 'showReset',

* DESCRIPTION: Get a method from the libraries
*
*
* INPUT: method name (string), library name (string)

@@ -61,3 +63,3 @@ * OUTPUT: String

* DESCRIPTION: Get a config from the libraries
*
*
* INPUT: config name (string), library name (string)

@@ -74,5 +76,5 @@ * OUTPUT: String

*
* DESCRIPTION: Returns a constructor: Defaults to a function if provided.
* DESCRIPTION: Returns a constructor: Defaults to a function if provided.
* Defaults to a Lock if library is included and function is not provided
*
*
* INPUT: function

@@ -117,3 +119,3 @@ * OUTPUT: object

* DESCRIPTION: Configures provider with provided options
*
*
* INPUT: option (object) and constructor

@@ -127,3 +129,5 @@ *

this.loginUrl = options.loginUrl;
this.loginUrlParams = options.loginUrlParams;
this.loginState = options.loginState;
this.loginStateParams = options.loginStateParams;
this.clientID = options.clientID || options.clientId;

@@ -166,3 +170,3 @@ var domain = options.domain;

this.$get = ["$rootScope", "$q", "$injector", "$window", "$location", "authUtils", "$http",
this.$get = ['$rootScope', '$q', '$injector', '$window', '$location', 'authUtils', '$http',
function($rootScope, $q, $injector, $window, $location, authUtils, $http) {

@@ -186,5 +190,12 @@ var auth = {

// SignIn
var onSigninOk = function(idToken, accessToken, state, refreshToken, profile, isRefresh) {
idToken = idToken || profile.idToken;
accessToken = accessToken || profile.accessToken;
state = state || profile.state;
refreshToken = refreshToken || profile.refreshToken;
var profilePromise = auth.getProfile(idToken);

@@ -213,5 +224,5 @@

if (config.loginUrl) {
$location.path(config.loginUrl);
$location.path(config.loginUrl, config.loginUrlParams);
} else if (config.loginState) {
$injector.get('$state').go(config.loginState);
$injector.get('$state').go(config.loginState, config.loginStateParams);
} else {

@@ -258,3 +269,3 @@ callHandler('forbidden');

function(){
$location.path(config.loginUrl);
$location.path(config.loginUrl, config.loginUrlParams);
}

@@ -272,2 +283,3 @@ );

verifyRoute(

@@ -285,3 +297,3 @@ (to.data && to.data.requiresLogin),

function() {
$injector.get('$state').go(config.loginState);
$injector.get('$state').go(config.loginState, config.loginStateParams);
}

@@ -292,2 +304,4 @@ );

/*jshint latedef: nofunc */
function verifyRoute(requiresLogin, e, getState, redirectToLogin) {

@@ -346,4 +360,4 @@ if (!auth.isAuthenticated && !auth.refreshTokenPromise) {

}
)
}
);
};

@@ -359,4 +373,4 @@ var unLinkAccount = function(primaryJWT, user_id, secondaryProvider, secondaryUserId){

}
)
}
);
};

@@ -437,2 +451,8 @@ auth.hookEvents = function() {

var successFn = !successCallback ? null : function(profile, idToken, accessToken, state, refreshToken) {
idToken = idToken || profile.idToken;
accessToken = accessToken || profile.accessToken;
state = state || profile.state;
refreshToken = refreshToken || profile.refreshToken;
if (!idToken && !angular.isUndefined(options.loginAfterSignup) && !options.loginAfterSignup) {

@@ -461,2 +481,32 @@ successCallback();

auth.signinOnly = function(options, successCallback, errorCallback, libName) {
options = options || {};
checkHandlers(options, successCallback, errorCallback);
options = getInnerLibraryConfigField('parseOptions', libName)(options);
var signinMethod = getInnerLibraryMethod('signinOnly', libName);
var successFn = !successCallback ? null : function(profile, idToken, accessToken, state, refreshToken) {
if (!idToken && !angular.isUndefined(options.loginAfterSignup) && !options.loginAfterSignup) {
successCallback();
} else {
onSigninOk(idToken, accessToken, state, refreshToken, profile).then(function(profile) {
if (successCallback) {
successCallback(profile, idToken, accessToken, state, refreshToken);
}
});
}
};
var errorFn = !errorCallback ? null : function(err) {
callHandler('loginFailure', { error: err });
if (errorCallback) {
errorCallback(err);
}
};
var signinCall = authUtils.callbackify(signinMethod, successFn, errorFn , innerAuth0libraryConfiguration[libName || config.lib].library());
signinCall(options);
};
/*

@@ -502,3 +552,3 @@ *

* DESCRIPTION: Link multiple accounts (e.g: FB, Twitter, Google)
*
*
* INPUT: primaryJWT (string): Initial JWT assigned to User,

@@ -554,3 +604,3 @@ * primaryProfile (object): Primary account user profile,

* DESCRIPTION: Unlink linked accounts
*
*
* INPUT: primaryJWT (string): Initial JWT assigned to User,

@@ -560,3 +610,3 @@ * user_id (string): Primary account user id,

* secondaryUserId: Secondary account user id
*
*
* OUTPUT: Promise

@@ -577,3 +627,3 @@ *

* DESCRIPTION: Performs forgot your password flow
*
*
* INPUT: config options (object), Callbacks

@@ -649,2 +699,2 @@ *

}];
}]);
}]);

@@ -11,2 +11,3 @@ /*

* */
angular.module('auth0.utils', [])

@@ -43,3 +44,3 @@ .provider('authUtils', function() {

this.$get = ["$rootScope", "$q", function($rootScope, $q) {
this.$get = ['$rootScope', '$q', function($rootScope, $q) {
var authUtils = {};

@@ -46,0 +47,0 @@ angular.extend(authUtils, Utils);

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

/*exported initAuth0 */
function executeInConfigBlock(cb, includes) {

@@ -2,0 +3,0 @@ var fakeModule = angular.module('fakeModule', []);

@@ -9,3 +9,3 @@ describe('if user: ', function () {

$compile = _$compile_;
})
});

@@ -12,0 +12,0 @@

@@ -37,2 +37,20 @@ describe('Auth0 Angular', function () {

describe('authenticate', function() {
var auth, $rootScope, $timeout;
beforeEach(initAuth0);
beforeEach(inject(function (_auth_, _$rootScope_, _$timeout_) {
auth = _auth_;
$rootScope = _$rootScope_;
$timeout = _$timeout_;
}));
it('isAuthenticated must be true after authenticate', function () {
expect(auth.isAuthenticated).to.be.equal(false);
auth.authenticate('id-token');
expect(auth.isAuthenticated).to.be.equal(true);
$timeout.flush();
});
});
describe('auth.profile and getProfile', function () {

@@ -81,2 +99,20 @@ var auth, $rootScope, $timeout;

describe('link accounts', function() {
var auth, $rootScope, $timeout;
beforeEach(initAuth0);
beforeEach(inject(function (_auth_, _$rootScope_, _$timeout_) {
auth = _auth_;
$rootScope = _$rootScope_;
$timeout = _$timeout_;
}));
it('link', function() {
auth.linkAccount('token', {}, {connection:'facebook'},
function() {
expect.to.be.ok;
});
});
});
describe('signout', function () {

@@ -83,0 +119,0 @@ var auth, $rootScope, $timeout;

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