Title: Determine Best Auth Solution · Issue #828 · reactive-python/reactpy · GitHub
Open Graph Title: Determine Best Auth Solution · Issue #828 · reactive-python/reactpy
X Title: Determine Best Auth Solution · Issue #828 · reactive-python/reactpy
Description: Current Situation This stems from discussion in #768 As explained in https://github.com/phihos/idom-auth-example-sanic, the problem we need to solve is how to securely authenticate users inside an ReactPy single page application. Usually...
Open Graph Description: Current Situation This stems from discussion in #768 As explained in https://github.com/phihos/idom-auth-example-sanic, the problem we need to solve is how to securely authenticate users inside an ...
X Description: Current Situation This stems from discussion in #768 As explained in https://github.com/phihos/idom-auth-example-sanic, the problem we need to solve is how to securely authenticate users inside an ...
Opengraph URL: https://github.com/reactive-python/reactpy/issues/828
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Determine Best Auth Solution","articleBody":"### Current Situation\r\n\r\nThis stems from discussion in https://github.com/idom-team/idom/discussions/768\r\n\r\nAs explained in https://github.com/phihos/idom-auth-example-sanic, the problem we need to solve is how to securely authenticate users inside an ReactPy single page application. Usually authentication is done via Cookie or Authorization header on each HTTP request. But after the websocket connection has been established no further HTTP requests and therefore no further headers will be sent. However, there are some ways you could try to work around this:\r\n\r\n1. You could push some Javascript via `html.script` that sends a separate auth request to your auth API and then reloads the page to reestablish the websocket connection with new auth headers, but this is kinda ugly. It defeats the purpose of ReactPy not having to write any Javascript and having a visible reload has a negative impact on the user-experience.\r\n\r\n2. You could also render the login page traditionally and then redirect to a new page with [embedded ReactPy](https://reactpy.dev/docs/guides/getting-started/running-reactpy.html?highlight=embed#embed-in-an-existing-webpage) . But then you already split your application into two parts: \"pre-auth\" with traditional server-side template rendering and \"post-auth\" with ReactPy. Keeping both parts consistent is probably not fun.\r\n\r\n3. You can also do authentication inside the single page app and save the auth state via `use_state`. But it will be gone as soon as a websocket disconnect happens. You can mitigate this by pushing some Javascript that sets a session cookie. But now there is a new problem: Session cookies should be set with the `HttpOnly` flag to prevent XSS attacks from recovering the session cookie. This can not be done (or at least is difficult to do) with Javascript. So you might end up with a security flaw in your app.\r\n\r\n4. Since you have at least one full HTTP request-response cycle you can set a session cookie with a session ID on that response if the request does not already contain a cookie with a valid session ID. That ensures that the following request for the websocket connection always contains a session ID cookie. With `use_request` we can extract the session ID and then the server can retrieve the session data. In that data we can look up the authentication state and let ReactPy display a login form or the actual content. We can later manipulate the session data to perform a login or logout. All without the need to set a further cookie or push Javascript - provided we implement a server-side session. A rough prototype for this [has been implemented here](https://github.com/reactive-python/reactpy/pull/771) based on work done in https://github.com/phihos/idom-auth-example-sanic. \r\n\r\n### Proposed Actions\r\n\r\nExplore the viability of each option.","author":{"url":"https://github.com/rmorshea","@type":"Person","name":"rmorshea"},"datePublished":"2022-11-01T19:13:28.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":19},"url":"https://github.com/828/reactpy/issues/828"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:370d5475-74ad-b7b5-bb29-b76d03945e92 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC00:14AB50:E76B810:12D6DB10:697729E5 |
| html-safe-nonce | ae1b9867c47940a77f2ccc449757d583153e90936fc8f2a82d3ee05701665211 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzAwOjE0QUI1MDpFNzZCODEwOjEyRDZEQjEwOjY5NzcyOUU1IiwidmlzaXRvcl9pZCI6IjUxMDg1ODgxNTU1MTg3OTAxMTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b3bbd84bd9418490a22e063f95147933448a071f6126a764727d444949138905 |
| hovercard-subject-tag | issue:1431951276 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/reactive-python/reactpy/828/issue_layout |
| twitter:image | https://opengraph.githubassets.com/504af503124a82218a390e4e6586dcee1b0d97fefda31243c1c45add2a528754/reactive-python/reactpy/issues/828 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/504af503124a82218a390e4e6586dcee1b0d97fefda31243c1c45add2a528754/reactive-python/reactpy/issues/828 |
| og:image:alt | Current Situation This stems from discussion in #768 As explained in https://github.com/phihos/idom-auth-example-sanic, the problem we need to solve is how to securely authenticate users inside an ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rmorshea |
| hostname | github.com |
| expected-hostname | github.com |
| None | 01d198479908d09a841b2febe8eb105a81af2af7d81830960fe0971e1f4adc09 |
| turbo-cache-control | no-preview |
| go-import | github.com/reactive-python/reactpy git https://github.com/reactive-python/reactpy.git |
| octolytics-dimension-user_id | 106191177 |
| octolytics-dimension-user_login | reactive-python |
| octolytics-dimension-repository_id | 171410703 |
| octolytics-dimension-repository_nwo | reactive-python/reactpy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 171410703 |
| octolytics-dimension-repository_network_root_nwo | reactive-python/reactpy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f752335dbbea672610081196a1998e39aec5e14b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width