# Revoke the access token using api okta restTemplate form batch

**URL:** <https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548>\
**Category:** Questions\
**Created:** [August 17, 2021, 10:26am UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548 "2021-08-17T10:26:51Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamedberrahal](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mohamedberrahal](https://devforum.okta.com/u/mohamedberrahal)\
**Post date:** [August 17, 2021, 10:26am UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/1 "2021-08-17T10:26:51Z")

</div>

I need to revoke token okta form batch java , using restTemplat .  
when I did the research sur okta dev , I found that must go through an API but the probleme  
i"dont have okta\_session\_cookie , what I stored in the database at the time of connection is just the access token ,I am looking for a complete process to revoke the token, my point of entry is just the access token okta,

here is what i found

 ![image](https://global.discourse-cdn.com/oktadev/original/2X/0/0893161cf93b7aff4e689fe99b744035a7a40b82.png)

```auto
 HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
    HttpEntity<?> entity = new HttpEntity(headers);
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(REVOKE_URL)
            .queryParam("token", tokenDetailsDto.getRefreshToken());
    LOGGER.info("used parameters:\n\turl={},\n\tentity={},\n\turiParameters={}", REVOKE_URL, entity);
    restTemplate.postForObject(builder.build().encode().toUri(), entity, Void.class);

```

---

<div class="post-metadata">

**Author:** ![Lijia](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/lijia/32/2295_2.png) [@Lijia](https://devforum.okta.com/u/Lijia)\
**Post date:** [August 17, 2021, 9:46pm UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/2 "2021-08-17T21:46:08Z")

</div>

@mohamedberrahal Can you pls try to test the API endpoint in postman first?

 ![image](https://global.discourse-cdn.com/oktadev/original/2X/6/6a9877ac93da25c1122ebb28be255dc591a667b7.png)

You can import Okta postman collections via the below reference:  
[https://developer.okta.com/docs/reference/postman-collections/](https://developer.okta.com/docs/reference/postman-collections/)

---

<div class="post-metadata">

**Author:** ![mohamedberrahal](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mohamedberrahal](https://devforum.okta.com/u/mohamedberrahal)\
**Post date:** [August 18, 2021, 2:31pm UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/3 "2021-08-18T14:31:06Z")

</div>

Hi Lijia,

 ![image](https://global.discourse-cdn.com/oktadev/original/2X/d/dc1b6364f0998ebed77b474feadd2eec5879e6f1.png)

---

<div class="post-metadata">

**Author:** ![mohamedberrahal](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mohamedberrahal](https://devforum.okta.com/u/mohamedberrahal)\
**Post date:** [August 18, 2021, 2:34pm UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/4 "2021-08-18T14:34:43Z")

</div>

I tried with this API too

 ![image](https://global.discourse-cdn.com/oktadev/original/2X/8/87e0fc0acf108f9e323ae70adf75c442f36c6416.png)

---

<div class="post-metadata">

**Author:** ![mohamedberrahal](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mohamedberrahal](https://devforum.okta.com/u/mohamedberrahal)\
**Post date:** [August 18, 2021, 2:58pm UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/5 "2021-08-18T14:58:02Z")

</div>

in my okta dashbord I have

 ![image](https://global.discourse-cdn.com/oktadev/original/2X/4/41caa129b25f11324f87fb2e8dcadc4bff071a46.png)

---

<div class="post-metadata">

**Author:** ![Lijia](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/lijia/32/2295_2.png) [@Lijia](https://devforum.okta.com/u/Lijia)\
**Post date:** [August 18, 2021, 7:21pm UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/6 "2021-08-18T19:21:21Z")

</div>

@mohamedberrahal Did you manually add the client id in Body? Why not add it in the authorization tab?  
What type of application you have?

---

<div class="post-metadata">

**Author:** ![mohamedberrahal](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mohamedberrahal](https://devforum.okta.com/u/mohamedberrahal)\
**Post date:** [August 18, 2021, 9:17pm UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/7 "2021-08-18T21:17:53Z")

</div>

Yes i add client id in the autorisation , bat the problem persiste

 ![image](https://global.discourse-cdn.com/oktadev/original/2X/c/ca24da26bb8acd5c54e08ed0d2ef68b74ced954b.png)

---

<div class="post-metadata">

**Author:** ![Lijia](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/lijia/32/2295_2.png) [@Lijia](https://devforum.okta.com/u/Lijia)\
**Post date:** [August 18, 2021, 9:32pm UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/8 "2021-08-18T21:32:50Z")

</div>

@mohamedberrahal It looks like your client id is not correct. Also, the two screens you attached earlier is not revoke token. One is get token and another one is delete current session.  
I suggest you to open a support ticket through an email to [support@okta.com](mailto:support@okta.com). One of our dev support engineers will help you review this API issue.

---

<div class="post-metadata">

**Author:** ![mohamedberrahal](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mohamedberrahal](https://devforum.okta.com/u/mohamedberrahal)\
**Post date:** [August 20, 2021, 10:03am UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/9 "2021-08-20T10:03:15Z")

</div>

Merci Lijia, I create new ticket in okta support 🙏 🙏 🙏

---

<div class="post-metadata">

**Author:** ![mohamedberrahal](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mohamedberrahal](https://devforum.okta.com/u/mohamedberrahal)\
**Post date:** [August 23, 2021, 9:51am UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/10 "2021-08-23T09:51:41Z")

</div>

helloo Lijia,

on okta support he asks me to go through dev forum 😓 😓

 ![image](https://global.discourse-cdn.com/oktadev/original/2X/6/6b9ea460fadecbac320b1d1ddaf23f05ce7f0d10.png)

---

<div class="post-metadata">

**Author:** ![mohamedberrahal](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mohamedberrahal](https://devforum.okta.com/u/mohamedberrahal)\
**Post date:** [August 23, 2021, 1:29pm UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/11 "2021-08-23T13:29:31Z")

</div>

@mraible do you have any idea , thank you in advance for your return

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [August 23, 2021, 1:42pm UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/12 "2021-08-23T13:42:01Z")

</div>

As far as I know, access tokens can not be revoked, they just expire. That’s why we recommend having short-lived access tokens and long-lived refresh tokens.

---

<div class="post-metadata">

**Author:** ![mohamedberrahal](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mohamedberrahal](https://devforum.okta.com/u/mohamedberrahal)\
**Post date:** [August 23, 2021, 2:53pm UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/13 "2021-08-23T14:53:54Z")

</div>

ok thank you matt I understood, in other words I can do otherwise, to delete the user session via this API [https://xxx.okta.com/api/v1/sessions/me](https://xxx.okta.com/api/v1/sessions/me) ? as an entry point the 'access token no?  
but I do not have the cookie session id, I am in a batch

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [August 23, 2021, 3:18pm UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/14 "2021-08-23T15:18:41Z")

</div>

It’s best to use our [logout API](https://developer.okta.com/docs/reference/api/oidc/#logout) when trying to end a user’s session.

We also have a guide that shows how to sign users out.

[https://developer.okta.com/docs/guides/sign-users-out/react/sign-out-of-okta/](https://developer.okta.com/docs/guides/sign-users-out/react/sign-out-of-okta/)

---

<div class="post-metadata">

**Author:** ![mohamedberrahal](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mohamedberrahal](https://devforum.okta.com/u/mohamedberrahal)\
**Post date:** [August 24, 2021, 10:26am UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/15 "2021-08-24T10:26:51Z")

</div>

Yes, I see this example bat ,I have to do this from a java batch not a fornt application (like react angular) either , and the entry point that I have is the access token and the **clientId** : **‘0oaxxxxkkgkgxxx’** , really i’m blocking, if you have a proposal , thanks in advance matt

restTemplate.exchange( …

```auto

```

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [August 24, 2021, 1:13pm UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/16 "2021-08-24T13:13:52Z")

</div>

If you don’t have a ID Token, you can’t use the guides I suggested. I’d suggest having a short-lived access token instead. It’s possible there’s another technique, but I’m not familiar with it.

---

<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:** [February 8, 2024, 7:04pm UTC](https://devforum.okta.com/t/revoke-the-access-token-using-api-okta-resttemplate-form-batch/15548/18 "2024-02-08T19:04:38Z")

</div>

Closed on February 8, 2024, 7:04pm UTC


