reflex-google-auth 0.0.4__py3-none-any.whl → 0.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reflex_google_auth/state.py +6 -6
- reflex_google_auth-0.0.6.dist-info/METADATA +91 -0
- reflex_google_auth-0.0.6.dist-info/RECORD +8 -0
- {reflex_google_auth-0.0.4.dist-info → reflex_google_auth-0.0.6.dist-info}/WHEEL +1 -1
- reflex_google_auth/google_auth.pyi +0 -24
- reflex_google_auth-0.0.4.dist-info/METADATA +0 -26
- reflex_google_auth-0.0.4.dist-info/RECORD +0 -9
- {reflex_google_auth-0.0.4.dist-info → reflex_google_auth-0.0.6.dist-info}/top_level.txt +0 -0
reflex_google_auth/state.py
CHANGED
@@ -10,7 +10,7 @@ from google.oauth2.id_token import verify_oauth2_token
|
|
10
10
|
import reflex as rx
|
11
11
|
|
12
12
|
|
13
|
-
CLIENT_ID =
|
13
|
+
CLIENT_ID = None
|
14
14
|
|
15
15
|
|
16
16
|
def set_client_id(client_id: str):
|
@@ -25,11 +25,11 @@ class GoogleAuthState(rx.State):
|
|
25
25
|
def on_success(self, id_token: dict):
|
26
26
|
self.id_token_json = json.dumps(id_token)
|
27
27
|
|
28
|
-
@rx.
|
28
|
+
@rx.var(cache=True)
|
29
29
|
def client_id(self) -> str:
|
30
|
-
return CLIENT_ID
|
30
|
+
return CLIENT_ID or os.environ.get("GOOGLE_CLIENT_ID", "")
|
31
31
|
|
32
|
-
@rx.
|
32
|
+
@rx.var(cache=True)
|
33
33
|
def tokeninfo(self) -> dict[str, str]:
|
34
34
|
try:
|
35
35
|
return verify_oauth2_token(
|
@@ -54,10 +54,10 @@ class GoogleAuthState(rx.State):
|
|
54
54
|
except Exception:
|
55
55
|
return False
|
56
56
|
|
57
|
-
@rx.
|
57
|
+
@rx.var(cache=True)
|
58
58
|
def user_name(self) -> str:
|
59
59
|
return self.tokeninfo.get("name", "")
|
60
60
|
|
61
|
-
@rx.
|
61
|
+
@rx.var(cache=True)
|
62
62
|
def user_email(self) -> str:
|
63
63
|
return self.tokeninfo.get("email", "")
|
@@ -0,0 +1,91 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: reflex-google-auth
|
3
|
+
Version: 0.0.6
|
4
|
+
Summary: Sign in with Google
|
5
|
+
Author-email: Masen Furer <m_github@0x26.net>
|
6
|
+
License: Apache-2.0
|
7
|
+
Project-URL: homepage, https://github.com/masenf/reflex-google-auth
|
8
|
+
Keywords: reflex,reflex-custom-components
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
10
|
+
Requires-Python: >=3.8
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
Requires-Dist: reflex>=0.4.6
|
13
|
+
Requires-Dist: google-auth[requests]
|
14
|
+
Provides-Extra: dev
|
15
|
+
Requires-Dist: build; extra == "dev"
|
16
|
+
Requires-Dist: twine; extra == "dev"
|
17
|
+
|
18
|
+
# google-auth
|
19
|
+
|
20
|
+
Sign in with Google.
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
```bash
|
25
|
+
pip install reflex-google-auth
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
### Create Google OAuth2 Client ID
|
31
|
+
|
32
|
+
Head over to https://console.developers.google.com/apis/credentials and sign in with the Google account that should manage the app and credential tokens.
|
33
|
+
|
34
|
+
- Click "Create Project" and give it a name. After creation the new project should be selected.
|
35
|
+
- Click "Configure Consent Screen", Choose "External", then Create.
|
36
|
+
- Enter App Name and User Support Email -- these will be shown to users when logging in
|
37
|
+
- Scroll all the way down to "Developer contact information" and add your email address, click "Save and Continue"
|
38
|
+
- Click "Add or Remove Scopes"
|
39
|
+
- Select "Email", "Profile", and "OpenID Connect"
|
40
|
+
- Click "Update", then "Save and Continue"
|
41
|
+
- Add any test users that should be able to log in during development.
|
42
|
+
- From the "Credentials" page, click "+ Create Credentials", then "OAuth client ID"
|
43
|
+
- Select Application Type: "Web Application"
|
44
|
+
- Add Authorized Javascript Origins: http://localhost, http://localhost:3000, https://example.com (prod domain must be HTTPS)
|
45
|
+
- Click "Save"
|
46
|
+
- Copy the OAuth "Client ID" and save it for later. Mine looks like 309209880368-4uqd9e44h7t4alhhdqn48pvvr63cc5j5.apps.googleusercontent.com
|
47
|
+
|
48
|
+
https://github.com/reflex-dev/reflex-examples/assets/1524005/af2499a6-0bda-4d60-b52b-4f51b7322fd5
|
49
|
+
|
50
|
+
### Integrate with Reflex app
|
51
|
+
|
52
|
+
The `GoogleAuthState` provided by this component has a `token_is_valid` var that
|
53
|
+
should be checked before returning any protected content.
|
54
|
+
|
55
|
+
Additionally the `GoogleAuthState.tokeninfo` dict contains the user's profile information.
|
56
|
+
|
57
|
+
```python
|
58
|
+
from reflex_google_auth import GoogleAuthState, require_google_login
|
59
|
+
|
60
|
+
|
61
|
+
class State(GoogleAuthState):
|
62
|
+
@rx.var(cache=True)
|
63
|
+
def protected_content(self) -> str:
|
64
|
+
if self.token_is_valid:
|
65
|
+
return f"This content can only be viewed by a logged in User. Nice to see you {self.tokeninfo['name']}"
|
66
|
+
return "Not logged in."
|
67
|
+
```
|
68
|
+
|
69
|
+
The convenience decorator, `require_google_login`, can wrap an existing component, and
|
70
|
+
show the "Sign in with Google" button if the user is not already authenticated. It can be
|
71
|
+
used on a page function or any subcomponent function of the page.
|
72
|
+
|
73
|
+
The "Sign in with Google" button can also be displayed via `google_login()`:
|
74
|
+
|
75
|
+
```python
|
76
|
+
from reflex_google_auth import google_login, google_oauth_provider
|
77
|
+
|
78
|
+
def page():
|
79
|
+
return rx.div(
|
80
|
+
google_oauth_provider(
|
81
|
+
google_login(),
|
82
|
+
),
|
83
|
+
)
|
84
|
+
```
|
85
|
+
|
86
|
+
To uniquely identify a user, the `GoogleAuthState.tokeninfo['sub']` field can be used.
|
87
|
+
|
88
|
+
See the example in
|
89
|
+
[masenf/rx_shout](https://github.com/masenf/rx_shout/blob/main/rx_shout/state.py)
|
90
|
+
for how to integrate an authenticated Google user with other app-specific user
|
91
|
+
data.
|
@@ -0,0 +1,8 @@
|
|
1
|
+
reflex_google_auth/__init__.py,sha256=StBRDVUPCsMwOVRRgvb_WdzoDkSZoq2RLOoe-YsBExE,291
|
2
|
+
reflex_google_auth/decorator.py,sha256=70gaOYTupWTE1m0hd2D8TvcoP0CUNVxtBdezurzXtMM,594
|
3
|
+
reflex_google_auth/google_auth.py,sha256=gEL68F4M77gS5bfG4GVojvIuq8fKx8XpAQ1cIIU6-pk,794
|
4
|
+
reflex_google_auth/state.py,sha256=IVsHpaI-ahcVNWTCyZGzA9g9mbcansKH3wrxGCV17R0,1514
|
5
|
+
reflex_google_auth-0.0.6.dist-info/METADATA,sha256=LThWAPOIhA7ujUweuhOIefAcDKnAVD1iBjI_cb1stYI,3337
|
6
|
+
reflex_google_auth-0.0.6.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
7
|
+
reflex_google_auth-0.0.6.dist-info/top_level.txt,sha256=JB7Letu_7VOfOx5EhyGn_bElQjzSq43-LHafE90wqyM,19
|
8
|
+
reflex_google_auth-0.0.6.dist-info/RECORD,,
|
@@ -1,24 +0,0 @@
|
|
1
|
-
from typing import Any, Dict, Literal, Optional, Union, overload
|
2
|
-
from reflex.vars import Var, BaseVar, ComputedVar
|
3
|
-
from reflex.event import EventChain, EventHandler, EventSpec
|
4
|
-
from reflex.style import Style
|
5
|
-
import reflex as rx
|
6
|
-
from .state import GoogleAuthState
|
7
|
-
|
8
|
-
class GoogleOAuthProvider(rx.Component):
|
9
|
-
|
10
|
-
@overload
|
11
|
-
@classmethod
|
12
|
-
def create(cls, *children, client_id: Optional[Union[Var[str], str]]=None, style: Optional[Style]=None, key: Optional[Any]=None, id: Optional[Any]=None, class_name: Optional[Any]=None, autofocus: Optional[bool]=None, custom_attrs: Optional[Dict[str, Union[Var, str]]]=None, on_blur: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_click: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_context_menu: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_double_click: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_focus: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mount: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_down: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_enter: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_leave: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_move: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_out: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_over: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_up: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_scroll: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_unmount: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, **props) -> 'GoogleOAuthProvider':
|
13
|
-
""""""
|
14
|
-
...
|
15
|
-
google_oauth_provider = GoogleOAuthProvider.create
|
16
|
-
|
17
|
-
class GoogleLogin(rx.Component):
|
18
|
-
|
19
|
-
@overload
|
20
|
-
@classmethod
|
21
|
-
def create(cls, *children, on_success: Optional[EventHandler[Any]]=None, style: Optional[Style]=None, key: Optional[Any]=None, id: Optional[Any]=None, class_name: Optional[Any]=None, autofocus: Optional[bool]=None, custom_attrs: Optional[Dict[str, Union[Var, str]]]=None, on_blur: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_click: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_context_menu: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_double_click: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_focus: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mount: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_down: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_enter: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_leave: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_move: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_out: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_over: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_mouse_up: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_scroll: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_success: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, on_unmount: Optional[Union[EventHandler, EventSpec, list, function, BaseVar]]=None, **props) -> 'GoogleLogin':
|
22
|
-
""""""
|
23
|
-
...
|
24
|
-
google_login = GoogleLogin.create
|
@@ -1,26 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: reflex-google-auth
|
3
|
-
Version: 0.0.4
|
4
|
-
Summary: Reflex custom component google-auth
|
5
|
-
Author-email: Masen Furer <m_github@0x26.net>
|
6
|
-
License: Apache-2.0
|
7
|
-
Project-URL: Homepage, https://github.com/martinxu9/reflex-google-auth
|
8
|
-
Keywords: reflex,reflex-custom-components
|
9
|
-
Classifier: Development Status :: 4 - Beta
|
10
|
-
Requires-Python: >=3.8
|
11
|
-
Description-Content-Type: text/markdown
|
12
|
-
Requires-Dist: reflex >=0.4.6a
|
13
|
-
Requires-Dist: google-auth[requests]
|
14
|
-
Provides-Extra: dev
|
15
|
-
Requires-Dist: build ; extra == 'dev'
|
16
|
-
Requires-Dist: twine ; extra == 'dev'
|
17
|
-
|
18
|
-
# google-auth
|
19
|
-
|
20
|
-
A Reflex custom component google-auth.
|
21
|
-
|
22
|
-
## Installation
|
23
|
-
|
24
|
-
```bash
|
25
|
-
pip install reflex-google-auth
|
26
|
-
```
|
@@ -1,9 +0,0 @@
|
|
1
|
-
reflex_google_auth/__init__.py,sha256=StBRDVUPCsMwOVRRgvb_WdzoDkSZoq2RLOoe-YsBExE,291
|
2
|
-
reflex_google_auth/decorator.py,sha256=70gaOYTupWTE1m0hd2D8TvcoP0CUNVxtBdezurzXtMM,594
|
3
|
-
reflex_google_auth/google_auth.py,sha256=gEL68F4M77gS5bfG4GVojvIuq8fKx8XpAQ1cIIU6-pk,794
|
4
|
-
reflex_google_auth/google_auth.pyi,sha256=qXp-LeMhQ-pt0JjHb2zTCn8oLU8YMt28gMYZTBvcdDE,3800
|
5
|
-
reflex_google_auth/state.py,sha256=q3C-tb4z4wfKCbRLsJ6JJuVy1MrTGptYnobo1jyKmuU,1486
|
6
|
-
reflex_google_auth-0.0.4.dist-info/METADATA,sha256=SgpLp2os4fTa0Bt7CYztgi2_E-c82jMVnXMGctJ7v1A,672
|
7
|
-
reflex_google_auth-0.0.4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
8
|
-
reflex_google_auth-0.0.4.dist-info/top_level.txt,sha256=JB7Letu_7VOfOx5EhyGn_bElQjzSq43-LHafE90wqyM,19
|
9
|
-
reflex_google_auth-0.0.4.dist-info/RECORD,,
|
File without changes
|