{"id":329422,"date":"2022-02-11T09:00:46","date_gmt":"2022-02-11T09:00:46","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=329422"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=329422","title":{"rendered":"<span>\u0420\u0435\u0446\u0435\u043f\u0442\u044b Nginx: \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 auth0<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/auth0.com\/\" rel=\"noopener noreferrer nofollow\">auth0<\/a> \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0441\u0430\u043c <a href=\"https:\/\/nginx.org\/\" rel=\"noopener noreferrer nofollow\">nginx<\/a> \u0438 \u0435\u0433\u043e \u043f\u043b\u0430\u0433\u0438\u043d\u044b <a href=\"https:\/\/github.com\/RekGRpth\/encrypted-session-nginx-module\" rel=\"noopener noreferrer nofollow\">encrypted-session<\/a>, <a href=\"https:\/\/github.com\/openresty\/headers-more-nginx-module\" rel=\"noopener noreferrer nofollow\">headers-more<\/a>, <a href=\"https:\/\/nginx.org\/ru\/docs\/http\/ngx_http_auth_request_module.html\" rel=\"noopener noreferrer nofollow\">auth_request<\/a>, <a href=\"https:\/\/github.com\/openresty\/set-misc-nginx-module\" rel=\"noopener noreferrer nofollow\">set-misc<\/a>, <a href=\"https:\/\/github.com\/openresty\/echo-nginx-module\" rel=\"noopener noreferrer nofollow\">echo<\/a>, <a href=\"https:\/\/github.com\/RekGRpth\/ngx_http_json_module\" rel=\"noopener noreferrer nofollow\">json<\/a>, <a href=\"https:\/\/github.com\/RekGRpth\/ngx_http_evaluate_module\" rel=\"noopener noreferrer nofollow\">evaluate<\/a> \u0438 <a href=\"https:\/\/github.com\/RekGRpth\/nginx-jwt-module\" rel=\"noopener noreferrer nofollow\">jwt<\/a>. \u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <a href=\"https:\/\/github.com\/rekgrpth\/nginx.docker\/pkgs\/container\/nginx.docker\" rel=\"noopener noreferrer nofollow\">\u0433\u043e\u0442\u043e\u0432\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439<\/p>\n<pre><code class=\"bash\">curl https:\/\/our.application.domain.com\/pem | openssl x509 -pubkey -noout > pub.key<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c<\/p>\n<pre><code class=\"nginx\">encrypted_session_key \"abcdefghijklmnopqrstuvwxyz123456\";<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <\/p>\n<pre><code class=\"nginx\">more_clear_input_headers Authorization;<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u043c \u0432\u0441\u0451 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439<\/p>\n<pre><code class=\"nginx\">auth_request @auth; location @auth {   # \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043a\u0443\u043a\u0438, \u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d     if ($cookie_auth = \"\") { return 401 UNAUTHORIZED; }   # \u0440\u0430\u0441\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043a\u0443\u043a\u0443     set_decode_base64 $auth_decode $cookie_auth;   # \u0435\u0441\u043b\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u0441\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d     if ($auth_decode = \"\") { return 401 UNAUTHORIZED; }   # \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043a\u0443\u043a\u0443     set_decrypt_session $auth_decrypt $auth_decode;   # \u0435\u0441\u043b\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d     if ($auth_decrypt = \"\") { return 401 UNAUTHORIZED; }   # \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430 basic (\u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e $remote_user)     more_set_input_headers \"Authorization: Basic $auth_decrypt\";     echo -n OK; # \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0438\u0437 \u0438\u0445 \u043f\u0430\u043f\u043a\u0438<\/p>\n<pre><code class=\"nginx\">location \/ {     alias html\/$remote_user\/; }<\/code><\/pre>\n<p>\u0410 \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430 auth0<\/p>\n<pre><code class=\"nginx\">error_page 401 = @error; location @error {   # \u0437\u0430\u0434\u0430\u0451\u043c \u0434\u043e\u043c\u0435\u043d \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 auth0     set $domain our.application.domain.com;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 auth0     set_escape_uri $client_id_escape YourApplicationClientID;   # \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441     set_escape_uri $request_uri_escape $request_uri;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430     set_escape_uri $redirect_uri_escape https:\/\/$host\/login?request_uri=$request_uri_escape;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0442\u0438\u043f \u043e\u0442\u0432\u0435\u0442\u0430     set_escape_uri $response_type_escape code;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0441\u043a\u043e\u0443\u043f\u044b     set_escape_uri $scope_escape \"openid profile\";   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435     set_escape_uri $state_escape 0;   # \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043d\u0430 auth0     return 303 https:\/\/$domain\/authorize?client_id=$client_id_escape&amp;redirect_uri=$redirect_uri_escape&amp;response_type=$response_type_escape&amp;scope=$scope_escape&amp;state=$state_escape; }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 auth0, \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430 \u0430\u0434\u0440\u0435\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430<\/p>\n<pre><code class=\"nginx\">location =\/login {     auth_request off; # \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e     evaluate $grant \/grant; # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0433\u0440\u0430\u043d\u0442     json_loads $grant_json $grant; # \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0435\u0433\u043e     json_dumps $aud $grant_json aud; # \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440   # \u0435\u0441\u043b\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d, \u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d   if ($aud = \"\") { return 401 UNAUTHORIZED; }     json_dumps $name $grant_json name; # \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0438\u043c\u044f   # \u0437\u0430\u0434\u0430\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043f\u0430\u0440\u043e\u043b\u044c \u0434\u043b\u044f basic \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438     set_secure_random_alphanum $password 8;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c basic \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e     set_encode_base64 $username_password_encode $name:$password;   # \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u043c basic \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430 12 \u0447\u0430\u0441\u043e\u0432 (12 * 60 * 60 = 43200)     set_encrypt_session $auth_encrypt $username_password_encode 43200;   # \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e basic \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e     set_encode_base64 $auth_encode $auth_encrypt;   # \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e basic \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u0432 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043a\u0443\u043a\u0443 \u043d\u0430 12 \u0447\u0430\u0441\u043e\u0432     add_header Set-Cookie \"Auth=$auth_encode; Max-Age=43200\";   # \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430     set $arg_request_uri_or_slash $arg_request_uri;   # \u0435\u0441\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043d\u0435 \u0437\u0430\u0434\u0430\u043d, \u0442\u043e \u043d\u0430\u0447\u0430\u043b\u043e     set_if_empty $arg_request_uri_or_slash \/;   # \u0440\u0430\u0441\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441     set_unescape_uri $request_uri_unescape $arg_request_uri_or_slash;   # \u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441     return 303 $request_uri_unescape; } location =\/grant {     internal; # \u0437\u0430\u043f\u0440\u043e\u0441 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0445\u043e\u0441\u0442     set_escape_uri $host_escape $host;   # \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c \u0441\u0436\u0438\u043c\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442     proxy_set_header Accept-Encoding deflate;   # \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440     proxy_pass http:\/\/localhost\/grant?request_uri=$arg_request_uri&amp;code=$arg_code&amp;host=$host_escape; }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u043d\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440<\/p>\n<pre><code class=\"nginx\">server {     listen localhost; # \u0441\u043b\u0443\u0448\u0430\u0435\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e     allow 127.0.0.1; # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f     deny all; # \u0438 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435     location =\/grant {         evaluate $token @token; # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d         json_loads $token_json $token; # \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0435\u0433\u043e         json_dumps $id_token $token_json id_token; # \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d         auth_jwt $id_token; # \u0437\u0430\u0434\u0430\u0451\u043c \u0435\u0433\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 jwt         auth_jwt_alg RS256; # \u0437\u0430\u0434\u0430\u0451\u043c \u0442\u0438\u043f \u0442\u043e\u043a\u0435\u043d\u0430         auth_jwt_key \/path\/to\/our\/pub.key file; # \u0437\u0430\u0434\u0430\u0451\u043c \u043d\u0430\u0448 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447         echo -n $jwt_grant; # \u043e\u0442\u0434\u0430\u0451\u043c \u0442\u0435\u043b\u043e \u0442\u043e\u043a\u0435\u043d\u0430     }     location @token {   # \u0437\u0430\u0434\u0430\u0451\u043c \u0434\u043e\u043c\u0435\u043d \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 auth0     set $domain our.application.domain.com;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 auth0     set_escape_uri $client_id_escape YourApplicationClientID;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u043f\u0430\u0440\u043e\u043b\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 auth0     set_escape_uri $client_secret_escape YourApplicationClientSecret;     # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0442\u0438\u043f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438         set_escape_uri $grant_type_escape authorization_code;     # \u0440\u0430\u0441\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0445\u043e\u0441\u0442         set_unescape_uri $host_unescape $arg_host;     # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430         set_escape_uri $redirect_uri_escape https:\/\/$host_unescape\/login?request_uri=$arg_request_uri; # \u0437\u0430\u0434\u0430\u0451\u043c \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u0440\u043e\u0441\u0430             proxy_method POST;     # \u0437\u0430\u0434\u0430\u0451\u043c \u0442\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430         proxy_set_body client_id=$client_id_escape&amp;code=$arg_code&amp;redirect_uri=$redirect_uri_escape&amp;client_secret=$client_secret_escape&amp;grant_type=$grant_type_escape;     # \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c \u0441\u0436\u0438\u043c\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442         proxy_set_header Accept-Encoding deflate;     # \u0437\u0430\u0434\u0430\u0451\u043c \u0442\u0438\u043f \u0442\u0435\u043b\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430         proxy_set_header Content-Type application\/x-www-form-urlencoded;     # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043b\u0430\u0432\u0430\u0442\u044c \u0438\u043c\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430         proxy_ssl_server_name on;     # \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 auth0         proxy_pass https:\/\/$domain\/oauth\/token;   } }<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/650911\/\"> https:\/\/habr.com\/ru\/post\/650911\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/auth0.com\/\" rel=\"noopener noreferrer nofollow\">auth0<\/a> \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0441\u0430\u043c <a href=\"https:\/\/nginx.org\/\" rel=\"noopener noreferrer nofollow\">nginx<\/a> \u0438 \u0435\u0433\u043e \u043f\u043b\u0430\u0433\u0438\u043d\u044b <a href=\"https:\/\/github.com\/RekGRpth\/encrypted-session-nginx-module\" rel=\"noopener noreferrer nofollow\">encrypted-session<\/a>, <a href=\"https:\/\/github.com\/openresty\/headers-more-nginx-module\" rel=\"noopener noreferrer nofollow\">headers-more<\/a>, <a href=\"https:\/\/nginx.org\/ru\/docs\/http\/ngx_http_auth_request_module.html\" rel=\"noopener noreferrer nofollow\">auth_request<\/a>, <a href=\"https:\/\/github.com\/openresty\/set-misc-nginx-module\" rel=\"noopener noreferrer nofollow\">set-misc<\/a>, <a href=\"https:\/\/github.com\/openresty\/echo-nginx-module\" rel=\"noopener noreferrer nofollow\">echo<\/a>, <a href=\"https:\/\/github.com\/RekGRpth\/ngx_http_json_module\" rel=\"noopener noreferrer nofollow\">json<\/a>, <a href=\"https:\/\/github.com\/RekGRpth\/ngx_http_evaluate_module\" rel=\"noopener noreferrer nofollow\">evaluate<\/a> \u0438 <a href=\"https:\/\/github.com\/RekGRpth\/nginx-jwt-module\" rel=\"noopener noreferrer nofollow\">jwt<\/a>. \u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <a href=\"https:\/\/github.com\/rekgrpth\/nginx.docker\/pkgs\/container\/nginx.docker\" rel=\"noopener noreferrer nofollow\">\u0433\u043e\u0442\u043e\u0432\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439<\/p>\n<pre><code class=\"bash\">curl https:\/\/our.application.domain.com\/pem | openssl x509 -pubkey -noout > pub.key<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c<\/p>\n<pre><code class=\"nginx\">encrypted_session_key \"abcdefghijklmnopqrstuvwxyz123456\";<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <\/p>\n<pre><code class=\"nginx\">more_clear_input_headers Authorization;<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u043c \u0432\u0441\u0451 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439<\/p>\n<pre><code class=\"nginx\">auth_request @auth; location @auth {   # \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043a\u0443\u043a\u0438, \u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d     if ($cookie_auth = \"\") { return 401 UNAUTHORIZED; }   # \u0440\u0430\u0441\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043a\u0443\u043a\u0443     set_decode_base64 $auth_decode $cookie_auth;   # \u0435\u0441\u043b\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u0441\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d     if ($auth_decode = \"\") { return 401 UNAUTHORIZED; }   # \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043a\u0443\u043a\u0443     set_decrypt_session $auth_decrypt $auth_decode;   # \u0435\u0441\u043b\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d     if ($auth_decrypt = \"\") { return 401 UNAUTHORIZED; }   # \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430 basic (\u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e $remote_user)     more_set_input_headers \"Authorization: Basic $auth_decrypt\";     echo -n OK; # \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0438\u0437 \u0438\u0445 \u043f\u0430\u043f\u043a\u0438<\/p>\n<pre><code class=\"nginx\">location \/ {     alias html\/$remote_user\/; }<\/code><\/pre>\n<p>\u0410 \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430 auth0<\/p>\n<pre><code class=\"nginx\">error_page 401 = @error; location @error {   # \u0437\u0430\u0434\u0430\u0451\u043c \u0434\u043e\u043c\u0435\u043d \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 auth0     set $domain our.application.domain.com;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 auth0     set_escape_uri $client_id_escape YourApplicationClientID;   # \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441     set_escape_uri $request_uri_escape $request_uri;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430     set_escape_uri $redirect_uri_escape https:\/\/$host\/login?request_uri=$request_uri_escape;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0442\u0438\u043f \u043e\u0442\u0432\u0435\u0442\u0430     set_escape_uri $response_type_escape code;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0441\u043a\u043e\u0443\u043f\u044b     set_escape_uri $scope_escape \"openid profile\";   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435     set_escape_uri $state_escape 0;   # \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043d\u0430 auth0     return 303 https:\/\/$domain\/authorize?client_id=$client_id_escape&amp;redirect_uri=$redirect_uri_escape&amp;response_type=$response_type_escape&amp;scope=$scope_escape&amp;state=$state_escape; }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 auth0, \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430 \u0430\u0434\u0440\u0435\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430<\/p>\n<pre><code class=\"nginx\">location =\/login {     auth_request off; # \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e     evaluate $grant \/grant; # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0433\u0440\u0430\u043d\u0442     json_loads $grant_json $grant; # \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0435\u0433\u043e     json_dumps $aud $grant_json aud; # \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440   # \u0435\u0441\u043b\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d, \u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d   if ($aud = \"\") { return 401 UNAUTHORIZED; }     json_dumps $name $grant_json name; # \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0438\u043c\u044f   # \u0437\u0430\u0434\u0430\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043f\u0430\u0440\u043e\u043b\u044c \u0434\u043b\u044f basic \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438     set_secure_random_alphanum $password 8;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c basic \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e     set_encode_base64 $username_password_encode $name:$password;   # \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u043c basic \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430 12 \u0447\u0430\u0441\u043e\u0432 (12 * 60 * 60 = 43200)     set_encrypt_session $auth_encrypt $username_password_encode 43200;   # \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e basic \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e     set_encode_base64 $auth_encode $auth_encrypt;   # \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e basic \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u0432 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043a\u0443\u043a\u0443 \u043d\u0430 12 \u0447\u0430\u0441\u043e\u0432     add_header Set-Cookie \"Auth=$auth_encode; Max-Age=43200\";   # \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430     set $arg_request_uri_or_slash $arg_request_uri;   # \u0435\u0441\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043d\u0435 \u0437\u0430\u0434\u0430\u043d, \u0442\u043e \u043d\u0430\u0447\u0430\u043b\u043e     set_if_empty $arg_request_uri_or_slash \/;   # \u0440\u0430\u0441\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441     set_unescape_uri $request_uri_unescape $arg_request_uri_or_slash;   # \u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441     return 303 $request_uri_unescape; } location =\/grant {     internal; # \u0437\u0430\u043f\u0440\u043e\u0441 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0445\u043e\u0441\u0442     set_escape_uri $host_escape $host;   # \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c \u0441\u0436\u0438\u043c\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442     proxy_set_header Accept-Encoding deflate;   # \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440     proxy_pass http:\/\/localhost\/grant?request_uri=$arg_request_uri&amp;code=$arg_code&amp;host=$host_escape; }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u043d\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440<\/p>\n<pre><code class=\"nginx\">server {     listen localhost; # \u0441\u043b\u0443\u0448\u0430\u0435\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e     allow 127.0.0.1; # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f     deny all; # \u0438 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435     location =\/grant {         evaluate $token @token; # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d         json_loads $token_json $token; # \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0435\u0433\u043e         json_dumps $id_token $token_json id_token; # \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d         auth_jwt $id_token; # \u0437\u0430\u0434\u0430\u0451\u043c \u0435\u0433\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 jwt         auth_jwt_alg RS256; # \u0437\u0430\u0434\u0430\u0451\u043c \u0442\u0438\u043f \u0442\u043e\u043a\u0435\u043d\u0430         auth_jwt_key \/path\/to\/our\/pub.key file; # \u0437\u0430\u0434\u0430\u0451\u043c \u043d\u0430\u0448 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447         echo -n $jwt_grant; # \u043e\u0442\u0434\u0430\u0451\u043c \u0442\u0435\u043b\u043e \u0442\u043e\u043a\u0435\u043d\u0430     }     location @token {   # \u0437\u0430\u0434\u0430\u0451\u043c \u0434\u043e\u043c\u0435\u043d \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 auth0     set $domain our.application.domain.com;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 auth0     set_escape_uri $client_id_escape YourApplicationClientID;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u043f\u0430\u0440\u043e\u043b\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 auth0     set_escape_uri $client_secret_escape YourApplicationClientSecret;     # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0442\u0438\u043f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438         set_escape_uri $grant_type_escape authorization_code;     # \u0440\u0430\u0441\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0445\u043e\u0441\u0442         set_unescape_uri $host_unescape $arg_host;     # \u0437\u0430\u0434\u0430\u0451\u043c \u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430         set_escape_uri $redirect_uri_escape https:\/\/$host_unescape\/login?request_uri=$arg_request_uri; # \u0437\u0430\u0434\u0430\u0451\u043c \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u0440\u043e\u0441\u0430             proxy_method POST;     # \u0437\u0430\u0434\u0430\u0451\u043c \u0442\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430         proxy_set_body client_id=$client_id_escape&amp;code=$arg_code&amp;redirect_uri=$redirect_uri_escape&amp;client_secret=$client_secret_escape&amp;grant_type=$grant_type_escape;     # \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c \u0441\u0436\u0438\u043c\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442         proxy_set_header Accept-Encoding deflate;     # \u0437\u0430\u0434\u0430\u0451\u043c \u0442\u0438\u043f \u0442\u0435\u043b\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430         proxy_set_header Content-Type application\/x-www-form-urlencoded;     # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043b\u0430\u0432\u0430\u0442\u044c \u0438\u043c\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430         proxy_ssl_server_name on;     # \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 auth0         proxy_pass https:\/\/$domain\/oauth\/token;   } }<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/650911\/\"> https:\/\/habr.com\/ru\/post\/650911\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-329422","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/329422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=329422"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/329422\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=329422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=329422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=329422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}