简体   繁体   English

为什么Google Drive API / Oauth2刷新令牌请求会返回错误消息“执行此操作需要SSL”。

[英]Why does Google Drive API / Oauth2 refresh token request, returns an error saying “SSL is required to perform this operation.”?

i'm new to OAuth2 and it confuses me why my refresh token request gets a response of "SSL is required to perform this operation." 我是OAuth2的新手,这使我感到困惑,为什么我的刷新令牌请求得到响应“执行此操作需要SSL”。 when obviously we got an SSL free from DigitalOcean. 显然,我们从DigitalOcean获得了免费的SSL。

  public function refresh_token($test = false){

    $url = "www.googleapis.com/oauth2/v4/token";
    $credentials = $this->credentials();
    $refresh_token = $credentials->refresh_token;
    $client_id = $credentials->client_id;
    $client_secret = $credentials->client_secret;
    $redirect =  base_url($credentials->redirect_url);

    $data = "client_id=$client_id&client_secret=$client_secret&refresh_token=$refresh_token&grant_type=refresh_token";

    $access = $this->curl_post($url,$data,array('Content-Type: application/x-www-form-urlencoded'));

    if($test){
      echo "<pre>";
      echo $access;
      die();
    }

    $access = json_decode($access);

    if(isset($access->access_token)){
      $this->admin->update(
        array('access_token'=>$access->access_token),
        'sheet_config',
        array('status'=>1)
      );
      echo $access->access_token;
      return true;
    }else{
      echo $access->error->message;
      return false;
    }
  }

I was expecting a result of a new token or some errors like your certificate is messed up or you need to configure something with digital ocean first about your SSL 我期待一个新令牌的结果或某些错误,例如您的证书被弄乱,或者您需要先使用Digital Ocean配置一些有关SSL的内容

I'm so noob about SSL and stuff, but i'm pretty sure that we have an SSL since we run https:// 我对SSL和其他内容非常了解,但是我很确定,因为我们运行https://,所以我们拥有SSL

Because making a call to an authorization server on HTTP would be really bad! 因为在HTTP上调用授权服务器确实很糟糕!

This $url = "www.googleapis.com/oauth2/v4/token"; 这个$url = "www.googleapis.com/oauth2/v4/token"; is the same as doing $url = "http://www.googleapis.com/oauth2/v4/token" ; 与执行$url = "http://www.googleapis.com/oauth2/v4/token" and no authorization server would respond to that. 而且没有授权服务器会对此做出响应。

That being said i think you are just missing the https on the front of your url. 话虽这么说,我认为您只是在网址前面缺少https

$url = "https://www.googleapis.com/oauth2/v4/token";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM