

#DECODE JWT CODE#
Once you have the code in your service, you can further customize it if you need to.Īll code on this page is provided under both the BSD and MIT open source licenses.You're viewing Apigee Edge documentation.Īpigee X documentation.
#DECODE JWT INSTALL#
Feel free to run it, and click the INSTALL tab to customize and upload it to a Fastly service in your account: The embedded fiddle below shows the complete solution. You can do this with a client certificate, a pre-shared key, or by adding Fastly network IP addresses to a firewall. If your origin servers are exposed to the internet (and not privately peered with Fastly), then you may want to take steps to ensure that users cannot send 'authenticated' requests directly to origin. You can define the table using an private edge dictionary, which enables you to manage the table via HTTP API calls, without having to clone and activate new versions of your service, and without having the credential data visible in your service configuration. This solution contains a VCL table that stores credentials. That's fine, and in that case, the responses that have inspected userID should include it in the vary header: It's possible that you always inspect something like auth-state, and then for certain states, you also inspect another property like UserID. Making use of high granularity data such as 'Name' and 'user ID' generally renders a response effectively uncacheable at the edge. Medium granularity data such as 'Groups' (which we assume to be a string containing multiple group names) can also work, but think about normalising this kind of data, e.g., by making it lowercase and sorting the tokens into alphabetical order. We don't need to keep separate copies for all the different auth-userids though, because you didn't use that information to generate the page output.Īuthentication data with low granularity, such as 'is authenticated', 'level', 'role', or 'is admin' are really good properties to use to vary page output in a way that still allows it to be efficiently cached. In this case, you're saying that the response contains information that varies based on the auth-state header, so Fastly needs to keep multiple copies of this resource, one for each of the possible values of auth-state (only two in our example here: "Authenticated" and "Anonymous"). This code goes at the end of the vcl_recv subroutine, because we want it to run regardless of whether the cookie was valid or not. Keep your application better encapsulated by removing data higher up the stack if it should not penetrate any lower. In fact, it's better that you don't, because if you do, you will send two sources of authentication information to the origin server, and you can't control which ones the server will use. Now that the authentication state data from the cookie has been resolved, you no longer need to keep the cookie around. Exit from the vcl_error subroutine by explicitly performing a return(deliver).entire HTML pages, can be included here using the syntax, which may include newlines Add headers using obj.http, such as -type.Set obj.response to the canonical HTTP response status descriptor that goes with the status code, e.g., "OK" for 200 (this feature is no longer present in HTTP/2, and has no effect in H2 connections).Set obj.status to the appropriate HTTP status code.Normally this includes some or all of the following:

Once you know you are processing the error condition that you triggered from your earlier code, you can modify the obj to create the response you want. Checking both of them will ensure you are trapping the right error. These two pieces of data then become obj.status and obj.response in the vcl_error subroutine. To make sure you trap the right error, it's a good idea to use a non-standard HTTP status code in the 6xx range, and also to set an error 'response text' as part of the error statement. This pattern, known as a 'synthetic response', involves triggering an error from somewhere else in your VCL, catching it in the vcl_error subroutine, and then converting the error obj into the response that you want to send to the client.
