首先:我不是 nginx 专家。非常新手。
我正在尝试使用 nginx 进行身份验证来保护第 3 方软件(实际上 - 只是验证请求是否具有有效的 OAuth2 Bearer 令牌)
HTTP 请求的身份验证标头中将包含 OAuth2 持有者令牌。
例如授权:承载 eyJhbGciOiJSUzI1NiIsImtpZ....H5w
我有一个 OAuth2 服务器(UAA),它有一个 api,我可以在其中调用http://myuaa/check_token?token=eyJhbGciOiJSUzI1NiIsImtpZ....H5w来获取 2XX 或 4XX(如果令牌有效)。复杂的是,该服务器确实需要基本身份验证才能调用 /check_token 端点。
我尝试使用映射来解析授权标头中的令牌,但没有成功。
就是有点不知所措。
也许这不太适合 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; …
Run Code Online (Sandbox Code Playgroud)