Hello sneha s,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you are in need to know how you can specify the x and y values of a ES256 JWK inside issuer-signing-key of validate-jwt in azure APIM.
I can see that in your statement, you are trying to use the JSON Web Key Set (JWKS) method to validate an ES256 (Elliptic Curve) JWT inside the validate-jwt
policy of Azure API Management (APIM). Your approach indicates that you are trying to directly pass a JWK key into APIM which is not going to work.
Since, concatenating x, y, and crv with Base64 encoding is not valid for EC keys in APIM. Instead, use a PEM-formatted EC public key to resolve the SymmetricSecurityKey error and enable ES256 validation. Also, Azure APIM's validate-jwt policy does not natively support EC JWK parameters but can validate ES256 signatures with PEM-formatted keys.
So, you do not need to encode x, y, and crv directly (via concatenation or JWK JSON). Azure APIM’s validate-jwt policy only supports PEM-formatted EC keys for ES256 validation. The PEM approach is the only valid method because it ensures APIM recognizes the key as asymmetric (EC), resolving the SymmetricSecurityKey error and enabling proper signature validation. You can try to use a library to convert your JWK to PEM, and avoid workarounds that rely on APIM magically parsing non-standard formats.
Examples of how to do it, are the followings:
- You can use Python’s
cryptography
library to convert your JWK into PEM format.from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives import serialization import base64 # Example JWK (Replace these values with your actual ones) jwk = { "kty": "EC", "kid": "kid_value", "use": "sig", "alg": "ES256", "x": "x_value", # Base64 URL-encoded "y": "y_value", # Base64 URL-encoded "crv": "P-256" } # Decode x and y x_bytes = base64.urlsafe_b64decode(jwk["x"] + "===") y_bytes = base64.urlsafe_b64decode(jwk["y"] + "===") # Create public key object public_numbers = ec.EllipticCurvePublicNumbers.from_encoded_point(ec.SECP256R1(), b'\x04' + x_bytes + y_bytes) public_key = public_numbers.public_key() # Convert to PEM format pem_key = public_key.public_bytes( encoding=serialization.Encoding.PEM, format=serialization.PublicFormat.SubjectPublicKeyInfo ).decode() print(pem_key) # This is the PEM key to use in APIM
- Then use the PEM Key in Azure APIM’s validate-jwt Policy, once you have the PEM-encoded key, insert it into the
validate-jwt
policy:<validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized"> <issuer-signing-keys> <key> -----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQ... -----END PUBLIC KEY----- </key> </issuer-signing-keys> <valid-issuers> <issuer>https://your-issuer.com</issuer> </valid-issuers> <valid-audiences> <audience>your-audience</audience> </valid-audiences> </validate-jwt>
I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.