Duration : 15 mins
Persona : API Team/Security
You have an API that is consumed by third parties. You want to secure that API using JSON Web Tokens aka JWTs.
Both JWS (JSON Web Signature) and JWT (JSON Web Token) are commonly used ways to share claims or assertions between connected applications in a secure fashion. Apigee Edge provides support for JWS and JWT via out-of-the-box policies. The JWS/JWT policies enables Edge API proxies to:
For more information on JWS and JWT support in Apigee visit the documentation page here: https://docs.apigee.com/api-platform/reference/policies/jwt-policies-overview
Go to https://apigee.com/edge and log in. This is the Edge management UI.
Select Environments → Key Value Maps in the side navigation menu:
/token
) to generate a JWT/verify
) to verify a JWTCheck both flows and read the JWT policies to get a deeper understanding of how they work (reference links available at the end of the lab). Then click the Trace tab:
/token
endpoint to generate a valid JWT. You can send this request either using a REST client like the one here, or by using the curl
command from a terminal. The HTTP request to send is:POST /v1/jwt/token HTTP/1.1
Host: -.apigee.net
Content-Length: 0
Here is an example curl
command (you will need to replace values as described above):
curl -X POST -H "Content-Length: 0" https://-.apigee.net/v1/jwt/token
token
value (without the surrounding quotes) and review the Trace tool to understand what happened./verify
proxy endpoint in Apigee. Use the same REST tool or curl
to do so. The HTTP request is:POST /v1/jwt/verify HTTP/1.1
Host: -.apigee.net
Content-Length: 0
token:
Replace with your actual Apigee org name, and with the deployment environment for your proxy (eg. test)
Replace with the value of the JWT
Here is an example curl
command (you will need to replace values as described above):
curl -X POST -I -H "Content-Length: 0" -H "token: " https://-.apigee.net/v1/jwt/verify
Change the JWT token generation policy to include additional claims (iss, aud, sub, extra claims) in it, to see how the behavior changes.
You can also try to tamper with the resultig JWT (add/remove characters) and invoke the same /verify
API call again. What happens?
In this lab, you learned how to use Apigee’s out of the box JWT policies to both generate and verify a JWT. Now you can use these policies to actually secure an API using JWT security. To do so, you would first want to authenticate a user against their IdP (which also contains “claims” about that user/principal) before calling GenerateJWT and issuing the JWT with claims back to that user (for simplicity, we skipped the user authentication step in this lab and hard coded the claims). The API that is protected would invoke VerifyJWT (either directly or via an Apigee endpoint) to verify the JWT and read/verify its claims.
You may now proceed to Lab 5.