Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nginx-如何创建将与auth_请求模块一起使用的自定义请求_Nginx_Nginx Reverse Proxy - Fatal编程技术网

Nginx-如何创建将与auth_请求模块一起使用的自定义请求

Nginx-如何创建将与auth_请求模块一起使用的自定义请求,nginx,nginx-reverse-proxy,Nginx,Nginx Reverse Proxy,首先:我不是nginx专家。我是个新手 我正试图通过nginx进行身份验证来保护第三方软件(实际上,只是验证请求是否具有有效的OAuth2承载令牌) HTTP请求将在身份验证标头中具有OAuth2承载令牌 e、 g.授权:持有人EYJHBGCOIJSUZI1NIISIMTPZ….H5w 我有一个OAuth2服务器(UAA),它有一个api,如果令牌有效,我可以在其中调用以获取2XX或4XX。复杂的是,此服务器确实需要基本身份验证来调用/check_令牌端点 我曾尝试使用映射从授权头解析令牌,但没

首先:我不是nginx专家。我是个新手

我正试图通过nginx进行身份验证来保护第三方软件(实际上,只是验证请求是否具有有效的OAuth2承载令牌)

HTTP请求将在身份验证标头中具有OAuth2承载令牌

e、 g.授权:持有人EYJHBGCOIJSUZI1NIISIMTPZ….H5w

我有一个OAuth2服务器(UAA),它有一个api,如果令牌有效,我可以在其中调用以获取2XX或4XX。复杂的是,此服务器确实需要基本身份验证来调用/check_令牌端点

我曾尝试使用映射从授权头解析令牌,但没有成功

只是有点不知所措

也许这不适合Nginx

nginx.conf的相关部分

# this map isnt working as I thought it might
http {
    ...
    map $http_authorization $token {
        ~Bearer(?<token>abc)    $token;
 }

...

# test just to see if the authorization header is being parsed and passed - no luck
 location /oauth {
         proxy_set_header X-my-header $token;
         proxy_set_header X-another-header value;
         proxy_set_header Authorization "Basic basdasdfasdf";
         proxy_pass http://localhost:8080;
 }

您的
map
指令不起作用,命名组
token
以某种方式干扰了
$token
变量,以下任何定义都有效:

map $http_authorization $token {
    ~^Bearer\s+([\S]+)$ $1;
}

map$http\u授权$token{
~^Bearer\s+(?[\s]+)$$Bearer;
}
完整的工作配置将如下所示:

map $http_authorization $token {
    ~^Bearer\s+(?<bearer>[\S]+)$ $bearer;
}

server {
    ...
    location / {
        auth_request            /uaa;
        ...
    }
    location /uaa {
        internal;
        proxy_pass_request_body off;
        proxy_set_header        Authorization "Basic your_base64_auth_string";
        proxy_set_header        Content-Length "";
        proxy_pass              http://localhost:8080/check_token?token=$token;
    }
}
map$http\u授权$token{
~^Bearer\s+(?[\s]+)$$Bearer;
}
服务器{
...
地点/{
授权请求/uaa;
...
}
地点/阿拉伯联合酋长国{
内部的;
代理通过请求关闭;
代理\u设置\u头授权“基本您的\u base64\u身份验证\u字符串”;
代理集标题内容长度“”;
代理通行证http://localhost:8080/check_token?token=$token;
}
}
map $http_authorization $token {
    ~^Bearer\s+([\S]+)$ $1;
}
map $http_authorization $token {
    ~^Bearer\s+(?<bearer>[\S]+)$ $bearer;
}
map $http_authorization $token {
    ~^Bearer\s+(?<bearer>[\S]+)$ $bearer;
}

server {
    ...
    location / {
        auth_request            /uaa;
        ...
    }
    location /uaa {
        internal;
        proxy_pass_request_body off;
        proxy_set_header        Authorization "Basic your_base64_auth_string";
        proxy_set_header        Content-Length "";
        proxy_pass              http://localhost:8080/check_token?token=$token;
    }
}