# Setting Up OAuth using PHP

**URL:** <https://community.hubspot.com/t/setting-up-oauth-using-php/18607>\
**Category:** APIs & Integrations\
**Tags:** oauth\
**Created:** [February 6, 2020, 3:03pm UTC](https://community.hubspot.com/t/setting-up-oauth-using-php/18607 "2020-02-06T15:03:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelbarley](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/michaelbarley/32/94419_2.png) [@michaelbarley](https://community.hubspot.com/u/michaelbarley)\
**Post date:** [February 6, 2020, 3:03pm UTC](https://community.hubspot.com/t/setting-up-oauth-using-php/18607/1 "2020-02-06T15:03:40Z")

</div>

I’m following with the HubSpot Academy course: Introduction to the [HubSpot APIs](https://app.hubspot.com/academy/7054015/tracks/71/593/2968). Im on to the Using OAuth with HubSpot part.

I’m working my way through the OAuth flow, but having difficulty as the course is written using NodeJs and im a little bit confused when trying to work with PHP.

I have succesfully managed to send the user to the authentication page (part 1/4).

```auto
 $hubSpot = new HubSpotIntegration();
 if($hubSpot->isAuthorized()) {
 echo "Authorised";
 } else {
 echo "OAuth URL link...";
 }

```

I’m not quite sure how I perform step 2: ‘Get temparary authorisation code from server’.

I have set up a route for when a user goes to my redirect URL which looks like this:

```auto
SimpleRouter::get('/hubspot-api-oauth-callback', function () {

});

```

but I’m unsure how I grab the data the server is sending.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Willson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/willson/32/84663_2.png) [@Willson](https://community.hubspot.com/u/Willson)\
**Post date:** [February 6, 2020, 4:01pm UTC](https://community.hubspot.com/t/setting-up-oauth-using-php/18607/2 "2020-02-06T16:01:34Z")

</div>

Hi @michaelbarley

Unfortunately I would not be the best resource when it comes to navigating this via PHP but the step you’re referring to is in relation to the `code` which is passed as a URL parameter after the user has authenticated the integration.

When the OAuth URL is accessed, this will prompt the integration user to login to their portal and confirm the scope access, once this is done, the redirect will occur to the `redirct_uri` which will have the `code` appended to it. This will then need to be captured and used as part of the data in the request for the access and refresh tokens.

This could be captured by using something along the lines of:

> **[How to get parameters from a URL string in PHP? - GeeksforGeeks](https://www.geeksforgeeks.org/php/how-to-get-parameters-from-a-url-string-in-php/)**
>
> Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and...

For further assistance, I was able to find this thread that may assist:

[https://community.hubspot.com/t5/APIs-Integrations/Oauth-2-get-authorisation-code-from-php-curl/td-p/234529](https://community.hubspot.com/t5/APIs-Integrations/Oauth-2-get-authorisation-code-from-php-curl/td-p/234529)

Further to the above, I was able to find this resource for you:

> <https://github.com/HubSpot/hubspot-php/issues/147>
>
> Can you provide example code on how to use the library to authorize an app and r…efresh tokens using Oauth2?
> 
> Thanks.

I hope this helps!

---

<div class="post-metadata">

**Author:** ![michaelbarley](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/michaelbarley/32/94419_2.png) [@michaelbarley](https://community.hubspot.com/u/michaelbarley)\
**Post date:** [February 7, 2020, 8:03am UTC](https://community.hubspot.com/t/setting-up-oauth-using-php/18607/3 "2020-02-07T08:03:14Z")

</div>

Very helpful, thank you very much Matthew
