How can I verify a Google authentication API access token?

前端 未结 10 494
长发绾君心
长发绾君心 2020-11-30 17:19

How can I verify a Google authentication access token?

I need to somehow query Google and ask: Is [given access token] valid for the [exampl

10条回答
  •  执笔经年
    2020-11-30 17:49

    function authenticate_google_OAuthtoken($user_id)
    {
        $access_token   = google_get_user_token($user_id); // get existing token from DB
        $redirecturl    = $Google_Permissions->redirecturl;
        $client_id      = $Google_Permissions->client_id;
        $client_secret  = $Google_Permissions->client_secret;
        $redirect_uri   = $Google_Permissions->redirect_uri;
        $max_results    = $Google_Permissions->max_results;
    
        $url = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token='.$access_token;
        $response_contacts  =  curl_get_responce_contents($url);
        $response   =   (json_decode($response_contacts));
    
        if(isset($response->issued_to))
        {
            return true;
        }
        else if(isset($response->error))
        {
            return false;
        }
    }
    

提交回复
热议问题