免責事項 - パトリックバークレーと私は一緒に働いています。この質問を投稿した後、私が共有すると思った解決策が見つかりました。
ember-simple-authのクッキーストアのバージョン0.7.3が1.0.0のバージョンでうまく動作するためには、以前のバージョンのアプリでクッキーがどのようにフォーマットされていたのかを標準化する必要がありました多くの場合、session
オブジェクト(the 0.7.3 session
は、独自のカスタムセッションを作成するために消費アプリで拡張できるObjectProxyです)を中心とした重要な場所はほとんどありません。
セッションを復元するときにクッキーストアに渡されるデータの構造と、返される内容を中心にオーバーライドする必要のあるメソッド。主な相違点は、セッションのオブジェクトプロパティcontent
にバージョン0.7.3、access_tokenなどが最上位に格納されています。 1.0.0。これはコンテンツ内の別のオブジェクトの中にネストされ、プロパティ名はauthenticated
です。したがって、私たちはどこでもトップレベルでaccess_tokenを設定または取得することを前提としていましたが、代わりに1レベルをより深く検索する必要がありました。このことを念頭に置いて、我々はカスタムsession
オブジェクトにこれらのメソッドがオーバーライドされて思い付いた:
// alias access_token to point to new place
access_token: Ember.computed.alias('content.authenticated.access_token'),
// overridden methods to handle v2 cookie structure
restore: function() {
return new Ember.RSVP.Promise((resolve, reject) => {
const restoredContent = this.store.restore();
const authenticator = restoredContent.authenticated.authenticator;
if (!!authenticator) {
delete restoredContent.authenticated.authenticator;
this.container.lookup(authenticator).restore(restoredContent.authenticated).then(function(content) {
this.setup(authenticator, content);
resolve();
},() => {
this.store.clear();
reject();
});
} else {
this.store.clear();
reject();
}
});
},
updateStore: function() {
let data = this.content;
if (!Ember.isEmpty(this.authenticator)) {
Ember.set(data, 'authenticated', Ember.merge({ authenticator: this.authenticator }, data.authenticated || {}));
}
if (!Ember.isEmpty(data)) {
this.store.persist(data);
}
},
setup(authenticator, authenticatedContent, trigger) {
trigger = !!trigger && !this.get('isAuthenticated');
this.beginPropertyChanges();
this.setProperties({
isAuthenticated: true,
authenticator
});
Ember.set(this, 'content.authenticated', authenticatedContent);
this.bindToAuthenticatorEvents();
this.updateStore();
this.endPropertyChanges();
if (trigger) {
this.trigger('sessionAuthenticationSucceeded');
}
},
clear: function(trigger) {
trigger = !!trigger && this.get('isAuthenticated');
this.beginPropertyChanges();
this.setProperties({
isAuthenticated: false,
authenticator: null
});
Ember.set(this.content, 'authenticated', {});
this.store.clear();
this.endPropertyChanges();
if (trigger) {
this.trigger('sessionInvalidationSucceeded');
}
},
bindToStoreEvents: function() {
this.store.on('sessionDataUpdated', (content) => {
const authenticator = content.authenticated.authenticator;
this.set('content', content);
if (!!authenticator) {
delete content.authenticated.authenticator;
this.container.lookup(authenticator).restore(content.authenticated).then((content) => {
this.setup(authenticator, content, true);
},() => {
this.clear(true);
});
} else {
this.clear(true);
}
});
}.observes('store'),
これは私たちが道のほとんどを取りました。使用するオーセンティケータ名が1.0.0の名前と一致するようにするだけでした。 'simple-auth-authenticator:oauth2-password-grant'
の代わりに、認証者の名前を'authenticator:oauth2'
に変更する必要がありました。これにより、Cookieセッションデータが変更されたときに、新しいバージョンのアプリケーションが正しいオーセンティケータイベントを処理できるようになります。初期化ロジックは十分に簡単です:
import OAuth2 from 'simple-auth-oauth2/authenticators/oauth2';
export default {
name: 'oauth2',
before: 'simple-auth',
initialize: function(container) {
container.register('authenticator:oauth2', OAuth2);
}
};
上記を満たして私たちのneeds-は、我々は燃えさし-シンプル-AUTH 0.7を使用してアプリにサインインすることができます。3とcookieセッションを格納し、ember-simple-auth 1.0.0上の別のアプリケーションが処理するように適切にフォーマットしてください。
理想的には、私たちはビジネスニーズはありますが、完全に新鮮で新しいコードベースのv2バージョンに力を注ぐことを望んでいたにもかかわらず、EmberとEmber Simple Authバージョンを更新するだけですこの道を下る。
ESA 1.0と1.0では、異なるセッションフォーマットが使用されます。どちらのバージョンでも、他のバージョンで生成されたデータは使用できません。あなたのユースケースは、より良く清潔な方法で解決される可能性があります。達成しようとしていることをより詳細に説明できますか? – marcoow
ありがとう@marcoow。私たちの目標は、2つのアプリケーションが同じブラウザで開いていてタブが異なる場合にセッションを同期させることです。私たちはこれで今働いています。しかし、ちょっとした問題は、新しいESAバージョンでアプリケーションからサインアウトすると、古いESAバージョンのブラウザタブで[syncData'](https://github.com/simplabs/ember-simple-auth)が呼び出されないということです/blob/0.7.3/packages/ember-simple-auth-cookie-store/lib/simple-auth-cookie-store/stores/cookie.js#L174-L184)、正確に60秒間、セッションはそこで期限切れになりますあまりにも。何か案は? –