7

I am working on Yii2. I have a URL which on hitting a browser is redirected to my redirect URI.

URL

https://accounts.zoho.com/oauth/v2/auth?scope=ZohoBugTracker.projects.ALL,ZohoBugTracker.bugs.ALL&client_id=1000&response_type=code&access_type=offline&redirect_uri=http://11.111.111.111:7000/api/oauth/zoho_auth

When I hit the above URL it will redirect to my redirect URI while giving a code

Redirect URI

After hitting the above URL the redirect URI is http://11.111.111.111:7000/api/oauth/zoho_auth?code=1000&location=us&accounts-server=https%3A%2F%2Faccounts.zoho.com

Redirect URI Response

{"Message":"No HTTP resource was found that matches the request URI 'http://11.111.111.111:7000/api/oauth/zoho_auth?code=1000&location=us&accounts-server=https:%2F%2Faccounts.zoho.com'."}

How to get the code from the above response?

Update 1

As per suggestion given. I tried to send a GET request using linslin. Below is my code

 public static function authToken()
{

    $curl = new curl\Curl();
    $response = $curl->setGetParams([
        'scope' => 'ZohoBugTracker.projects.ALL,ZohoBugTracker.bugs.ALL',
        'client_id' => '1000',
        'response_type' => 'code',
        'access_type' => 'offline',
        'redirect_uri' => 'http://11.111.111.111:7000/api/oauth/zoho_auth',
    ])
        ->get('https://accounts.zoho.com/oauth/v2/auth');

    echo $response;
    exit();
}

And then called this function inside a function through which I am actually creating bugs using zoho API

Testing my API via POSTMAN

http://localhost:225/inventory-web/api/web/v1/installation/email?ref_no=28373340485858U&customer_id=37030315933&site_snap_name=28373340485858U_1530958224_site_9.jpg&flag=1

My email function is written inside a API controller. So, it will first hit the issueSetup($param1,$param2)

public function actionEmail()
{
    .
    .
    .
    .

     Installations::setupEmail($param1, $param2, $param3);
    .
    .
    .
}

The above function setupEmail($param1,$param2,$param3) is inside my controller.

 public static function setupEmail($ref_no, $customer_id, $install_id)
 {
     .
     .
     .
     .
     .
      list(params.....)= Installations::issueSetup($param1,$param2);
     .
     .
     .
     .      
  }

issuSetup funciton

public static function issueSetup($param1,$param2)
{
     .
     .
     .
     .
    $token = Installations::authToken();

    exit();
    .
    .
    .
    . 
}

After hitting the API the I am getting no response in POSTMAN just the empty window

enter image description here

Any help would be highly appreciated.

lin
  • 17,956
  • 4
  • 59
  • 83
Moeez
  • 494
  • 9
  • 55
  • 147
  • Can you show us the code where you handle issuing this request? – mrateb Jul 16 '18 at 11:33
  • i dont get it, how are you hitting the initial url are you opening it in the browser or send a curl request? as typing the above url inthe browser will ask you to enter the credentials for the Zoho platform, how are you getting the response that you have pasted above – Muhammad Omer Aslam Jul 16 '18 at 13:28
  • and above all have you configured the `urlManager` in your API to allow `GET` request for the current action you are redirecting to ? – Muhammad Omer Aslam Jul 16 '18 at 13:29
  • @MuhammadOmerAslam for your 1st comment. For now yes I am opening it in my browser the `client_id` and `redirect_uri` are hardcoded. After opening it in my browser a call to my `web api` is made and it returns me a response with the code in it. I want that code in my application. – Moeez Jul 16 '18 at 14:44
  • you should first implement the actual scenario what i understand is that zoho api sends a hit to `redirect_uri` provided and displays th response from that url whichever api it is? is that correct? – Muhammad Omer Aslam Jul 16 '18 at 14:52
  • @MuhammadOmerAslam yes it's correct – Moeez Jul 16 '18 at 14:54
  • you should send a curl GET request to the zoho api url with the params and then receive the response first and add the code in your question, you can use the [linslin/curl](https://github.com/linslin/Yii2-Curl) for sending the cUrl request – Muhammad Omer Aslam Jul 16 '18 at 14:57
  • @MuhammadOmerAslam I tried to access it via Postman but I got this error `Note : Javascript is disabled in your browser. Please enable the javascript to continue.` – Moeez Jul 17 '18 at 03:25
  • @MuhammadOmerAslam kindly check my `update 1` – Moeez Jul 17 '18 at 05:03
  • @MuhammadOmerAslam I am still waiting – Moeez Jul 18 '18 at 03:40
  • @mrateb I have updated my question – Moeez Jul 18 '18 at 03:40

2 Answers2

2

Its working quite fine when you enable SSL and check the response code / response header to redirect to the userAuth form on Zuhu:

$curl = new \linslin\yii2\curl\Curl();

/** @var Curl $response */
$curl->setGetParams([
        'scope' => 'ZohoBugTracker.projects.ALL,ZohoBugTracker.bugs.ALL',
        'client_id' => '1000',
        'response_type' => 'code',
        'access_type' => 'offline',
        'redirect_uri' => 'http://11.111.111.111:7000/api/oauth/zoho_auth',
])->setOption(CURLOPT_SSL_VERIFYPEER, true)
    ->setOption(CURLOPT_SSL_VERIFYHOST, false)
    ->setOption(CURLOPT_CAINFO, 'C:/Ampps/apache/conf/ssl_crt/cacert.pem')
    ->get('https://accounts.zoho.com/oauth/v2/auth');

$responseHeaders = $curl->responseHeaders;

if ($curl->responseCode === 302 && isset($responseHeaders['Location'])) {
    header("location: ".$responseHeaders['Location']);
    die();
}
lin
  • 17,956
  • 4
  • 59
  • 83
0

Have you tried this to get Error

if ($curl->errorCode === null) {
   echo $response;
} else {

    echo '<pre>';print_r($curl->errorCode);
} 
Sudharshan Nair
  • 1,152
  • 1
  • 10
  • 24
  • Yes but still empty screen – Moeez Jul 18 '18 at 15:00
  • @MrFaisal. Can you try to set `CURLOPT_FOLLOWLOCATION`. Like `curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // follow redirects curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // set referer on redirect curl_exec($ch); $target = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);` And check if any luck – Sudharshan Nair Jul 19 '18 at 04:42
  • ok before this `$response = $curl->setGetParams([ 'scope' => 'ZohoBugTracker.projects.ALL,ZohoBugTracker.bugs.ALL', 'client_id' => '1000', 'response_type' => 'code', 'access_type' => 'offline', 'redirect_uri' => 'http://11.111.111.111:7000/api/oauth/zoho_auth', ]) ->get('https://accounts.zoho.com/oauth/v2/auth');` ? – Moeez Jul 19 '18 at 05:57