3

PHP ベースのアプリケーションで Google Identity Toolkit API を動作させようとしています。

ここで入手できるGoogleのクイックスタートガイドに従っています: https://developers.google.com/identity/toolkit/web/quickstart/php

私は正確に手順に従いました(そしてチェックしてダブルチェックしました)。

ページにサインイン ボタンが表示されindex.phpます。これをクリックすると、ページにリダイレクトされwidget.phpます。サインインに使用するアカウントを選択できます。サインインに成功したページに戻ると (index.phpもう一度)、次のエラー メッセージが表示されます。

致命的なエラー:「OAuth2 トークンの更新中にエラーが発生しました。メッセージ: '{ "error" : "invalid_client", "error_description" : "The OAuth client was invalid." (OAuth クライアントが無効でした。) }'

Google Developer Console 内で OAuth クライアントを再作成してみました。電子メールとプロジェクト名のフィールドを確認するために言及されたいくつかの検索結果は、OAuth 同意画面で完了しました。すべて完了しました。

ヘルプとアドバイスをいただければ幸いです。注: Identity Toolkit API 設定で使用可能なプロバイダーのうち、「Google」のみを使用しています。

私の index.php ページ:

<!DOCTYPE html>
<html>
<head>

<!-- 1: Load the Google Identity Toolkit helpers -->
<?php
  set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ .'/vendor/google/apiclient/src');
  require_once __DIR__ . '/vendor/autoload.php';

  $gitkitClient = Gitkit_Client::createFromFile(dirname(__FILE__) . '/gitkit-server-config.json');
  $gitkitUser = $gitkitClient->getUserInRequest();
?>
<!-- End modification 1 -->

<script type="text/javascript" src="//www.gstatic.com/authtoolkit/js/gitkit.js"></script>
<link type=text/css rel=stylesheet href="//www.gstatic.com/authtoolkit/css/gitkit.css" />

<script type=text/javascript>
  window.google.identitytoolkit.signInButton(
    '#navbar',
    {
      widgetUrl: "/gitkit",
      signOutUrl: "/index"
    }
  );
</script>
</head>
<body>
<div id="navbar"></div>

<!-- 2: Print the user information if a signed in user is present -->
<p>
  <?php if ($gitkitUser) { ?>
    Welcome back!<br><br>
    Email: <?= $gitkitUser->getEmail() ?><br>
    Id: <?= $gitkitUser->getUserId() ?><br>
    Name: <?= $gitkitUser->getDisplayName() ?><br>
    Identity provider: <?= $gitkitUser->getProviderId() ?><br>
  <?php } else { ?>
    You are not logged in yet.
  <?php } ?>
</p>
<!-- End modification 2 -->

</body>
</html>

私の gitkit.php ページ:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<!-- Copy and paste here the client configuration from Developer Console into the config variable -->
<script type="text/javascript" src="//www.gstatic.com/authtoolkit/js/gitkit.js"></script>
<link type="text/css" rel="stylesheet" href="//www.gstatic.com/authtoolkit/css/gitkit.css" />
<script type="text/javascript">
  var config =
    {
  "widgetUrl": "http://local.myfakedomain.com/gitkit",
  "signInSuccessUrl": "/",
  "signOutUrl": "/",
  "oobActionUrl": "/",
  "apiKey": "<my-api-key-here>",
  "siteName": "this site",
  "signInOptions": ["password","google"]
}
  ;
  // The HTTP POST body should be escaped by the server to prevent XSS
  window.google.identitytoolkit.start(
      '#gitkitWidgetDiv', // accepts any CSS selector
      config,
      JSON.parse('<?php echo json_encode(file_get_contents("php://input")); ?>')
  );
</script>
<!-- End modification -->

</head>
<body>

<!-- Include the sign in page widget with the matching 'gitkitWidgetDiv' id -->
<div id="gitkitWidgetDiv"></div>
<!-- End identity toolkit widget -->

</body>
</html>

私の gitkit-server-config.json ファイル:

{
  "clientId": "<my-client-id-here>",
  "projectId": "<my-project-id-here>",
  "serviceAccountEmail": "<my-serviceAccountEmail-here>",
  "serviceAccountPrivateKeyFile": "<my-p12-KeyFile-location-here>",
  "widgetUrl": "http://local.myfakedomain.com/gitkit",
  "cookieName": "gtoken"
}
4

3 に答える 3

0

gitkit-server-config.json ファイルで、serviceAccountEmail を空にしないでください。サービス アカウントのメールは、Google Developers Console のプロジェクト設定ページからコピーできます。

于 2016-03-23T17:54:13.550 に答える