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의 버그입니까? 어떻게 수정해야합니까?
정보를 제공해 주셔서 감사합니다.하지만'reject()'를 반환해도 문제가 해결되지 않습니다. 이것은 또 다른 문제로 보입니다. 어떤 이유로 Ember Simple Auth의 예제 (https://github.com/simplabs/ember-simple-auth/blob/master/examples/7-multiple-external-providers.html)에이 오류가 표시되지 않습니다. . 지금은 예제와 더 유사하게 코드를 변경하고 잘못된 점을 파악하려고합니다. –
이 문제는 [Ember 1.10] (https://github.com/emberjs/ember.js/releases/tag/v1.10.0-beta.2), 특히 5 번째 지점에서 해결 된 것으로 보입니다. 잘하면 그것은 당신이 상대하고있는 것을 다룰 것입니다. –