8000 fix(google): move $deferred inside of the GoogleTokenVerifier injector · angular-oauth/angular-oauth@7757211 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7757211

Browse files
committed
fix(google): move $deferred inside of the GoogleTokenVerifier injector
- Move the $deferred object to GoogleTokenVerifier and inside $injector.invoke and return directly $deferred.promise - Update the demo to call $rootScope.$apply inside the verifyAsync then() Closes #1, #8
1 parent 607deb8 commit 7757211

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

example/js/demo.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ angular.module('demo', ['googleOauth']).
1717
});
1818
}).
1919

20-
controller('DemoCtrl', function($scope, $window, Token) {
20+
controller('DemoCtrl', function($rootScope, $scope, $window, Token) {
2121
$scope.accessToken = Token.get();
2222

2323
$scope.authenticate = function() {
@@ -29,10 +29,12 @@ angular.module('demo', ['googleOauth']).
2929
// Verify the token before setting it, to avoid the confused deputy problem.
3030
Token.verifyAsync(params.access_token).
3131
then(function(data) {
32-
$scope.accessToken = params.access_token;
33-
$scope.expiresIn = params.expires_in;
32+
$rootScope.$apply(function() {
33+
$scope.accessToken = params.access_token;
34+
$scope.expiresIn = params.expires_in;
3435

35-
Token.set(params.access_token);
36+
Token.set(params.access_token);
37+
});
3638
}, function() {
3739
alert("Failed to verify token.")
3840
});
@@ -42,4 +44,4 @@ angular.module('demo', ['googleOauth']).
4244
alert("Failed to get token from popup.");
4345
});
4446
};
45-
});
47+
});

src/js/angularOauth.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ angular.module('angularOauth', []).
115115
* `status`, `headers`, `config`).
116116
*/
117117
verifyAsync: function(accessToken) {
118-
var deferred = $q.defer();
119-
config.verifyFunc(config, accessToken, deferred);
120-
return deferred.promise;
118+
return config.verifyFunc(config, accessToken);
121119
},
122120

123121
/**

src/js/googleOauth.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
*/
99
angular.module('googleOauth', ['angularOauth']).
1010

11-
constant('GoogleTokenVerifier', function(config, accessToken, deferred) {
11+
constant('GoogleTokenVerifier', function(config, accessToken) {
1212
var $injector = angular.injector(['ng']);
13-
return $injector.invoke(['$http', '$rootScope', function($http, $rootScope) {
13+
return $injector.invoke(['$http', '$rootScope', '$q', function($http, $rootScope, $q) {
14+
var deferred = $q.defer();
1415
var verificationEndpoint = 'https://www.googleapis.com/oauth2/v1/tokeninfo';
1516

1617
$rootScope.$apply(function() {
@@ -33,7 +34,7 @@ angular.module('googleOauth', ['angularOauth']).
3334
});
3435
});
3536

36-
return deferred;
37+
return deferred.promise;
3738
}]);
3839
}).
3940

0 commit comments

Comments
 (0)
0