Skip to content

Instantly share code, notes, and snippets.

@ThijsFeryn
Last active February 13, 2017 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThijsFeryn/0b1bd4337c934ac77bc6759dc38a6a11 to your computer and use it in GitHub Desktop.
Save ThijsFeryn/0b1bd4337c934ac77bc6759dc38a6a11 to your computer and use it in GitHub Desktop.
Call the custom-defined JWT VCL procedure that checks the validity of a JSON Web Token. This VCL snippet requires vmod_digest and https://gist.github.com/ThijsFeryn/b745c42dbfa328d702b8dbba8777aee2
vcl 4.0;
import digest;
backend default {
.host = "localhost";
.port = "8080";
}
include "jwt.vcl";
sub vcl_recv {
if ((req.method != "GET" && req.method != "HEAD") || req.http.Authorization) {
return (pass);
}
call jwt;
if(req.url == "/private" && req.http.X-Login != "true") {
return(synth(302,"/login"));
}
return(hash);
}
sub vcl_synth {
if (resp.status == 301 || resp.status == 302) {
set resp.http.location = resp.reason;
set resp.reason = "Moved";
return (deliver);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment