Replies: 4 comments 3 replies
-
Hi @human-77. I believe you are referring to the |
Beta Was this translation helpful? Give feedback.
-
Hi, @tom2drum ! 1 - No, the frontend app and backend app are on different domains, but, we change it so they use the same nginx. 2 - We don't want the account function, we want the info in blockscout to be public, which is why we are protecting behind a login. From what you said, I understand the there is no such function in the calls to the blockscout API itself (where we need the cookies to be send in order to protect the data), Am I correct? |
Beta Was this translation helpful? Give feedback.
-
For anyone keeping up with this thread, I have tried to activate the account feature, as suggested by tom2drum and it worked, however, the app is still rough on the edges, so we are smoothing things a bit. Once we have solved the remaining problems I will do a complete explanation, but, if you are working on the cloud, I suggest that is easier to use the same nginx for both the frontend and blockscout. |
Beta Was this translation helpful? Give feedback.
-
Solution: The first step was enable the usage of accounts in the frontend, we did that by:
After that, we edited the proxy of the backend (blockscout itself) as bellow: server {
listen 8080;
server_name {{ .Values.blockscout.proxy.env.SERVER_NAME }};
add_header 'Access-Control-Allow-Origin' '{{ .Values.blockscout.proxy.env.CORS_ORIGIN }}' always;
proxy_http_version 1.1;
location / {
# CHECKING COOKIES
proxy_set_header Cookie $http_cookie;
auth_request /auth_check;
error_page 400 401 402 403 405 500 501 502 503 504 = /unauthorized;
proxy_pass {{ .Values.blockscout.proxy.env.SERVICE_APPLICATION }};
...REST OF CONFIGURATION...
}
location = /auth_check {
proxy_pass {{ .Values.blockscout.proxy.env.AUTHENTICATION_API}};
proxy_set_header Content-Type application/json;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
}
location /unauthorized {
return 301 {{ .Values.blockscout.proxy.env.LOGIN_ENDPOINT }};
}
} We tried using the exact same configuration in the frontend proxy, however, for some reason, it kept getting a CORS error. After many failed attempts we decided to use the proxy of the frontend as a reverse proxy, creating a redirect endpoint. In other words, we configured our endpoint to call itself rather than the blockscout directly and we used the endpoint server {
listen {{ .Values.frontend.service.port }};
server_name {{ .Values.frontend.proxy.env.SERVER_NAME }};
proxy_http_version 1.1;
location / {
# CHECANDO COOKIES
proxy_set_header Cookie $http_cookie;
auth_request /auth_check;
error_page 400 401 402 403 405 500 501 502 503 504 = /unauthorized;
proxy_pass {{ .Values.frontend.proxy.env.SERVICE_APPLICATION }};
...REST OF CONFIGURATION...
}
location = /auth_check {
proxy_pass {{ .Values.frontend.proxy.env.AUTHENTICATION_API}};
proxy_set_header Content-Type application/json;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
}
location /unauthorized {
return 301 {{ .Values.frontend.proxy.env.LOGIN_ENDPOINT }};
}
location ~ ^/(api|socket|sitemap.xml|auth/auth0|auth/auth0/callback|auth/logout) {
proxy_pass "https://{{ .Values.frontend.proxy.env.BLOCKSCOUT_DOMAIN }}";
proxy_set_header Host {{ .Values.frontend.proxy.env.BLOCKSCOUT_DOMAIN }};
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket headers
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Forward cookies
proxy_pass_request_headers on;
proxy_cookie_domain {{ .Values.frontend.proxy.env.SERVER_NAME }} {{ .Values.frontend.proxy.env.BLOCKSCOUT_DOMAIN }};
proxy_hide_header Access-Control-Allow-Origin;
}
} Albeit slower at times, it works perfectly. We are still looking towards an enviroment variable to control de usage of 'include' in the fetch requests. Thank you for the help! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This may seem as a strange question, as blockscout is meant for public networks, but we are using it within our company and we wanted to implement an authentication system around it.
Basically, we have configured 2 nginx servers, one in front of the fronted and another in front of the backend. When a request comes in, we use a subrequest to authenticate it on our authenticator server, redirecting the request and it's cookies, if the answer is 200, nginx allow the request to pass, otherwise, redirect user to login page.
It works perferctly on the frontend page, however it does not work on the backend, because the fetch functions do not use the 'include' option, as can be seen here (that is, the code doesn't forward the cookies) so my frontend can't call the APIs of the backend.
Is there any way to enable the forwarding of cookies? If no, is there any plan of bringing this in the future? How can I suggest this as a feature?
Beta Was this translation helpful? Give feedback.
All reactions