Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename variable from args to query params for authz endpoint #78

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
16 changes: 8 additions & 8 deletions openid_connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function auth(r, afterSyncCheck) {
return;
}
// Redirect the client to the IdP login page with the cookies we need for state
r.return(302, r.variables.oidc_authz_endpoint + getAuthZArgs(r));
r.return(302, r.variables.oidc_authz_endpoint + getQueryParamsAuthZ(r));
return;
}

Expand Down Expand Up @@ -271,16 +271,16 @@ function logout(r) {
r.return(302, r.variables.oidc_logout_redirect);
}

function getAuthZArgs(r) {
function getQueryParamsAuthZ(r) {
// Choose a nonce for this flow for the client, and hash it for the IdP
var noncePlain = r.variables.request_id;
var c = require('crypto');
var h = c.createHmac('sha256', r.variables.oidc_hmac_key).update(noncePlain);
var nonceHash = h.digest('base64url');
var authZArgs = "?response_type=code&scope=" + r.variables.oidc_scopes + "&client_id=" + r.variables.oidc_client + "&redirect_uri="+ r.variables.redirect_base + r.variables.redir_location + "&nonce=" + nonceHash;
var queryParams = "?response_type=code&scope=" + r.variables.oidc_scopes + "&client_id=" + r.variables.oidc_client + "&redirect_uri="+ r.variables.redirect_base + r.variables.redir_location + "&nonce=" + nonceHash;

if (r.variables.oidc_authz_extra_args) {
authZArgs += "&" + r.variables.oidc_authz_extra_args;
if (r.variables.oidc_authz_extra_query_params) {
queryParams += "&" + r.variables.oidc_authz_extra_query_params;
}

r.headersOut['Set-Cookie'] = [
Expand All @@ -294,11 +294,11 @@ function getAuthZArgs(r) {
var pkce_code_challenge = c.createHash('sha256').update(pkce_code_verifier).digest('base64url');
r.variables.pkce_code_verifier = pkce_code_verifier;

authZArgs += "&code_challenge_method=S256&code_challenge=" + pkce_code_challenge + "&state=" + r.variables.pkce_id;
queryParams += "&code_challenge_method=S256&code_challenge=" + pkce_code_challenge + "&state=" + r.variables.pkce_id;
} else {
authZArgs += "&state=0";
queryParams += "&state=0";
}
return authZArgs;
return queryParams;
}

function idpClientAuth(r) {
Expand Down
11 changes: 5 additions & 6 deletions openid_connect_configuration.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ map $host $oidc_authz_endpoint {
#www.example.com "https://my-idp/oauth2/v1/authorize";
}

map $host $oidc_authz_extra_args {
# Extra arguments to include in the request to the IdP's authorization
map $host $oidc_authz_extra_query_params {
# Extra query params to include in the request to the IdP's authorization
# endpoint.
# Some IdPs provide extended capabilities controlled by extra arguments,
# Some IdPs provide extended capabilities controlled by extra query params,
# for example Keycloak can select an IdP to delegate to via the
# "kc_idp_hint" argument.
# Arguments must be expressed as query string parameters and URL-encoded
# if required.
# It must be expressed as query string params and URL-encoded if required.
default "";
#www.example.com "kc_idp_hint=another_provider"
#www.example.com "kc_idp_hint=another_provider";
}

map $host $oidc_token_endpoint {
Expand Down