# Error while calling routes using oAuth2 token

**URL:** <https://discuss.konghq.com/t/error-while-calling-routes-using-oauth2-token/1476>\
**Category:** Questions\
**Created:** [July 16, 2018, 5:42am UTC](https://discuss.konghq.com/t/error-while-calling-routes-using-oauth2-token/1476 "2018-07-16T05:42:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ritesh\_Jha](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/ritesh_jha/32/1448_2.png) [@Ritesh\_Jha](https://discuss.konghq.com/u/Ritesh_Jha)\
**Post date:** [July 16, 2018, 5:42am UTC](https://discuss.konghq.com/t/error-while-calling-routes-using-oauth2-token/1476/1 "2018-07-16T05:42:48Z")

</div>

Hello,

I am using oath2 client-credential flow. I enabled oauth2 plugin at service layer but when I tried to call routes, always received below error.

> {  
> “error\_description”:“The access token is invalid or has expired”,  
> “error”:“invalid\_token”  
> }

I am sure that token is not expired since I fetched just before calling this endpoint.

For getting token:

> curl --insecure --include --request POST --header ‘Content-type: application/json’ --data ‘{“client\_id”:“hasjahdkjkHCiyrS0PTYGE2P6”,“grant\_type”: “client\_credentials”, “client\_secret” : “59skkzG0asao889asaslLAzkwLK”}’ ‘[https://localhost:8443/oauth2/token](https://localhost:8443/oauth2/token)’

For calling endpoint:

> curl --include --insecure -X GET “[https://localhost:8443/v1/pickup-locations](https://localhost:8443/v1/pickup-locations)” -H ‘Accept: application/json’ -H ‘Authorization: Bearer Npwe9eKZv9c3BHiTmV7dtPC66q2ACE7H’

Here are my settings for your reference.

> /services
> 
> {  
> “next”: null,  
> “data”: [  
> {  
> “host”: “[httpbin.org](http://httpbin.org)”,  
> “created\_at”: 1531455793,  
> “connect\_timeout”: 60000,  
> “id”: “17b6a21d-2a11-41d5-a42f-567a19c8e2fc”,  
> “protocol”: “http”,  
> “name”: “service-v1-products”,  
> “read\_timeout”: 60000,  
> “port”: 80,  
> “path”: “/v1/products”,  
> “updated\_at”: 1531714879,  
> “retries”: 2,  
> “write\_timeout”: 60000  
> },  
> {  
> “host”: “[httpbin.org](http://httpbin.org)”,  
> “created\_at”: 1531455162,  
> “connect\_timeout”: 60000,  
> “id”: “6dd03fec-a7fc-4ab2-9c0d-b2c9a7343ea5”,  
> “protocol”: “http”,  
> “name”: “service-v1-pickup-locations”,  
> “read\_timeout”: 60000,  
> “port”: 80,  
> “path”: “/v1/pickup-locations”,  
> “updated\_at”: 1531714831,  
> “retries”: 2,  
> “write\_timeout”: 60000  
> },  
> {  
> “host”: “[dummy.com](http://dummy.com)”,  
> “created\_at”: 1531538382,  
> “connect\_timeout”: 60000,  
> “id”: “a15b0bdb-7acd-42a7-b19b-13a7ccb0a875”,  
> “protocol”: “http”,  
> “name”: “oauth2-service”,  
> “read\_timeout”: 60000,  
> “port”: 80,  
> “path”: null,  
> “updated\_at”: 1531538382,  
> “retries”: 5,  
> “write\_timeout”: 60000  
> }  
> ]  
> }
> 
> /plugins
> 
> {  
> “total”: 3,  
> “data”: [  
> {  
> “created\_at”: 1531538421000,  
> “config”: {  
> “refresh\_token\_ttl”: 1209600,  
> “enable\_client\_credentials”: true,  
> “mandatory\_scope”: false,  
> “hide\_credentials”: false,  
> “token\_expiration”: 7200,  
> “enable\_implicit\_grant”: false,  
> “global\_credentials”: true,  
> “accept\_http\_if\_already\_terminated”: false,  
> “enable\_password\_grant”: false,  
> “anonymous”: “”,  
> “enable\_authorization\_code”: false,  
> “provision\_key”: “IzsmxYISTlNDbIiPezgkMjTPt4HUdWFF”,  
> “auth\_header\_name”: “authorization”  
> },  
> “id”: “947371cd-c851-4458-a767-c41e4f166e63”,  
> “name”: “oauth2”,  
> “service\_id”: “a15b0bdb-7acd-42a7-b19b-13a7ccb0a875”,  
> “enabled”: true  
> },  
> {  
> “created\_at”: 1531715358000,  
> “config”: {  
> “refresh\_token\_ttl”: 1209600,  
> “scopes”: [  
> “read:pickup-location”  
> ],  
> “mandatory\_scope”: false,  
> “provision\_key”: “SHQHskX3WbhAAH8ym2irMYO782WkYk74”,  
> “hide\_credentials”: false,  
> “token\_expiration”: 3600,  
> “enable\_implicit\_grant”: false,  
> “global\_credentials”: false,  
> “anonymous”: “”,  
> “enable\_password\_grant”: false,  
> “enable\_client\_credentials”: true,  
> “enable\_authorization\_code”: false,  
> “accept\_http\_if\_already\_terminated”: false,  
> “auth\_header\_name”: “authorization”  
> },  
> “id”: “59f4a238-4a2f-4848-a15d-ec7c28141fa2”,  
> “name”: “oauth2”,  
> “service\_id”: “6dd03fec-a7fc-4ab2-9c0d-b2c9a7343ea5”,  
> “enabled”: true  
> },  
> {  
> “created\_at”: 1531715462000,  
> “config”: {  
> “refresh\_token\_ttl”: 1209600,  
> “scopes”: [  
> “read:product”,  
> “read:stock-lot”,  
> “write:stock-lot”  
> ],  
> “mandatory\_scope”: false,  
> “provision\_key”: “MVyY5Fip9tAFDTp520uluyV8LXDa4JfP”,  
> “hide\_credentials”: false,  
> “token\_expiration”: 3600,  
> “enable\_implicit\_grant”: false,  
> “global\_credentials”: false,  
> “anonymous”: “”,  
> “enable\_password\_grant”: false,  
> “enable\_client\_credentials”: true,  
> “enable\_authorization\_code”: false,  
> “accept\_http\_if\_already\_terminated”: false,  
> “auth\_header\_name”: “authorization”  
> },  
> “id”: “159e67f5-3a6e-4fff-858f-dd93958e7ce8”,  
> “name”: “oauth2”,  
> “service\_id”: “17b6a21d-2a11-41d5-a42f-567a19c8e2fc”,  
> “enabled”: true  
> }  
> ]  
> }
> 
> /routes
> 
> {  
> “next”: null,  
> “data”: [  
> {  
> “created\_at”: 1531464055,  
> “strip\_path”: true,  
> “hosts”: null,  
> “preserve\_host”: false,  
> “regex\_priority”: 0,  
> “updated\_at”: 1531505499,  
> “paths”: [  
> “/v1/pickup-locations”  
> ],  
> “service”: {  
> “id”: “6dd03fec-a7fc-4ab2-9c0d-b2c9a7343ea5”  
> },  
> “methods”: [  
> “GET”  
> ],  
> “protocols”: [  
> “https”  
> ],  
> “id”: “1346d2bd-5f9c-402d-83e7-1aefb6ef4e02”  
> },  
> {  
> “created\_at”: 1531464292,  
> “strip\_path”: true,  
> “hosts”: null,  
> “preserve\_host”: false,  
> “regex\_priority”: 0,  
> “updated\_at”: 1531464292,  
> “paths”: [  
> “/v1/products”  
> ],  
> “service”: {  
> “id”: “17b6a21d-2a11-41d5-a42f-567a19c8e2fc”  
> },  
> “methods”: [  
> “GET”,  
> “PATCH”  
> ],  
> “protocols”: [  
> “https”  
> ],  
> “id”: “1f341261-ba0a-42ea-8425-ec604b354d6f”  
> },  
> {  
> “created\_at”: 1531538450,  
> “strip\_path”: true,  
> “hosts”: null,  
> “preserve\_host”: false,  
> “regex\_priority”: 0,  
> “updated\_at”: 1531538450,  
> “paths”: [  
> “/oauth2/token”  
> ],  
> “service”: {  
> “id”: “a15b0bdb-7acd-42a7-b19b-13a7ccb0a875”  
> },  
> “methods”: null,  
> “protocols”: [  
> “http”,  
> “https”  
> ],  
> “id”: “54a20ada-27c2-4d1c-8826-db00cf1c78d4”  
> }  
> ]  
> }

---

<div class="post-metadata">

**Author:** ![Ritesh\_Jha](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/ritesh_jha/32/1448_2.png) [@Ritesh\_Jha](https://discuss.konghq.com/u/Ritesh_Jha)\
**Post date:** [July 16, 2018, 1:41pm UTC](https://discuss.konghq.com/t/error-while-calling-routes-using-oauth2-token/1476/2 "2018-07-16T13:41:29Z")

</div>

Ignore my above query. I found reason.

---

<div class="post-metadata">

**Author:** ![prathima](https://avatars.discourse-cdn.com/v4/letter/p/edb3f5/32.png) [@prathima](https://discuss.konghq.com/u/prathima)\
**Post date:** [March 13, 2020, 4:44am UTC](https://discuss.konghq.com/t/error-while-calling-routes-using-oauth2-token/1476/3 "2020-03-13T04:44:49Z")

</div>

Hello, could you explain what solved the issue? I’m facing the same currently. It would be of great help.

---

<div class="post-metadata">

**Author:** ![Sachin\_Ghumbre](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/sachin_ghumbre/32/2737_2.png) [@Sachin\_Ghumbre](https://discuss.konghq.com/u/Sachin_Ghumbre)\
**Post date:** [May 25, 2022, 1:01pm UTC](https://discuss.konghq.com/t/error-while-calling-routes-using-oauth2-token/1476/4 "2022-05-25T13:01:48Z")

</div>

please tell us the solution as others get benefited
