После моего предыдущего вопроса об ember-simple-auth и torii я успешно аутентифицирую своих пользователей своими учетными записями Facebook.
Но в настоящее время поставщик torii facebook-oauth2 возвращает код авторизации от Facebook; когда обещание решает, я отправляю этот код авторизации на свой бэкэнд, где я выполняю запрос против Facebook, чтобы получить идентификатор пользователя и адрес электронной почты: затем я аутентифицирую пользователя на своем бэкэнд, создавая конкретный токен доступа и отправляя обратно в свое приложение ember.
Клиентский код:
// app/controllers/login.js
import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';
export
default Ember.Controller.extend(LoginControllerMixin, {
// This authenticator for a simple login/password authentication.
authenticator: 'simple-auth-authenticator:oauth2-password-grant',
actions: {
// This method for login with Facebook.
authenticateWithFacebook: function() {
var _this = this;
this.get('session').authenticate(
'simple-auth-authenticator:torii',
"facebook-oauth2"
).then(
function() {
var authCode = _this.get('session.authorizationCode');
Ember.$.ajax({
type: "POST",
url: window.ENV.host + "/facebook/auth.json",
data: JSON.stringify({
auth_code: authCode
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
// TODO : manage access_token and save it to the session
},
failure: function(errMsg) {
// TODO : manage error
}
});
},
function(error) {
alert('There was an error when trying to sign you in: ' + error);
}
);
}
}
});
Проблема заключается в следующем: сеанс ember-simple-auth помечен как аутентифицированный, когда обещает аутентификация, а затем приложение перенаправляется на определенный аутентифицированный маршрут. Но в этом случае сеанс должен быть аутентифицирован, когда мой бэкэнд возвращает "реальный" access_token.
Есть ли способ управлять этим документооборотом с помощью ember-simple-auth-torii или я должен написать собственный аутентификатор?