Error while calling routes using oAuth2 token

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

For calling endpoint:

curl --include --insecure -X GET “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”,
“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”,
“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”,
“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”
}
]
}

Ignore my above query. I found reason.

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

please tell us the solution as others get benefited