mod_auth_openidc 如何访问用户变量以在 PHP 中使用

art*_*lay 5 php apache httpd.conf mod-auth-openidc

我一直在mod_auth_openidc努力centos7,但找不到引用如何提取传递的用户信息的文档。

我的日志显示该模块正在执行以下询问

oidc_authz_match_claim: evaluating key "nickname"
oidc_authz_match_claim: evaluating key "email"
oidc_authz_match_claim: evaluating key "user_id"
oidc_authz_match_claim: evaluating key "identities"
oidc_authz_match_claim: evaluating key "iat"
oidc_authz_match_claim: evaluating key "picture"
oidc_authz_match_claim: evaluating key "last_password_reset"
oidc_authz_match_claim: evaluating key "name"
oidc_authz_match_claim: evaluating key "created_at"
oidc_authz_match_claim: evaluating key "app_metadata"
oidc_authz_match_claim: evaluating key "email_verified"
oidc_authz_match_claim: evaluating key "clientID"
oidc_authz_match_claim: evaluating key "folders"
Run Code Online (Sandbox Code Playgroud)

我尝试在 httpd.conf 中设置以下两项

OIDCRemoteUserClaim email
OIDCOAuthRemoteUserClaim email
Run Code Online (Sandbox Code Playgroud)

然后使用<?php echo $_SESSION['REMOTE_USER']; ?>,但我没有得到任何返回的变量。

谢谢艺术

Han*_* Z. 4

在默认设置中,email声明可用作环境变量:

echo $_SERVER['OIDC_CLAIM_email']
Run Code Online (Sandbox Code Playgroud)

并作为 HTTP 标头:

$hdrs = apache_request_headers();
echo $hdrs['OIDC_CLAIM_email'];
Run Code Online (Sandbox Code Playgroud)

REMOTE_USER变量可通过以下方式访问:

$_SERVER['REMOTE_USER'];
Run Code Online (Sandbox Code Playgroud)

默认情况下将设置为全局唯一标识符,但可以通过OIDCRemoteUserClaim如您所示的指令进行配置。关于设置的一些说明:

  1. 您会注意到,HTTP 标头也可在环境变量中使用,其变量名称以大写HTTP_字母开头,例如
    $_SERVER['HTTP_OIDC_CLAIM_EMAIL'];

  2. 您可以通过各种配置指令配置在标头和/或环境变量中传递声明的行为

  3. id_token当然,仅当关联声明存在于用户信息端点或从用户信息端点返回时,变量才会存在