# Retrieve Okta User On Backend

**URL:** <https://devforum.okta.com/t/retrieve-okta-user-on-backend/12996>\
**Category:** Questions\
**Created:** [February 19, 2021, 4:03am UTC](https://devforum.okta.com/t/retrieve-okta-user-on-backend/12996 "2021-02-19T04:03:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucas88](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@lucas88](https://devforum.okta.com/u/lucas88)\
**Post date:** [February 19, 2021, 4:03am UTC](https://devforum.okta.com/t/retrieve-okta-user-on-backend/12996/1 "2021-02-19T04:03:28Z")

</div>

I have a problem. I use okta for my app login but I wanna try to use it for manage the users directly on the app. For this, I like to connect on okta and show all users. But, the client credentials doesn’t work. My frontend call my backend like localhost:8080/users or localhost:8080/users/id to see some specific but nothing works. I’ve tried to use this:

Client client = Clients.builder()  
.setOrgUrl(“https://{yourOktaDomain}”) // e.g. [https://dev-123456.okta.com](https://dev-123456.okta.com)  
.setAuthorizationMode(AuthorizationMode.PRIVATE\_KEY)  
.setClientId("{clientId}")  
.setScopes(new HashSet\<\>(Arrays.asList(“okta.users.read”, “okta.apps.read”)))  
.setPrivateKey("/path/to/yourPrivateKey.pem")  
.build();

or

Client client = Clients.builder()  
.setOrgUrl(“https://{yourOktaDomain}”) // e.g. [https://dev-123456.okta.com](https://dev-123456.okta.com)  
.setClientCredentials(new TokenClientCredentials("{apiToken}"))  
.build();

but the info that they expect I don’t have or it’s impracticable.  
Thanks for helping

---

<div class="post-metadata">

**Author:** ![Cale](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/cale/32/2496_2.png) [@Cale](https://devforum.okta.com/u/Cale)\
**Post date:** [February 19, 2021, 3:28pm UTC](https://devforum.okta.com/t/retrieve-okta-user-on-backend/12996/2 "2021-02-19T15:28:15Z")

</div>

Hi there @lucas88. Can you provide any more specifics on the error(s) you’re encountering?

Also, make sure your apiToken has not expired - you can check this at Security → API → Tokens in your Okta dashboard.

---

<div class="post-metadata">

**Author:** ![lucas88](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@lucas88](https://devforum.okta.com/u/lucas88)\
**Post date:** [February 19, 2021, 4:03pm UTC](https://devforum.okta.com/t/retrieve-okta-user-on-backend/12996/3 "2021-02-19T16:03:45Z")

</div>

So,

I don’t wanna use an API Token. There is a way to retrieve the list of users or create or delete or update a user with client\_id and client\_secret? Or pretty much any data already exists…  
Or the unique way is using the API Token? I read a lot of content, gathering information, but nothing helps… I thought about using a PEM certificate but I think it’s complex too.  
My piece of code:

```auto
return oktaUserMapper.toDto(oktaClient.getUser(userEmail));

```

the oktaClient. How do I initiate it?

---

<div class="post-metadata">

**Author:** ![Cale](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/cale/32/2496_2.png) [@Cale](https://devforum.okta.com/u/Cale)\
**Post date:** [February 19, 2021, 5:22pm UTC](https://devforum.okta.com/t/retrieve-okta-user-on-backend/12996/4 "2021-02-19T17:22:47Z")

</div>

Gotcha! Unfortunately you will not be able achieve this flow solely with a client ID and secret. If you don’t want to go the api token route then the other constructor you posted is the only alternate option. Take a look at this thread here for more discussion on this as well as a guide to help you create your PEM file:

> <https://github.com/okta/okta-sdk-java/issues/424>
>
> After reading your document, I can't understand how to build a client with oauth2, It confuses me that "pathToYourPrivateKeyPemFile", becaust in...

---

<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:** [January 26, 2024, 11:40pm UTC](https://devforum.okta.com/t/retrieve-okta-user-on-backend/12996/5 "2024-01-26T23:40:40Z")

</div>

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