|
8 | 8 | */
|
9 | 9 | angular.module('googleOauth', ['angularOauth']).
|
10 | 10 |
|
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) { |
13 | 14 | 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 | + }); |
29 | 33 | });
|
30 |
| - }); |
31 |
| - } |
| 34 | + }); |
| 35 | + |
| 36 | + return deferred; |
| 37 | + }]); |
32 | 38 | }).
|
33 | 39 |
|
34 | 40 | config(function(TokenProvider, GoogleTokenVerifier) {
|
35 | 41 | TokenProvider.extendConfig({
|
36 | 42 | authorizationEndpoint: 'https://accounts.google.com/o/oauth2/auth',
|
37 |
| - tokenVerifierEndpoint: 'https://www.googleapis.com/oauth2/v1/tokeninfo', |
38 | 43 | scopes: ["https://www.googleapis.com/auth/userinfo.email"],
|
39 | 44 | verifyFunc: GoogleTokenVerifier
|
40 | 45 | });
|
|
0 commit comments