Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions oauth2-token-introspection-oss/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ function introspectAccessToken(r) {
var authHeader = "";
if (r.variables.oauth_client_id.length) {
var basicAuthPlaintext = r.variables.oauth_client_id + ":" + r.variables.oauth_client_secret;
authHeader = "Basic " + basicAuthPlaintext.toBytes().toString('base64');
authHeader = "Basic " + Buffer.from(basicAuthPlaintext).toString('base64');
} else {
authHeader = "Bearer " + r.variables.oauth_client_secret;
}

// Make the OAuth 2.0 Token Introspection request
r.log("OAuth sending introspection request with token: " + r.variables.access_token)
r.log("OAuth sending introspection request with token: " + r.variables.access_token);
r.subrequest("/_oauth2_send_introspection_request", "token=" + r.variables.access_token + "&authorization=" + authHeader,
function(reply) {
if (reply.status != 200) {
Expand All @@ -35,8 +35,8 @@ function introspectAccessToken(r) {

// We have a response from authorization server, validate it has expected JSON schema
try {
r.log("OAuth token introspection response: " + reply.responseBody)
var response = JSON.parse(reply.responseBody);
r.log("OAuth token introspection response: " + reply.responseText);
var response = JSON.parse(reply.responseText);
// TODO: check for errors in the JSON response first
// We have a valid introspection response
// Check for validation success
Expand Down
10 changes: 5 additions & 5 deletions oauth2-token-introspection-plus/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function introspectAccessToken(r) {
var authHeader = "";
if (r.variables.oauth_client_id.length) {
var basicAuthPlaintext = r.variables.oauth_client_id + ":" + r.variables.oauth_client_secret;
authHeader = "Basic " + basicAuthPlaintext.toBytes().toString('base64');
authHeader = "Basic " + Buffer.from(basicAuthPlaintext).toString('base64');
} else {
authHeader = "Bearer " + r.variables.oauth_client_secret;
}
Expand All @@ -43,18 +43,18 @@ function introspectAccessToken(r) {

// We have a response from authorization server, validate it has expected JSON schema
try {
r.log("OAuth token introspection response: " + reply.responseBody)
var response = JSON.parse(reply.responseBody); // Test for valid JSON so that we only store good responses
r.log("OAuth token introspection response: " + reply.responseText);
var response = JSON.parse(reply.responseText); // Test for valid JSON so that we only store good responses
if (response.active.length) {
r.variables.token_data = response.toString('base64'); // Store this repsonse in keyval zone
tokenResult(r);
} else {
r.error("OAuth error in token introspection response: " + reply.responseBody);
r.error("OAuth error in token introspection response: " + reply.responseText);
r.return(401);
return;
}
} catch (e) {
r.error("OAuth token introspection response is not JSON: " + reply.responseBody);
r.error("OAuth token introspection response is not JSON: " + reply.responseText);
r.return(401);
}
}
Expand Down