Read redirect url to get authrisation code

Hi folks,

In the backend, I am trying to send HTTP request to generating Zoom authrisation code. Then, I would like to read redirect url to get authrisation code. How can I achieve this by PHP/Symfony, what class/service I should use to read redirect url body?

Example:

  1. I send this HTTP request “zoom.us.oauth.authorize?response_type=code&client_id=xxxxxxxxxx&redirect_uri=http://localhost:8000/
  2. The above request should redirect the request with authorisation code (localhost:8000/?code=xxxxxxx, Then I want to read/get the value of code.

Attempts:

  1. When I copy the url (Error - Zoom…) in the browser, I get redirect with authorisation code, but I need to achieve this programmatically not manually.
  2. I use PHP HttpClient class like:
    $client = HttpClient::create();
    $response = $client->request(‘GET’, $urlTK);
    $code = $response->getInfo(‘code’);

But I get $code = null

Any thought?

To achieve the task of sending an HTTP request to generate a Zoom authorization code and then reading the redirect URL to get the authorization code in PHP/Symfony, you can use the Symfony HttpClient component.

Here’s an example code snippet to achieve this:
use Symfony\Component\HttpClient\HttpClient;

// Create an HTTP client instance
$client = HttpClient::create();

// Set the URL for the initial authorization request
$url = ‘https://zoom.us/oauth/authorize?response_type=code&client_id=xxxxxxxxxx&redirect_uri=http://localhost:8000/’;

// Send the initial authorization request
$response = $client->request(‘GET’, $url);

// Get the redirect URL from the response
$redirectUrl = $response->getInfo(‘redirect_url’);

// Parse the redirect URL to get the authorization code
$code = ‘’;
parse_str(parse_url($redirectUrl, PHP_URL_QUERY), $query);
if (isset($query[‘code’])) {
$code = $query[‘code’];
}

// Use the authorization code to get an access token from Zoom
// …
In the above code, we create an HTTP client instance using the HttpClient::create() method. Then, we set the URL for the initial authorization request and send it using the request() method of the client instance.

After sending the initial authorization request, we get the redirect URL from the response using the getInfo() method. We then parse the redirect URL to get the authorization code using the parse_str() function.

Finally, we can use the authorization code to get an access token from Zoom.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.