APIs & Integrations

michaelbarley
Contributor

Setting Up OAuth using PHP

SOLVE

I'm following with the HubSpot Academy course: Introduction to the HubSpot APIs. 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).

 

 
       $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: 

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

});

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

 

Thanks in advance

 
0 Upvotes
1 Accepted solution
Willson
Solution
HubSpot Employee
HubSpot Employee

Setting Up OAuth using PHP

SOLVE

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: 

https://www.geeksforgeeks.org/how-to-get-parameters-from-a-url-string-in-php/

 

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...

 

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

https://github.com/HubSpot/hubspot-php/issues/147

 

I hope this helps!

Product Manager @ HubSpot

View solution in original post

Willson
Solution
HubSpot Employee
HubSpot Employee

Setting Up OAuth using PHP

SOLVE

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: 

https://www.geeksforgeeks.org/how-to-get-parameters-from-a-url-string-in-php/

 

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...

 

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

https://github.com/HubSpot/hubspot-php/issues/147

 

I hope this helps!

Product Manager @ HubSpot
michaelbarley
Contributor

Setting Up OAuth using PHP

SOLVE

Very helpful, thank you very much Matthew