Node.js「passport-google-oauth2」がExpressアプリケーションで「ユーザープロファイルの取得に失敗しました」というエラーを発する 質問する

Node.js「passport-google-oauth2」がExpressアプリケーションで「ユーザープロファイルの取得に失敗しました」というエラーを発する 質問する

最後の例を開発しながらの紹介Google OpenIDによる認証戦略を使用するアプリケーション)をpassport-googleパッケージに置き換えた後(2015年4月20日に廃止されました)passport-google-oauth2パッケージ(Google OAuth 2.0による認証戦略)を使用し、ドキュメントのページ例はこちら; Google+ アカウントを選択した後、モジュールによってスローされた以下のエラーが発生しました。具体的には、メソッド内でoath2.js呼び出します。関連するソース コードとモジュールの依存関係は次のとおりです。this._oauth2.get("https://www.googleapis.com/plus/v1/people/me",...)userProfile(accessToken, done)

問題の根本は何なのでしょうか?

具体的なエラーは次のとおりです。

InternalOAuthError: failed to fetch user profile
    at <...>\web-app\b4\node_modules\passport-google-oauth2\lib\oauth2.js:92:28
    at passBackControl (<...>\web-app\b4\node_modules\passport-google-oauth2\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:124:9)
    at IncomingMessage.<anonymous> (<...>\web-app\b4\node_modules\passport-google-oauth2\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:143:7)
    at IncomingMessage.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)

関連するアプリケーションのコードは次のとおりです。

  passport = require('passport'),
  //...
  GoogleStrategy = require('passport-google-oauth2').Strategy; // #passport-google-oauth2
  //...
  /***** #passport-google-oauth2 vv *****/
  passport.use(new GoogleStrategy({
    clientID: "a_specific_value",
    clientSecret: "another_specific_value",
    callbackURL: "http://127.0.0.1:3000/auth/google/callback",
    passReqToCallback:true
  },
  function(request, accessToken, refreshToken, profile, done) {
      profile.identifier=profile.id;
      return done(null, profile);
  }
  ));
  /***** #passport-google-oauth2 ^^ *****/
  //...
  /*****  #passport-google-oauth2 vv    *****/
  app.get('/auth/google',
  passport.authenticate('google', { successRedirect: '/',scope:
    [ 'https://www.googleapis.com/auth/userinfo.email']})
  );
  app.get( '/auth/google/callback',
    passport.authenticate( 'google', {
        successRedirect: '/',
        failureRedirect: '/'
  }));
  /*****  #passport-google-oauth2 ^^    *****/    

アプリケーションには次の依存関係があります。

[メールアドレス]
├─┬[メールアドレス]
│ ├─┬[メールアドレス]
│ │ └──[メールアドレス]
│ └──[メールアドレス]
├─┬[メールアドレス]
│ ├──[メールアドレス]
│ └──[メールアドレス]
├─┬[メールアドレス]
│ ├──[メールアドレス]
│ ├─┬[メールアドレス]
│ │ └──[メールアドレス]
│ ├─┬[メールアドレス]
│ │ ├──[メールアドレス]
│ │ ├──[メールアドレス]
│ │ ├──[メールアドレス]
│ │ ├──[メールアドレス]
│ │ └──[メールアドレス]
│ ├──[メールアドレス]
│ ├──[メールアドレス]
│ ├─┬[メールアドレス]
│ │ └──[メールアドレス]
│ ├──[メールアドレス]
│ ├──[メールアドレス]
│ ├──[メールアドレス]
│ ├──[メールアドレス]
│ └─┬[メールアドレス]
│ └──[メールアドレス]
├─┬[メールアドレス]
│ ├──[メールアドレス]
│ ├──[メールアドレス]
│ ├──[メールアドレス]
│ ├─┬[メールアドレス]
│ │ └──[メールアドレス]
│ ├──[メールアドレス]
│ ├──[メールアドレス]
│ ├──[メールアドレス]
│ ├─┬[メールアドレス]
│ │ ├──[メールアドレス]
│ │ └──[メールアドレス]
│ └──[メールアドレス]
├─┬[メールアドレス]
│ ├──[メールアドレス]
│ ├─┬[メールアドレス]
│ │ └──[メールアドレス]
│ ├──[メールアドレス]
│ └─┬[メールアドレス]
│ └──[メールアドレス]
├─┬[メールアドレス]
│ └──[メールアドレス]
├─┬[メールアドレス]
│ ├──[メールアドレス]
│ └──[メールアドレス]
├─┬[メールアドレス]
│ └─┬[メールアドレス]
│ ├──[メールアドレス]
│ ├──[メールアドレス]
│ └──[メールアドレス]
├──[メールアドレス]
├──[メールアドレス]
└─┬[メールアドレス]
  ├──[メールアドレス]
  ├──[メールアドレス]
  ├──[メールアドレス]
  ├─┬[メールアドレス]
  │ ├──[メールアドレス]
  │ └─┬[メールアドレス]
  │ └──[メールアドレス]
  ├─┬[メールアドレス]
  │ ├──[メールアドレス]
  │ ├──[メールアドレス]
  │ ├──[メールアドレス]
  │ └──[メールアドレス]
  ├─┬[メールアドレス]
  │ ├──[メールアドレス]
  │ ├──[メールアドレス]
  │ └──[メールアドレス]
  ├──[メールアドレス]
  ├──[メールアドレス]
  ├──[メールアドレス]
  ├──[メールアドレス]
  ├──[メールアドレス]
  └──[メールアドレス]

ベストアンサー1

幸運にも、同様の問題をjaredhanson/パスポート-google-oauthそこから私はアイデアを得たへ行くことGoogleのプロジェクトコンソールそして、Google+ APIは「オフ」になっていました (ああ、私は Google+ をベースにした最初のアプリケーションを開発した素人です)。これが問題の根本でした。もう一度試してみたところ、oauth2プロファイルを正しく受信し始めました。

おすすめ記事