Skip to content

Commit

Permalink
refactor parsing of claims encoding into parse.c
Browse files Browse the repository at this point in the history
Signed-off-by: Hans Zandbelt <[email protected]>
  • Loading branch information
zandbelt committed Nov 3, 2023
1 parent 28e79bf commit cab5199
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
20 changes: 3 additions & 17 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,23 +1135,9 @@ static const char* oidc_set_pass_claims_as(cmd_parms *cmd, void *m,
oidc_dir_cfg *dir_cfg = (oidc_dir_cfg*) m;
const char *rv = oidc_parse_set_claims_as(cmd->pool, arg1,
&dir_cfg->pass_info_in_headers, &dir_cfg->pass_info_in_env_vars);
if (rv == NULL) {
if (arg2 != NULL) {
if (_oidc_strcmp(arg2, "base64url") == 0) {
dir_cfg->pass_info_as = OIDC_PASS_APP_INFO_AS_BASE64URL;
} else if (_oidc_strcmp(arg2, "latin1") == 0) {
dir_cfg->pass_info_as = OIDC_PASS_APP_INFO_AS_LATIN1;
} else if (_oidc_strcmp(arg2, "none") == 0) {
dir_cfg->pass_info_as = OIDC_PASS_APP_INFO_AS_NONE;
} else {
rv =
apr_pstrcat(cmd->temp_pool,
"unknown encoding option \"", arg2,
"\", only \"base64url\", \"latin1\" or \"none\" is supported",
NULL);
}
}
}
if ((rv == NULL) && (arg2 != NULL))
rv = oidc_parse_pass_claims_as_encoding(cmd->pool, arg2,
&dir_cfg->pass_info_as);
return OIDC_CONFIG_DIR_RV(cmd, rv);
}

Expand Down
27 changes: 27 additions & 0 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,33 @@ const char *oidc_parse_set_claims_as(apr_pool_t *pool, const char *arg,
return NULL;
}

#define OIDC_PASS_CLAIMS_ENCODING_NONE_STR "none"
#define OIDC_PASS_CLAIMS_ENCODING_LATIN1_STR "latin1"
#define OIDC_PASS_CLAIMS_ENCODING_BASE64URL_STR "base64url"

const char* oidc_parse_pass_claims_as_encoding(apr_pool_t *pool,
const char *arg, int *pass_as) {
static char *options[] = {
OIDC_PASS_CLAIMS_ENCODING_NONE_STR,
OIDC_PASS_CLAIMS_ENCODING_LATIN1_STR,
OIDC_PASS_CLAIMS_ENCODING_BASE64URL_STR,
NULL };
const char *rv = oidc_valid_string_option(pool, arg, options);
if (rv != NULL)
return rv;

if (_oidc_strcmp(arg, OIDC_PASS_CLAIMS_ENCODING_NONE_STR) == 0) {
*pass_as = OIDC_PASS_APP_INFO_AS_BASE64URL;
} else if (_oidc_strcmp(arg, OIDC_PASS_CLAIMS_ENCODING_LATIN1_STR) == 0) {
*pass_as = OIDC_PASS_APP_INFO_AS_LATIN1;
} else if (_oidc_strcmp(arg, OIDC_PASS_CLAIMS_ENCODING_BASE64URL_STR)
== 0) {
*pass_as = OIDC_PASS_APP_INFO_AS_BASE64URL;
}

return NULL;
}

#define OIDC_UNAUTH_ACTION_AUTH_STR "auth"
#define OIDC_UNAUTH_ACTION_PASS_STR "pass"
#define OIDC_UNAUTH_ACTION_401_STR "401"
Expand Down
2 changes: 2 additions & 0 deletions src/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ const char* oidc_parse_claim_required(apr_pool_t *pool, const char *arg,
int *is_required);
const char* oidc_parse_set_claims_as(apr_pool_t *pool, const char *arg,
int *in_headers, int *in_env_vars);
const char* oidc_parse_pass_claims_as_encoding(apr_pool_t *pool,
const char *arg, int *pass_as);
const char* oidc_parse_unauth_action(apr_pool_t *pool, const char *arg,
int *action);
const char* oidc_parse_unautz_action(apr_pool_t *pool, const char *arg,
Expand Down

0 comments on commit cab5199

Please sign in to comment.