0

このエラーは、ローカルまたはオンラインのベータ環境では発生せず、本番環境でのみ発生することをもう一度述べておきましょう。3つのサーバーすべてが同じ次の環境変数を共有しているにもかかわらず:

REDDIT_USERNAME=username
REDDIT_PASSWORD=pwd
REDDIT_ID=id
REDDIT_SECRET=secret

この方法を使用して本番環境で reddit アクセス トークンをリクエストしようとすると、次のようになります。

/**
 * @internal
 *
 * Request A Reddit Token
 *
 * If the client does not have a current valid OAuth2 token, fetch one here. Set it as a cookie.
 */
private function requestRedditToken() {
    $response = $this->client->post(Reddit::ACCESS_TOKEN_URL, array(
        'query' => [
            [
                'client_id' => $this->clientId,
                'response_type' => 'code',
                'state' => bin2hex(openssl_random_pseudo_bytes(10)),
                'redirect_uri' => 'http://localhost/reddit/test.php',
                'duration' => 'permanent',
                'scope' => 'save,modposts,identity,edit,flair,history,modconfig,modflair,modlog,modposts,modwiki,mysubreddits,privatemessages,read,report,submit,subscribe,vote,wikiedit,wikiread'
            ]
        ],
        'auth' => [$this->clientId, $this->clientSecret],
        'form_params' => [
            'grant_type' => 'password',
            'username' => $this->username,
            'password' => $this->password
        ]
    ));

    $body = json_decode($response->getBody());
    $this->tokenType = $body->token_type;
    $this->accessToken = $body->access_token;

    // Set the cookie to expire in 60 minutes.
    setcookie('reddit_token', $this->tokenType . ':' . $this->accessToken, 60 * 60 + time());
}

$response->getBody()が に等しいため、アプリのフローを中断する例外が発生しinvalid_grantます。

しかし、異なる環境で正確に類似した資格情報を使用し、Postman を使用するだけでも、応答で有効なアクセス トークンを受け取ることになるため、なぜ無効なのかわかりません。何が起きてる?

4

0 に答える 0