2015-01-30 3 views
0

Ember Simple Auth의 기본 인증 클래스를 확장하여 Google 인증을 허용합니다. 지금까지 Safari 8 및 Chrome 41 (모두 Yosemite에서)에서 오류없이 작동합니다. 그러나 Firefox 35에서는 다른 브라우저에서는 발생하지 않는 오류가 발생합니다. 여기에 내 Google 인증 클래스입니다 :Ember Simple Auth on Firefox : authentication throws Error

App.GoogleAuthenticator = SimpleAuth.Authenticators.Base.extend({ 
    // constants for Google API 
    GAPI_CLIENT_ID: 'the client id', 
    GAPI_SCOPE: ['email'], 
    GAPI_TOKEN_VERIFICATION_ENDPOINT: 'https://www.googleapis.com/oauth2/v2/tokeninfo', 

    // method for scheduleing a single token refresh 
    // time in milliseconds 
    scheduleSingleTokenRefresh: function(time) { 
     var self = this; 
     return new Ember.RSVP.Promise(function(resolve, reject) { 
      Ember.run.later(self, function() { 
       gapi.auth.authorize({ 
        client_id: self.GAPI_CLIENT_ID, 
        scope: self.GAPI_SCOPE, 
        immediate: true 
       }, function(data) { 
        if (data && !data.error) { 
         resolve(data); 
        } else { 
         reject((data || {}).error); 
        } 
       }); 
      }, time); 
     }); 
    }, 
    // WIP: recursive method that reschedules another token refresh after the previous scheduled one was fulfilled 
    // usage: scheduleTokenRefreshes(time until token should refresh for the first time, time between subsequent refreshes) 
    // usage: scheduleTokenRefreshes(time between refreshes) 
    scheduleTokenRefreshes: function(time1, time2) { 
     var self = this; 
     // if there is a time2, schedule a single refresh, wait for it to be fulfilled, then call myself to schedule again 
     if (!Ember.isEmpty(time2)) { 
      self.scheduleSingleTokenRefresh(time1) 
      .then(function() { 
       self.scheduleTokenRefreshes(time2); 
      }); 
     // if there isn't a time2, simply schedule a single refresh, then call myself to schedule again 
     } else { 
      self.scheduleSingleTokenRefresh(time1) 
      .then(function() { 
       self.scheduleTokenRefreshes(time1); 
      }); 
     } 
    }, 

    // method that restores the session on reload 
    restore: function(data) { 
     var self = this; 
     return new Ember.RSVP.Promise(function(resolve, reject) { 
      console.log(data); 
      if (Ember.isEmpty(data.access_token)) { 
       reject(); 
       return; 
      } 
      // schedule a refresh 15 minutes before it expires or immediately if it expires in < 15 
      var timeNow = Math.floor(Date.now()/1000); 
      var expiresAt = +data.expires_at; 
      var timeDifference = expiresAt - timeNow; 
      var schedulingDelay = Math.floor(timeDifference - 15 * 60); 
      schedulingDelay = schedulingDelay < 0 ? 0 : schedulingDelay; 
      self.scheduleTokenRefreshes(schedulingDelay * 1000, 45 * 60); 
      resolve(data); 
     }); 
    }, 
    // method that authenticates 
    authenticate: function() { 
     var self = this; 
     return new Ember.RSVP.Promise(function(resolve, reject) { 
      gapi.auth.authorize({ 
       client_id: self.GAPI_CLIENT_ID, 
       scope: self.GAPI_SCOPE 
      }, function(data) { 
       if (data && !data.error) { 
        // schedule a refresh in 45 minutes 
        var schedulingDelay = 45 * 60; 
        self.scheduleTokenRefreshes(schedulingDelay * 1000); 
        resolve(data); 
       } else { 
        reject((data || {}).error); 
       } 
      }); 
     }); 
    }, 
    // method that logs the user out and revokes the token 
    invalidate: function(data) { 
     var self = this; 
     return new Ember.RSVP.Promise(function(resolve, reject) { 
      // send a GET request to revoke the token 
      Ember.$.ajax({ 
       type: 'GET', 
       url: 'https://accounts.google.com/o/oauth2/revoke?token=' + self.get('session.access_token'), 
       contentType: 'application/json', 
       dataType: 'jsonp' 
      }) 
      .done(function(successData) { 
       resolve(successData); 
      }) 
      .fail(function(error) { 
       reject(error); 
      }); 
     }); 
    } 
}); 

팝업 창 구글의 끝에 성공적으로 로그인이 오류가 파이어 폭스의 콘솔에 나타납니다 후 닫을 때 :

: 여기
Error: Assertion Failed: Error: Permission denied to access property 'toJSON' ember.js:13749 
"__exports__.default<[email protected]://127.0.0.1/~jonchan/test/bower_components/ember-simple-auth/simple-auth.js:1524:1 
__exports__.default<[email protected]://127.0.0.1/~jonchan/test/bower_components/ember-simple-auth/simple-auth.js:1195:11 
__exports__.default<[email protected]://127.0.0.1/~jonchan/test/bower_components/ember-simple-auth/simple-auth.js:1149:9 
__exports__.default<.authenticate/</<@http://127.0.0.1/~jonchan/test/bower_components/ember-simple-auth/simple-auth.js:1066:13 
[email protected]://127.0.0.1/~jonchan/test/bower_components/ember/ember.js:47982:16 
[email protected]://127.0.0.1/~jonchan/test/bower_components/ember/ember.js:47994:17 
[email protected]://127.0.0.1/~jonchan/test/bower_components/ember/ember.js:47965:11 
@http://127.0.0.1/~jonchan/test/bower_components/ember/ember.js:29462:9 
[email protected]://127.0.0.1/~jonchan/test/bower_components/ember/ember.js:848:11 
[email protected]://127.0.0.1/~jonchan/test/bower_components/ember/ember.js:913:13 
[email protected]://127.0.0.1/~jonchan/test/bower_components/ember/ember.js:718:13 
[email protected]://127.0.0.1/~jonchan/test/bower_components/ember/ember.js:143:11 
createAutorun/backburner._autorun<@http://127.0.0.1/~jonchan/test/bower_components/ember/ember.js:546:9 
" ember.js:29488 

이 버전 정보입니다
DEBUG: Ember    : 1.9.1 
DEBUG: Ember Data  : 1.0.0-beta.14.1 
DEBUG: Handlebars  : 2.0.0 
DEBUG: jQuery   : 2.1.3 
DEBUG: Ember Simple Auth : 0.7.2 

가장 혼란스러운 점은 Firefox에서만 나타납니다. Ember Simple Auth 또는 Ember의 버그입니까? 어떻게 수정해야합니까?

답변

0

오류가 authenticate 방법의 resolve 부분이었다 낸다. 다음은이를 수정 한 내용입니다.

App.GoogleAuthenticator = SimpleAuth.Authenticators.Base.extend({ 
    authenticate: function() { 
     return new Ember.RSVP.Promise(function(resolve, reject) { 
      gapi.auth.authorize({ 
       client_id: 'the client id', 
       scope: ['the scopes'], 
      }, function(data) { 
       if (data && !data.error) { 
        resolve({ 
         access_token: data.access_token // !! passing the entire 'data' object caused the error somehow 
        }); 
       } else { 
        reject((data || {}).error); 
       } 
      }); 
     }); 
    }, 
    // ... 
}); 

왜 이것이 오류의 원인인지 아직 확실하지 않습니다. 아마도 Google API의 응답 (전체적으로)이 Ember Simple Auth와 호환되지 않을 수도 있습니다.

0

파이어 폭스가 오류를 발생시키는 경우 (Chrome 40과 비슷한 오류가 발생했습니다) 모르겠지만 실제 오류 보내기를 금지하는 Ember-simple-auth 0.7.2 및 Ember 1.9의 버그가 있습니다. 인증 자의 authenticate 메소드의 응답.

reject()의 거부 기능을 authenticate (으)로 반환하면 추가 오류가 발생하지 않습니다. 그러나 이것은 errorstatus 나 메시지를 전달하지 않으므로 버그라고 생각합니다.

Ember.onerror=Ember.K을 일시적으로 설정하여 추가 오류가 전파되지 않도록이 문제에 대한 github의 해결 방법이 제시되었지만 오류 상태로 원래 authenticate 거부를 전파합니다.

github 저장소의 문제는 테스트의 문제 만 언급하지만 정상적인 코드에서는이 문제가 발생했습니다.

볼 : https://github.com/simplabs/ember-simple-auth/issues/407

+0

정보를 제공해 주셔서 감사합니다.하지만'reject()'를 반환해도 문제가 해결되지 않습니다. 이것은 또 다른 문제로 보입니다. 어떤 이유로 Ember Simple Auth의 예제 (https://github.com/simplabs/ember-simple-auth/blob/master/examples/7-multiple-external-providers.html)에이 오류가 표시되지 않습니다. . 지금은 예제와 더 유사하게 코드를 변경하고 잘못된 점을 파악하려고합니다. –

+0

이 문제는 [Ember 1.10] (https://github.com/emberjs/ember.js/releases/tag/v1.10.0-beta.2), 특히 5 번째 지점에서 해결 된 것으로 보입니다. 잘하면 그것은 당신이 상대하고있는 것을 다룰 것입니다. –