# OAuth 2.0 code grant

**URL:** <https://community.hubspot.com/t/oauth-2-0-code-grant/31894>\
**Category:** APIs & Integrations\
**Tags:** free\
**Created:** [February 17, 2021, 6:48am UTC](https://community.hubspot.com/t/oauth-2-0-code-grant/31894 "2021-02-17T06:48:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ldandelion](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ldandelion/32/5125_2.png) [@ldandelion](https://community.hubspot.com/u/ldandelion)\
**Post date:** [February 17, 2021, 6:48am UTC](https://community.hubspot.com/t/oauth-2-0-code-grant/31894/1 "2021-02-17T06:48:35Z")

</div>

i tried to integrate hubspot with my app , i used OAuth2.0 , while trying to authorize for first time im geting this available apps to connect ,selecting one took me to a page with connect app /cancel option ,if i click “connect App” im getting the code in my redirect url as expected , but when i do the integration once again,before clicking the “connect app” button the app is redirecting the code without me granting access,(i.e just choosing the available app link,redirection happens).

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [February 17, 2021, 10:08pm UTC](https://community.hubspot.com/t/oauth-2-0-code-grant/31894/2 "2021-02-17T22:08:48Z")

</div>

Hey @ldandelion

Why would you do it again? What happens when you disconnect the app and go through the auth process again?

@JZhao , what do you think 😀

---

<div class="post-metadata">

**Author:** ![ldandelion](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ldandelion/32/5125_2.png) [@ldandelion](https://community.hubspot.com/u/ldandelion)\
**Post date:** [February 19, 2021, 6:57am UTC](https://community.hubspot.com/t/oauth-2-0-code-grant/31894/3 "2021-02-19T06:57:39Z")

</div>

“Why would you do it again?” : we had to multiple integrations if needed, to do so we had to authorize again.

“What happens when you disconnect the app and go through the auth process again?” : it asks for consent for the first time , afterwards it is automatically sending auth code to redireted url.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [February 19, 2021, 4:38pm UTC](https://community.hubspot.com/t/oauth-2-0-code-grant/31894/4 "2021-02-19T16:38:13Z")

</div>

@MichaelC how would you deal with this?

---

<div class="post-metadata">

**Author:** ![MichaelC](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/michaelc/32/9055_2.png) [@MichaelC](https://community.hubspot.com/u/MichaelC)\
**Post date:** [February 19, 2021, 4:49pm UTC](https://community.hubspot.com/t/oauth-2-0-code-grant/31894/5 "2021-02-19T16:49:43Z")

</div>

@ldandelion @dennisedson

Im not sure that you are authenticating correctly.

This is how it should work:

1. You send a request with your client id, scopes, redirect uri and so and - you have done this part - check!

2. You will recieve an authentication code (showing as ?code=xxx in your adress bar) - check!

This code is only valid during this specific request - one time only - can not be reused - its only purpose is to use the code to send it to recieve an access token.

3. You send code you reiceved in step 2 - and you will get back an authentication token AND a refresh token - save these in your database.

4. Your authentication token is valid for a limited amount of time - in order to get a new one you can either go back to step 1 above - or request a new token (without user having to sign in) with the refresh token.

Are you used to working with oauth2 since before? Else I would advice you to read up on everything here:

> **[Working with OAuth | OAuth Quickstart Guide - HubSpot docs](https://developers.hubspot.com/docs/apps/legacy-apps/authentication/oauth-quickstart-guide)**
>
> Learn how set up OAuth for your app using this quickstart Guide and sample Node.js app.
