1. Turn on http wire log. - How to Enable HTTP Wire Logging for HTTP Connector or Other Connectors Using HTTP Service and What Logs To Collect For API Policy Case turn on debug for package - com.mulesoft.extension.policies.
2. With debug turned on - search for the request which is failing and search for - Authorization: Bearer.
3. Authorization: Bearer is JWT token which you can decode by pasting the token here - https://jwt.io/. this will give you human readable format of the token.
e.g.,
{
"client_id": "XXXXXXXXXXXXXXXX",
"http://schemas.XXX.com/ws/2008/06/identity/claims/expiration": "15/01/2021 22:02:23",
"nbf": 1610747843,
"exp": 1610834243,
"iat": 1610747843,
"iss": "xxxx.co.uk",
"aud": "xxx.co.uk"
}
4. Analyze the logs just before application is throwing the "Invalid token" error and you will see number of statements and executions done by the package - com.mulesoft.extension.policies.
5. By looking at the JWT token details and detail logs observed at point 4, you should be able to work out the possible root cause for the failure.
[2021-01-15 21:47:31.297] DEBUG org.mule.service.http.impl.service.HttpMessageLogger.XXXXXXX-xxxx-exp-api-httpListenerConfig [http.listener.01 SelectorRunner]: LISTENER
POST /XXXXX-service-exp-api/v1/accounts/5292/renewals HTTP/1.1
X-SSL-Client-Verify: NONE
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnRfaWQiOiI4Y2IwYmM4MjMxMzc0ZDkwOWI5ZmVkYTNkYWRlNmE0NiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvZXhwaXJhdGlvbiI6IjE1LzAxLzIwMjEgMjE6NTI6NDAiLCJuYmYiOjE2MTA3NDcyNjAsImV4cCI6MTYxMDgzMzY2MCwiaWF0IjoxNjEwNzQ3MjYwLCJpc3MiOiJlbnNlay5jby51ayIsImF1ZCI6ImVuc2VrLmNvLnVrIn0.WD0xjsEAPKfJ8KJ65RsqtWLWt-J5rAYucS7j9YGPyhuYptNW5v8kyOR9AgZVOgqpbMEy_cQeHzzks9Wft_ajE46Q3I7AJciv9ORYrFWalGgofEL_JWL7J1euOfzn9U6EORoWVTtfqfQRWbns7XJcJ4flWKd0z8baXUHjlsINn1_h6MqvkkB1xhW8LDAunW7RXj7Zb8LmsN7gPY5fA35QNFVlaXwKlF1dl0iJ0PVQtdPNwXY1FsCIqyPptH4aJhZ0ToRHp3H0ewXKoJ7-7V3Kuj7UOhFQKO5IuEEtlvJ28IUPqjaOMIhumacZSWqtu5y0lk6nwkgDtkcV79FIFP7_PQ
[2021-01-15 21:47:31.322] DEBUG com.mulesoft.extension.policies.jwt.validator.claims.ClaimValidator [[MuleRuntime].uber.38: [jwt-validation-1446864-xxxx-service-exp-api-main].1446864-client-id-enforcement.CPU_INTENSIVE @53e8545d]: event:44df9770-577b-11eb-9fce-06acea3e07a0 Validating nbf claim.
[2021-01-15 21:47:31.322] DEBUG com.mulesoft.extension.policies.jwt.validator.claims.NbfClaimValidator [[MuleRuntime].uber.38: [jwt-validation-1446864-xxxx-service-exp-api-main].1446864-client-id-enforcement.CPU_INTENSIVE @53e8545d]: event:44df9770-577b-11eb-9fce-06acea3e07a0 The token is not valid yet. It will be rejected.
[2021-01-15 21:47:31.385] DEBUG org.mule.service.http.impl.service.HttpMessageLogger.xxxxx-service-exp-api-httpListenerConfig [[MuleRuntime].uber.38: [jwt-validation-1446864-bgevolve-service-exp-api-main].1446864-client-id-enforcement.CPU_INTENSIVE @53e8545d]: event:44df9770-577b-11eb-9fce-06acea3e07a0 LISTENER
HTTP/1.1 401 Unauthorized
www-authenticate: Bearer
Content-Type: application/json; charset=UTF-8
Content-Length: 31
Date: Fri, 15 Jan 2021 21:47:31 GMT
{
"error": "Invalid token."
}
If you decode this token you will see below details
{
"client_id": "8cb0bc8231374d909b9feda3dade6a46",
"http://xxx.xxx.com/ws/2008/06/identity/claims/expiration": "15/01/2021 21:52:40",
"nbf": 1610747260, ==> Friday, January 15, 2021 9:47:40 PM
"exp": 1610833660, ==> Saturday, January 16, 2021 9:47:40 PM
"iat": 1610747260, ==> Friday, January 15, 2021 9:47:40 PM
"iss": "xxxx.co.uk",
"aud": "xxxx.co.uk"
}
001120553

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.