EDIT: I posted a link to my implementation, possibly triggering the forum immune system to mark this post as spam. Removing the link to my implementation. Screenshots showing the issue are in the following posts.
If someone wouldn’t mind pointing out the (probably obvious) flaw in my deploy I would greatly appreciate it…
Here [link redacted] we have my attempt to deploy an exact clone of the Auth0 Custom Authorizer Function Example. Public endpoint works. Login works. The private endpoint resulting in a CORS error in the browser. (Test with login: test@test.com / fdsa)
You can find a working example with all endpoints working by following the Auth0 Custom Authorizer github repo link above.
The CORS setting in serverless.yml on each endpoint are, a bit different.
Being fairly new to CORS and Serverless I can’t seem to find the flaw, even after digging through the request / response headers. I’m hoping someone can point me in the right direction. Any tips?
can you post the exact CORS error? a screenshot of the browser debugger window will do. Need to know which endpoint you are trying to reach, whether it’s the GET or OPTIONS that’s failing etc.
Also, your complete yaml file would be good too - where are you defining the auth function?
I did enter (and just double-checked) those values.
I added some logs around the auth function and found an invalid signature error. However, when I paste the token into jwt.io with the AUTH0_CLIENT_SECRET value the signature says it’s valid.
(Forum not letting me post a link to the github code for some reason. Authorizer function pasted below)
const token = event.authorizationToken.substring(7); //i'm logging to token to verify on jwt.io
const options = {
audience: AUTH0_CLIENT_ID,
};
jwt.verify(token, new Buffer(AUTH0_CLIENT_SECRET, 'base64'), options, (err, decoded) => {
if (err) {
cb('Unauthorized'); // <---- invalid signature error being thrown here
} else {
cb(null, generatePolicy(decoded.sub, 'Allow', event.methodArn));
}
});
The fact the that the live demo is working fine gives me hope that it’s me, not the code.
Just two days ago a PR was submitted on the examples repo to fix the bug. More info on issue #62 in the Serverless Examples Repo (forum is not letting me post a link!)
PR not yet merged, but in the meantime I manually removed the base64 encoding of the AUTH0_CLIENT_SECRET and it worked.