Google Ads Api Oauth Catchable Exception

Aperta
#404 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
php

Direzione di ricerca

Inizia tracciando il percorso di un refresh token scaduto attraverso vendor/google/auth/src/OAuth2.php e vendor/google/auth/src/Credentials/UserRefreshCredentials.php, usando la risposta invalid_grant segnalata come caso di riproduzione. Determina quale eccezione raggiunge il chiamante e se la libreria espone un punto affidabile per la gestione. Il lavoro è completo quando l’errore può essere distinto e gestito in modo prevedibile, con una copertura di test o una documentazione del comportamento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

needs more info type: question
        try {
            // Generate a refreshable OAuth2 credential for authentication.
            $oAuth2Credential = (new OAuth2TokenBuilder())
                ->withClientId(env('GOOGLE_ADS_CLIENT_ID'))
                ->withClientSecret(env('GOOGLE_ADS_CLIENT_SECRET'))
                ->withRefreshToken($refreshToken)
                ->build();
        } catch (\Throwable $e) {
            return $this->job->fail();
        }

        try {
            // Construct a Google Ads client configured from a properties file and the
            // OAuth2 credentials above.
            $googleAdsClient = (new GoogleAdsClientBuilder())
                ->withOAuth2Credential($oAuth2Credential)
                ->withDeveloperToken(env('GOOGLE_ADS_DEVELOPER_TOKEN'))
                ->withLoginCustomerId($customerID)
                ->withTransport('rest')
                ->build();
        } catch (\Throwable $e) {
            return $this->job->fail();
        }

So i have the code above which is using the google auth library to create the oauth credential, however some of our clients have expired refresh tokens: This spits out:

Message
Client error: POST https://oauth2.googleapis.com/token resulted in a 400 Bad Request response:
{
 "error": "invalid_grant",
 "error_description": "Token has been expired or revoked."
}
Level
ERROR
Exception
{
    "class": "GuzzleHttp\\Exception\\ClientException",
    "message": "Client error: `POST https://oauth2.googleapis.com/token` resulted in a `400 Bad Request` response:\n{\n  \"error\": \"invalid_grant\",\n  \"error_description\": \"Token has been expired or revoked.\"\n}\n",
    "code": 400,
    "file": "/usr/local/bigtop/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113",
    "trace": [
        "/usr/local/bigtop/vendor/guzzlehttp/guzzle/src/Middleware.php:69",
        "/usr/local/bigtop/vendor/guzzlehttp/promises/src/Promise.php:204",
        "/usr/local/bigtop/vendor/guzzlehttp/promises/src/Promise.php:153",
        "/usr/local/bigtop/vendor/guzzlehttp/promises/src/TaskQueue.php:48",
        "/usr/local/bigtop/vendor/guzzlehttp/promises/src/Promise.php:248",
        "/usr/local/bigtop/vendor/guzzlehttp/promises/src/Promise.php:224",
        "/usr/local/bigtop/vendor/guzzlehttp/promises/src/Promise.php:269",
        "/usr/local/bigtop/vendor/guzzlehttp/promises/src/Promise.php:226",
        "/usr/local/bigtop/vendor/guzzlehttp/promises/src/Promise.php:62",
        "/usr/local/bigtop/vendor/guzzlehttp/guzzle/src/Client.php:123",
        "/usr/local/bigtop/vendor/google/auth/src/HttpHandler/Guzzle6HttpHandler.php:47",
        "/usr/local/bigtop/vendor/google/auth/src/OAuth2.php:544",
        "/usr/local/bigtop/vendor/google/auth/src/Credentials/UserRefreshCredentials.php:114",
        "/usr/local/bigtop/vendor/google/auth/src/CredentialsLoader.php:214",
        "/usr/local/bigtop/vendor/google/gax/src/CredentialsWrapper.php:208",
        "/usr/local/bigtop/vendor/google/gax/src/Transport/HttpUnaryTransportTrait.php:111",
        "/usr/local/bigtop/vendor/google/gax/src/Transport/RestTransport.php:110",
        "/usr/local/bigtop/vendor/google/gax/src/GapicClientTrait.php:608",
        "/usr/local/bigtop/vendor/google/gax/src/Middleware/CredentialsWrapperMiddleware.php:61",
        "/usr/local/bigtop/vendor/google/gax/src/Middleware/FixedH

Is there a good way to be able to catch that since it's being caught inside the libraries and i'm not seeing a way to properly handle that exception.

Lingua principale
PHP
Stelle
1.4k
Fork
197
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.