# How to implement access\_token generation via rest api

**URL:** <https://devforum.okta.com/t/how-to-implement-access-token-generation-via-rest-api/296>\
**Category:** OAuth/OIDC\
**Created:** [August 1, 2017, 3:33pm UTC](https://devforum.okta.com/t/how-to-implement-access-token-generation-via-rest-api/296 "2017-08-01T15:33:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JustinPihony](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@JustinPihony](https://devforum.okta.com/u/JustinPihony)\
**Post date:** [August 1, 2017, 3:33pm UTC](https://devforum.okta.com/t/how-to-implement-access-token-generation-via-rest-api/296/1 "2017-08-01T15:33:21Z")

</div>

Hi,

I am finishing migrating our code from Stormpath, but am having a problem with generating an access token as I had done previously. As far as I can tell, I should be able to call oauth2/v1/authorize with a sessionToken retrieved from the authn API. The problem is that no matter what I’m entering I get a 404 currently.

Here is what my longest string looks like - any help would be appreciated:

[https://MYORG.oktapreview.com/oauth2/v1/authorize?response\_type=token&client\_id=MYCLIENTID&scope=offline\_access&response\_mode=query&sessionToken=MYSESSIONTOKEN&state=foo&nonce=bar](https://MYORG.oktapreview.com/oauth2/v1/authorize?response_type=token&client_id=MYCLIENTID&scope=offline_access&response_mode=query&sessionToken=MYSESSIONTOKEN&state=foo&nonce=bar)

Note that in Stormpath I could just make a call and get the token back. I realize that I might need to parse some data that isn’t json, but that’s fine with me…how do I do this? I’ve spent quite a bit of time on this already and feel like I’m running in circles.

Thanks,  
Justin

\*I have looked at the other questions based on this, but they have not proven to be helpful.

---

<div class="post-metadata">

**Author:** ![JustinPihony](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@JustinPihony](https://devforum.okta.com/u/JustinPihony)\
**Post date:** [August 1, 2017, 3:49pm UTC](https://devforum.okta.com/t/how-to-implement-access-token-generation-via-rest-api/296/2 "2017-08-01T15:49:31Z")

</div>

Per [this response](https://devforum.okta.com/t/we-are-using-okta-openid-connect-rest-api-for-authentication-when-i-call-oauth2-v1-authorize-with-session-token-client-id-and-other-parameters-i-am-getting-html-form-as-response-with-token-and-other-response-parameters-as-hidden-fields/279/2) I should use the token api, and not authorize since I am doing this all in backend. The problem is that I have tried that one also, and cannot authenticate. If I use SSWS and pass in client\_id then I’m still prompted for a username/password (which still doesn’t seem to work):

POST /oauth2/v1/token HTTP/1.1  
Host: [MYORG.oktapreview.com](http://MYORG.oktapreview.com)  
Authorization: SSWS MYTOKEN  
Accept: application/json  
Content-Type: application/x-www-form-urlencoded  
Cache-Control: no-cache

grant\_type=password&username=URLENCODEDUSER&password=PASSWORD&scope=[offline\_access]&client\_id=MYCLIENTID&client\_secret=MYCLIENTSECRET

And if I try to remove client\_id and secret, Base64ing MYCLIENTID:MYCLIENTSECRET and using Basic BASE64OUTPUT then I get an automatic failure

---

<div class="post-metadata">

**Author:** ![mort](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mort](https://devforum.okta.com/u/mort)\
**Post date:** [August 14, 2017, 2:59am UTC](https://devforum.okta.com/t/how-to-implement-access-token-generation-via-rest-api/296/3 "2017-08-14T02:59:21Z")

</div>

JustinPihony, Did you ever get this to work? I’m struggling with the same. Thanks!

---

<div class="post-metadata">

**Author:** ![JustinPihony](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@JustinPihony](https://devforum.okta.com/u/JustinPihony)\
**Post date:** [August 15, 2017, 12:45am UTC](https://devforum.okta.com/t/how-to-implement-access-token-generation-via-rest-api/296/4 "2017-08-15T00:45:44Z")

</div>

Hi @mort

Yes I was able to solve it in my case by setting the Access Policy to “All Clients”. If you need specifics let me know.

-Justin

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [January 12, 2024, 7:14pm UTC](https://devforum.okta.com/t/how-to-implement-access-token-generation-via-rest-api/296/5 "2024-01-12T19:14:42Z")

</div>

Closed on January 12, 2024, 7:14pm UTC


