nginxinc / NGINX-Demos

NGINX and NGINX Plus demos
Apache License 2.0
1.25k stars 668 forks source link

oauth2-token-introspection-oss throws interbediate value toBytes is not a function #120

Open netchild opened 11 months ago

netchild commented 11 months ago

For line 22 in oauth2.js the code throws a TypeError: (intermediate value)["toBytes"] is not a function (even after adding the missing semicolons in #119 ).

Atomique commented 9 months ago

Having the same problem trying to use this example. Can someone help out here?

Edit: Found something, but dont know how to get this working at the moment,

Since 0.8.0, the support for byte strings and byte string methods were removed. When working with byte sequence, the Buffer object and Buffer properties, such as r.requestBuffer, r.rawVariables, should be used.

http://nginx.org/en/docs/njs/reference.html#string_tobytes

PatBriPerso commented 6 months ago

I try to use oauth2-token-introspection-oss too and I confirm that toBytes does not exist anymore.

I change the line 22 from: authHeader = "Basic " + basicAuthPlaintext.toBytes().toString('base64'); to: authHeader = "Basic " + basicAuthPlaintext.toString('base64'); and it works.

Then I have had a second issue: reply.responseBody does not exist anymore. So I replace it by reply.responseText and I'm able to validate my token.