I'm trying to implement JWT validation as demonstrated in this video.
To achieve this I've implemented the following policies:
<policies>
<inbound>
<validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="No auth" require-expiration-time="false" require-signed-tokens="false">
<issuer-signing-keys>
<key> base64key </key>
</issuer-signing-keys>
</validate-jwt>
<return-response>
<set-status code="200" reason="OK" />
<set-body>test</set-body>
</return-response>
<base />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
require-signed-tokens and require-expiration-time will be enabled in production - I was trying to disable as much validation as i could just to get this running.
Then on JWT.io I'm generating a token:
Then it's time to get some data from the API:
import urllib.request
headers = {"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNTM0MDAzOTk4In0.0DlazlR4-InCb-m0dBs-9BbPbyvu5s7Opr8uXIUaMdA"}
api_request = urllib.request.Request("https://someapi", headers=headers)
try:
api_response = urllib.request.urlopen(api_request)
print(api_response.read())
except urllib.error.HTTPError as e:
print(e.read())
Note that there is no Ocp-Apim-Subscription-Key header as the product containing the API doesn't require a subscription, thou I've also tested it with one. And the result:
b'{ "statusCode": 401, "message": "No auth" }'
API request trace doesn't provide any useful information.
Is there anything obvious that I'm missing?
<key> base64key </key>
– jps