hubspot-php icon indicating copy to clipboard operation
hubspot-php copied to clipboard

client key to use oauth2

Open itulga opened this issue 8 years ago • 4 comments

I want to use OAuth2, but I dont understand why I need client here?

I tried to use

$oauth2 = new OAuth2();

but it gives error and I created like:

$client = new Client('key'=>'xxxxxxxx'); $oauth2 = new OAuth2($client);

Why should I use HAPIKey? I think I should directly call oauth2 with client_id and client secret is enough.

Thanks,

itulga avatar Nov 09 '18 11:11 itulga

I am also confused on this...what key do I pass in for OAuth2 the client ID?

$this->hubspot = new SevenShores\Hubspot\Factory(['key' => $credentials['client-id'], 'oauth' => $oauth], null, ['http_errors' => false], true);

rbenzing avatar Nov 12 '18 15:11 rbenzing

The client is the class responsible for doing the requests to the API, so in order to get the OAuth2 tokens you need to pass it to the OAuth2 object.

The issue is mostly a check on the construct of the client in which it specifically needs a key to proceed. This is either Hubspot API Key (hapikey) or the access token. But as you need first to ask for this access token it doesn't make much sense to ask for that key on construct.

Pryrios avatar Jun 06 '19 07:06 Pryrios

The OAuth2 Integration flows like this:

Redirect the customer to HubSpot so they can authorize your app

  • => getAuthUrl($clientId, $redirectURI, $scopesArray=array())

Assuming customer gives permission, it will redirect back into your App with a "code"

This is a one time code you can use to get the refresh token needed to access the customer data

  • => getTokensByCode($clientId, $clientSecret, $redirectURI, $tokenCode)

You will receive a refresh token (persistent) | SAVE that | It will enable you to refresh indefinitely

And now you can get your access token that will be valid for ~=8h and you can pull data on behalf of your customer

  • => getTokensByRefresh($clientId, $clientSecret, $refreshToken)

After this, just remember to get new access tokens every 8h or when you need them using the refresh token (persistent key)

The hapiKey is for when you're not interested in other customers connecting your App. You only want to connect to your own platform / company data. It's a perpetual access token.

siremi avatar Jun 06 '19 15:06 siremi

See https://github.com/HubSpot/hubspot-php/issues/147#issuecomment-550315109

atanasiuk-hubspot avatar Nov 06 '19 14:11 atanasiuk-hubspot