# The github java sample fails with a 401 while obtaining a token

**URL:** <https://devforum.okta.com/t/the-github-java-sample-fails-with-a-401-while-obtaining-a-token/13083>\
**Category:** Questions\
**Created:** [February 25, 2021, 3:00pm UTC](https://devforum.okta.com/t/the-github-java-sample-fails-with-a-401-while-obtaining-a-token/13083 "2021-02-25T15:00:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gishu](https://avatars.discourse-cdn.com/v4/letter/g/50afbb/32.png) [@gishu](https://devforum.okta.com/u/gishu)\
**Post date:** [February 25, 2021, 3:00pm UTC](https://devforum.okta.com/t/the-github-java-sample-fails-with-a-401-while-obtaining-a-token/13083/1 "2021-02-25T15:00:19Z")

</div>

I am following the [Quickstart](https://developer.okta.com/docs/guides/quickstart/cli/register-app/)  
and the [Java spring boot sample](https://github.com/okta/samples-java-spring)

I have created an Okta client and followed the instructions - except i had to set login redirect uri =  
**[http://localhost:8080](http://localhost:8080)** (as opposed to [http://localhost:8080/login/callback](http://localhost:8080/login/callback))  
I have set the environment variables as follows:

Front End:  
okta.oauth2.issuer={my\_url};okta.oauth2.client-id={my\_client\_id}

Resource Server:  
okta.oauth2.issuer={my\_url}

Client configuration:

- AppType=Web,
- AuthCode grant type is checked
- User Consent is checked
- All uris set to http:/localhost:8080 - the FrontEnd url

Started both apps. When I enter my credentials and hit sign in.

[https://dev-xxx.okta.com/oauth2/default/v1/token](https://dev-xxx.okta.com/oauth2/default/v1/token) fails with  
401  
{“error”:“invalid\_client”,“error\_description”:“Client authentication failed. Either the client or the client credentials are invalid.”}

I have verified that the client-id is correct but cannot find the location where the /token call is made from. It looks like the auth\_code grant type is being used.

---

<div class="post-metadata">

**Author:** ![gishu](https://avatars.discourse-cdn.com/v4/letter/g/50afbb/32.png) [@gishu](https://devforum.okta.com/u/gishu)\
**Post date:** [March 4, 2021, 10:19am UTC](https://devforum.okta.com/t/the-github-java-sample-fails-with-a-401-while-obtaining-a-token/13083/2 "2021-03-04T10:19:13Z")

</div>

Bump.  
Can someone try out this sample and see if they can get it to work?

---

<div class="post-metadata">

**Author:** ![Fuzzard](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/fuzzard/32/1909_2.png) [@Fuzzard](https://devforum.okta.com/u/Fuzzard)\
**Post date:** [March 4, 2021, 6:14pm UTC](https://devforum.okta.com/t/the-github-java-sample-fails-with-a-401-while-obtaining-a-token/13083/3 "2021-03-04T18:14:53Z")

</div>

have you verified that the client secret is correct? there is no mention of this being set in your post

---

<div class="post-metadata">

**Author:** ![gishu](https://avatars.discourse-cdn.com/v4/letter/g/50afbb/32.png) [@gishu](https://devforum.okta.com/u/gishu)\
**Post date:** [March 5, 2021, 11:34am UTC](https://devforum.okta.com/t/the-github-java-sample-fails-with-a-401-while-obtaining-a-token/13083/4 "2021-03-05T11:34:14Z")

</div>

[Readme](https://github.com/okta/samples-java-spring/tree/master/front-end)  
The repo instructions do not mention setting the client-secret.

I see that the /v1/token request is made from within [global.oktacdn.com/okta-signin-widget/5.2.0/js/okta-sign-in.min.js](http://global.oktacdn.com/okta-signin-widget/5.2.0/js/okta-sign-in.min.js)  
It doesn’t seem to be passing the client-secret, which I believe is required to exchange the auth\_code for a token. Correct?  
Form Data contains [client\_id, redirect\_uri, grant\_type=authorization\_code, code\_verifier, code]

I tried setting another environment variable for the client-secret (on the frontend). No change - still fails with a 401.

---

<div class="post-metadata">

**Author:** ![akrishnakumar](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@akrishnakumar](https://devforum.okta.com/u/akrishnakumar)\
**Post date:** [March 5, 2021, 2:45pm UTC](https://devforum.okta.com/t/the-github-java-sample-fails-with-a-401-while-obtaining-a-token/13083/5 "2021-03-05T14:45:45Z")

</div>

Create a “SPA” application type as mentioned in the prerequisites [here](https://github.com/okta/samples-java-spring/tree/master/front-end#prerequisites) and try out the example.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [March 8, 2021, 2:41pm UTC](https://devforum.okta.com/t/the-github-java-sample-fails-with-a-401-while-obtaining-a-token/13083/6 "2021-03-08T14:41:54Z")

</div>

Closed on March 8, 2021, 2:41pm UTC

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
