2016-03-23 4 views
3

PHPベースのアプリケーションで動作するGoogle Identity Toolkit APIを取得しようとしています。Google Identity Toolkit API for PHPが返されるINVALID_CLIENT

私はここに利用できるGoogleからのクイック・スタート・ガイドを追ってきた: https://developers.google.com/identity/toolkit/web/quickstart/php

私は正確に手順を追った(とチェックされ、二重にチェック)しました。

index.phpページにサインインボタンが表示されます。これをクリックするとwidget.phpページにリダイレクトされます。私は内のOAuthクライアントを再作成しようとした

Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "invalid_client", "error_description" : "The OAuth client was invalid." }'

:ページに成功記号(index.php再び)に戻ったとき、私は、私は次のエラーメッセージが表示され、その後、私はでログインしたいアカウントを選択し、することができますGoogleデベロッパーコンソール。 Eメールとプロジェクト名のフィールドを確認するために述べた検索結果の一部は、OAuth Consent画面で完成しました。

任意のヘルプ&アドバイスをいただければ幸いです。 注:アイデンティティ・ツールキットの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サーバ-config.jsonファイル:あなたのgitkitで

{ 
    "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" 
} 

答えて

6

I持っていた私は、サーバ設定コード内の「正しい」サービスアカウントのメール挿入することによって、それを解決し、同じ問題:

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

そのトリックはserviceAccouですntEmailその後、サービスアカウントキーの下にクリックは、使用中のサービスにアクセスし、電子メールのフィールドに注意し、サービスを右にリンクを占める管理資格情報に行く正しいメールを検索するには、Googleのメールされていません。電子メールは長く、形式は次のようになります[email protected]

+0

ありがとう、それはそれを解決しました:) –

+0

それは私の問題を解決しました。参考:正しいサービスアカウントのメールは https://console.developers.google.com/permissions/serviceaccounts 「サービスアカウントID」の列をご覧ください。 – hirikarate

0

-server-config.jsonファイルの場合、serviceAccountEmailは空でなければなりません。 Google Developers Consoleのプロジェクト設定ページからサービスアカウントのメールをコピーできます。

+0

残念ながら、これは問題を解決しません。 –

0

としてだけでなく、サービスアカウントの電子メール(「[email protected]」のような何か、プロジェクトIDは私の問題を引き起こした。私が見つけた

ソリューションでしたGoogleはあなたのPROJECTIDは「example.com:appname」であるならば、それを変更する「APPNAME」

関連する問題