1

私は一週間中、認証を機能させるために取り組んできました。私はそれが動作するようになりました

  • Ember-CLI
  • Ember-Simple-Auth
  • 鳥居
    • google-oauth2 プロバイダー

ただし、Google からユーザー情報を取得できませんでした。ドキュメントに記載されているように torii-adapter を作成しようとしましたが、呼び出されていないようです

// app/torii-adapters/application.js
export default Ember.Object.extend({
  open: function(authorization){
    console.log('authorization from adapter', authorization);
  }
});

google-foo を使い果たしたので、あなたの助けを求めています。これは承認のための優れたライブラリの組み合わせですが、この場合のドキュメントは不足しており、判明したら必ず貢献します.

ありがとうございました

4

1 に答える 1

4

私が遭遇した問題は、Torii のデフォルトの google-oauth2 プロバイダーがこの情報にアクセスせず、google+ API に必要なトークン ワークフローの代わりにコード ワークフローを使用することです。

これを修正するために、G+ API への jquery GET リクエストを使用するカスタム プロバイダーを作成し、コンテンツの下のセッションで userName と userEmail を返してアクセスします。

ここで、Google の開始から終了までを使用して ember アプリを承認する方法を詳しく説明した完全なチュートリアルを書きました。

//app/torii-providers/google-token.js
import {configurable} from 'torii/configuration';
import Oauth2Bearer from 'torii/providers/oauth2-bearer';

var GoogleToken = Oauth2Bearer.extend({
  name: 'google-token',
  baseUrl: 'https://accounts.google.com/o/oauth2/auth',

  // additional params that this provider requires
  requiredUrlParams: ['state'],
  optionalUrlParams: ['scope', 'request_visible_actions', 'access_type'],

  requestVisibleActions: configurable('requestVisibleActions', ''),

  accessType: configurable('accessType', ''),

  responseParams: ['token'],

  scope: configurable('scope', 'email'),

  state: configurable('state', 'STATE'),

  redirectUri: configurable('redirectUri',
                            'http://localhost:8000/oauth2callback'),

  open: function(){
      var name        = this.get('name'),
          url         = this.buildUrl(),
          redirectUri = this.get('redirectUri'),
          responseParams = this.get('responseParams');

      var client_id = this.get('client_id');

      return this.get('popup').open(url, responseParams).then(function(authData){
        var missingResponseParams = [];

        responseParams.forEach(function(param){
          if (authData[param] === undefined) {
            missingResponseParams.push(param);
          }
        });

        if (missingResponseParams.length){
          throw "The response from the provider is missing " +
                "these required response params: " + responseParams.join(', ');
        }

        return $.get("https://www.googleapis.com/plus/v1/people/me", {access_token: authData.token}).then(function(user){
          return {
            userName: user.displayName,
            userEmail: user.emails[0].value,
            provider: name,
            redirectUri: redirectUri
          };
        });
      });
    }
});

export default GoogleToken;
于 2014-12-20T20:03:37.543 に答える