1- /* oauth-ng - v0.2.8 - 2014-10-28 */
1+ /* oauth-ng - v0.3.0 - 2014-10-30 */
22
33'use strict' ;
44
@@ -20,7 +20,7 @@ angular.module('oauth').config(['$locationProvider','$httpProvider',
2020
2121var accessTokenService = angular . module ( 'oauth.accessToken' , [ 'ngStorage' ] ) ;
2222
23- accessTokenService . factory ( 'AccessToken' , function ( $rootScope , $location , $sessionStorage , $timeout ) {
23+ accessTokenService . factory ( 'AccessToken' , function ( $rootScope , $location , $sessionStorage , $interval ) {
2424
2525 var service = {
2626 token : null
@@ -43,7 +43,7 @@ accessTokenService.factory('AccessToken', function($rootScope, $location, $sessi
4343 * - takes the token from the sessionStorage
4444 */
4545 service . set = function ( ) {
46- setTokenFromString ( $location . hash ( ) ) ;
46+ this . setTokenFromString ( $location . hash ( ) ) ;
4747
4848 //If hash is present in URL always use it, cuz its coming from oAuth2 provider redirect
4949 if ( null === service . token ) {
@@ -72,15 +72,11 @@ accessTokenService.factory('AccessToken', function($rootScope, $location, $sessi
7272 } ;
7373
7474
75- /* * * * * * * * * *
76- * PRIVATE METHODS *
77- * * * * * * * * * */
78-
7975 /**
8076 * Get the access token from a string and save it
8177 * @param hash
8278 */
83- var setTokenFromString = function ( hash ) {
79+ service . setTokenFromString = function ( hash ) {
8480 var params = getTokenFromString ( hash ) ;
8581
8682 if ( params ) {
@@ -91,6 +87,11 @@ accessTokenService.factory('AccessToken', function($rootScope, $location, $sessi
9187 }
9288 } ;
9389
90+
91+ /* * * * * * * * * *
92+ * PRIVATE METHODS *
93+ * * * * * * * * * */
94+
9495 /**
9596 * Set the access token from the sessionStorage.
9697 */
@@ -161,9 +162,9 @@ accessTokenService.factory('AccessToken', function($rootScope, $location, $sessi
161162 var setExpiresAtEvent = function ( ) {
162163 var time = ( new Date ( service . token . expires_at ) ) - ( new Date ( ) ) ;
163164 if ( time ) {
164- $timeout ( function ( ) {
165+ $interval ( function ( ) {
165166 $rootScope . $broadcast ( 'oauth:expired' , service . token )
166- } , time )
167+ } , time , 1 )
167168 }
168169 } ;
169170
@@ -239,13 +240,16 @@ endpointClient.factory('Endpoint', function(AccessToken, $location) {
239240
240241var profileClient = angular . module ( 'oauth.profile' , [ ] )
241242
242- profileClient . factory ( 'Profile' , function ( $http , AccessToken ) {
243+ profileClient . factory ( 'Profile' , function ( $http , AccessToken , $rootScope ) {
243244 var service = { } ;
244245 var profile ;
245246
246247 service . find = function ( uri ) {
247248 var promise = $http . get ( uri , { headers : headers ( ) } ) ;
248- promise . success ( function ( response ) { profile = response } ) ;
249+ promise . success ( function ( response ) {
250+ profile = response ;
251+ $rootScope . $broadcast ( 'oauth:profile' , profile ) ;
252+ } ) ;
249253 return promise ;
250254 } ;
251255
0 commit comments