# Generate OAuth 2.0 Access Token Programatically

**URL:** <https://community.hubspot.com/t/generate-oauth-2-0-access-token-programatically/11359>\
**Category:** APIs & Integrations\
**Tags:** oauth\
**Created:** [October 15, 2018, 8:49pm UTC](https://community.hubspot.com/t/generate-oauth-2-0-access-token-programatically/11359 "2018-10-15T20:49:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![galenweber](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/galenweber/32/102945_2.png) [@galenweber](https://community.hubspot.com/u/galenweber)\
**Post date:** [October 15, 2018, 8:49pm UTC](https://community.hubspot.com/t/generate-oauth-2-0-access-token-programatically/11359/1 "2018-10-15T20:49:20Z")

</div>

I would like to add an event on a user’s timeline whenever the complete our registration flow (ie. “User completed registration”). As per the documentation, this requires an OAuth token.

Because **we** are adding the event to _our_ user’s timeline when they register, **we** would be the “user” going through the OAuth process to grant the access token. Since we would like to this automatically, my question is:

**How can we generate an OAuth 2.0 access token programmatically?** (without any user input).

This question appears to have been asked here: [“HubSpot Access Token”](https://integrate.hubspot.com/t/hubspot-access-token/8159/7), but without a concrete response. [This post](https://integrate.hubspot.com/t/oauth-2-get-authorisation-code-from-php-curl/4676/3) seems to suggest that the access token _cannot_ be generated programmatically, but that would surprise me.

Thanks,  
Galen

---

<div class="post-metadata">

**Author:** ![Karthick\_Shiva](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/karthick_shiva/32/97852_2.png) [@Karthick\_Shiva](https://community.hubspot.com/u/Karthick_Shiva)\
**Post date:** [October 16, 2018, 11:02am UTC](https://community.hubspot.com/t/generate-oauth-2-0-access-token-programatically/11359/2 "2018-10-16T11:02:59Z")

</div>

Create a refresh token manually once and store it. Use that refresh token to generate access token programmatically every time.

![]() [developers.hubspot.com](https://developers.hubspot.com/docs/methods/oauth2/get-access-and-refresh-tokens)

### [Get OAuth 2.0 Access Token and Refresh Tokens](https://developers.hubspot.com/docs/methods/oauth2/get-access-and-refresh-tokens)

POST /oauth/v1/token

---

<div class="post-metadata">

**Author:** ![cbarley](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cbarley/32/82559_2.png) [@cbarley](https://community.hubspot.com/u/cbarley)\
**Post date:** [November 1, 2018, 11:24pm UTC](https://community.hubspot.com/t/generate-oauth-2-0-access-token-programatically/11359/3 "2018-11-01T23:24:41Z")

</div>

Hey @galenweber [@Karthick\_Shiva](https://community.hubspot.com/u/karthick_shiva) , thanks for jumping in here Karthick! We just published a doc that links to a github repo mainly for getting one up and running quickly with Oauth, but also inherently shows how one would programmatically generate access tokens etc. I’d recommend checking out the article here: [Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/methods/oauth2/oauth2-quickstart) and the app which is written in Node.js here: [GitHub - HubSpot/oauth-quickstart-nodejs: A Node JS app to get up and running with the HubSpot API using OAuth 2.0 · GitHub](https://github.com/HubSpot/oauth-quickstart-nodejs). Note: this doesn’t mean there will be 0 user input -- somebody _must_ confirm your app being installed into their portal, but this takes out much of the legwork that OAuth 2.0 requires. Hope you find it useful  
 ![slight_smile.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/3/33fb2a14544119c2351fe774141779702299e6a6.png)
