# Read redirect url to get authrisation code

**URL:** <https://devforum.zoom.us/t/read-redirect-url-to-get-authrisation-code/86192>\
**Category:** Web\
**Tags:** api\
**Created:** [April 6, 2023, 10:40am UTC](https://devforum.zoom.us/t/read-redirect-url-to-get-authrisation-code/86192 "2023-04-06T10:40:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibrahimsabat](https://avatars.discourse-cdn.com/v4/letter/i/f07891/32.png) [@ibrahimsabat](https://devforum.zoom.us/u/ibrahimsabat)\
**Post date:** [April 6, 2023, 10:40am UTC](https://devforum.zoom.us/t/read-redirect-url-to-get-authrisation-code/86192/1 "2023-04-06T10:40:41Z")

</div>

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/](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](https://zoom.us/oauth/authorize)…) 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?

---

<div class="post-metadata">

**Author:** ![jamalkhan354055](https://avatars.discourse-cdn.com/v4/letter/j/b5ac83/32.png) [@jamalkhan354055](https://devforum.zoom.us/u/jamalkhan354055)\
**Post date:** [April 13, 2023, 1:21pm UTC](https://devforum.zoom.us/t/read-redirect-url-to-get-authrisation-code/86192/2 "2023-04-13T13:21:13Z")

</div>

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/](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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [May 13, 2023, 11:21pm UTC](https://devforum.zoom.us/t/read-redirect-url-to-get-authrisation-code/86192/3 "2023-05-13T23:21:44Z")

</div>

Closed on May 13, 2023, 11:21pm UTC

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