8000 Fix bug in GoogleTokenVerifier causing it never to work. · angular-oauth/angular-oauth@7ee4007 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ee4007

Browse files
committed
Fix bug in GoogleTokenVerifier causing it never to work.
Apparently, I was horribly misusing constants. Comprehensive tests would have uncovered this. I'm not convinced that I'm doing the right thing by injecting services inside the verification function, and this particular section (the verification function and how best to make that customizable) could really use a second pair of eyes. It would help to know a pattern for configuring functions that use services inside providers.
1 parent 45ee9eb commit 7ee4007

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/js/googleOauth.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,38 @@
88
*/
99
angular.module('googleOauth', ['angularOauth']).
1010

11-
constant('GoogleTokenVerifier', function($http) {
12-
return function(config, accessToken, deferred) {
11+
constant('GoogleTokenVerifier', function(config, accessToken, deferred) {
12+
var $injector = angular.injector(['ng']);
13+
return $injector.invoke(['$http', '$rootScope', function($http, $rootScope) {
1314
var verificationEndpoint = 'https://www.googleapis.com/oauth2/v1/tokeninfo';
14-
$http.get(verificationEndpoint, {params: {access_token: accessToken}}).
15-
success(function(data) {
16-
if (data.audience == config.clientId) {
17-
deferred.resolve(data);
18-
} else {
19-
deferred.reject({name: 'invalid_audience'});
20-
}
21-
}).
22-
error(function(data, status, headers, config) {
23-
deferred.reject({
24-
name: 'error_response',
25-
data: data,
26-
status: status,
27-
headers: headers,
28-
config: config
15+
16+
$rootScope.$apply(function() {
17+
$http({method: 'GET', url: verificationEndpoint, params: {access_token: accessToken}}).
18+
success(function(data) {
19+
if (data.audience == config.clientId) {
20+
deferred.resolve(data);
21+
} else {
22+
deferred.reject({name: 'invalid_audience'});
23+
}
24+
}).
25+
error(function(data, status, headers, config) {
26+
deferred.reject({
27+
name: 'error_response',
28+
data: data,
29+
status: status,
30+
headers: headers,
31+
config: config
32+
});
2933
});
30-
});
31-
}
34+
});
35+
36+
return deferred;
37+
}]);
3238
}).
3339

3440
config(function(TokenProvider, GoogleTokenVerifier) {
3541
TokenProvider.extendConfig({
3642
authorizationEndpoint: 'https://accounts.google.com/o/oauth2/auth',
37-
tokenVerifierEndpoint: 'https://www.googleapis.com/oauth2/v1/tokeninfo',
3843
scopes: ["https://www.googleapis.com/auth/userinfo.email"],
3944
verifyFunc: GoogleTokenVerifier
4045
});

0 commit comments

Comments
 (0)
0