reflex-google-auth 0.0.1__tar.gz → 0.0.3__tar.gz
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-0.0.3/PKG-INFO +26 -0
- reflex-google-auth-0.0.3/README.md +9 -0
- reflex-google-auth-0.0.3/custom_components/reflex_google_auth/__init__.py +11 -0
- reflex-google-auth-0.0.3/custom_components/reflex_google_auth/decorator.py +25 -0
- reflex-google-auth-0.0.3/custom_components/reflex_google_auth/google_auth.py +34 -0
- reflex-google-auth-0.0.3/custom_components/reflex_google_auth/state.py +63 -0
- reflex-google-auth-0.0.3/custom_components/reflex_google_auth.egg-info/PKG-INFO +26 -0
- {reflex-google-auth-0.0.1 → reflex-google-auth-0.0.3}/custom_components/reflex_google_auth.egg-info/SOURCES.txt +2 -0
- {reflex-google-auth-0.0.1 → reflex-google-auth-0.0.3}/custom_components/reflex_google_auth.egg-info/requires.txt +1 -0
- reflex-google-auth-0.0.3/pyproject.toml +36 -0
- reflex-google-auth-0.0.1/PKG-INFO +0 -74
- reflex-google-auth-0.0.1/README.md +0 -58
- reflex-google-auth-0.0.1/custom_components/reflex_google_auth/__init__.py +0 -1
- reflex-google-auth-0.0.1/custom_components/reflex_google_auth/google_auth.py +0 -34
- reflex-google-auth-0.0.1/custom_components/reflex_google_auth.egg-info/PKG-INFO +0 -74
- reflex-google-auth-0.0.1/pyproject.toml +0 -29
- {reflex-google-auth-0.0.1 → reflex-google-auth-0.0.3}/custom_components/reflex_google_auth.egg-info/dependency_links.txt +0 -0
- {reflex-google-auth-0.0.1 → reflex-google-auth-0.0.3}/custom_components/reflex_google_auth.egg-info/top_level.txt +0 -0
- {reflex-google-auth-0.0.1 → reflex-google-auth-0.0.3}/setup.cfg +0 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: reflex-google-auth
|
3
|
+
Version: 0.0.3
|
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.2
|
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
|
+
```
|
@@ -0,0 +1,11 @@
|
|
1
|
+
from .decorator import require_google_login
|
2
|
+
from .google_auth import google_login, google_oauth_provider
|
3
|
+
from .state import GoogleAuthState, set_client_id
|
4
|
+
|
5
|
+
__all__ = [
|
6
|
+
"GoogleAuthState",
|
7
|
+
"google_oauth_provider",
|
8
|
+
"google_login",
|
9
|
+
"set_client_id",
|
10
|
+
"require_google_login",
|
11
|
+
]
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import functools
|
2
|
+
|
3
|
+
import reflex as rx
|
4
|
+
|
5
|
+
from . import google_auth
|
6
|
+
from .state import GoogleAuthState
|
7
|
+
|
8
|
+
|
9
|
+
def require_google_login(page) -> rx.Component:
|
10
|
+
@functools.wraps(page)
|
11
|
+
def _auth_wrapper() -> rx.Component:
|
12
|
+
return google_auth.google_oauth_provider(
|
13
|
+
rx.cond(
|
14
|
+
rx.State.is_hydrated,
|
15
|
+
rx.cond(
|
16
|
+
GoogleAuthState.token_is_valid,
|
17
|
+
page(),
|
18
|
+
google_auth.google_login(),
|
19
|
+
),
|
20
|
+
),
|
21
|
+
)
|
22
|
+
|
23
|
+
_auth_wrapper.__name__ = page.__name__
|
24
|
+
|
25
|
+
return _auth_wrapper
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import reflex as rx
|
2
|
+
|
3
|
+
from .state import GoogleAuthState
|
4
|
+
|
5
|
+
|
6
|
+
class GoogleOAuthProvider(rx.Component):
|
7
|
+
library = "@react-oauth/google"
|
8
|
+
tag = "GoogleOAuthProvider"
|
9
|
+
|
10
|
+
client_id: rx.Var[str]
|
11
|
+
|
12
|
+
@classmethod
|
13
|
+
def create(cls, *children, **props) -> rx.Component:
|
14
|
+
props.setdefault("client_id", GoogleAuthState.client_id)
|
15
|
+
return super().create(*children, **props)
|
16
|
+
|
17
|
+
|
18
|
+
google_oauth_provider = GoogleOAuthProvider.create
|
19
|
+
|
20
|
+
|
21
|
+
class GoogleLogin(rx.Component):
|
22
|
+
library = "@react-oauth/google"
|
23
|
+
tag = "GoogleLogin"
|
24
|
+
|
25
|
+
def get_event_triggers(self):
|
26
|
+
return {"on_success": lambda data: [data]}
|
27
|
+
|
28
|
+
@classmethod
|
29
|
+
def create(cls, **props) -> "GoogleLogin":
|
30
|
+
props.setdefault("on_success", GoogleAuthState.on_success)
|
31
|
+
return super().create(**props)
|
32
|
+
|
33
|
+
|
34
|
+
google_login = GoogleLogin.create
|
@@ -0,0 +1,63 @@
|
|
1
|
+
"""Handle Google Auth."""
|
2
|
+
|
3
|
+
import json
|
4
|
+
import os
|
5
|
+
import time
|
6
|
+
|
7
|
+
from google.auth.transport import requests
|
8
|
+
from google.oauth2.id_token import verify_oauth2_token
|
9
|
+
|
10
|
+
import reflex as rx
|
11
|
+
|
12
|
+
|
13
|
+
CLIENT_ID = os.environ.get("GOOGLE_CLIENT_ID", "")
|
14
|
+
|
15
|
+
|
16
|
+
def set_client_id(client_id: str):
|
17
|
+
"""Set the client id."""
|
18
|
+
global CLIENT_ID
|
19
|
+
CLIENT_ID = client_id
|
20
|
+
|
21
|
+
|
22
|
+
class GoogleAuthState(rx.State):
|
23
|
+
id_token_json: str = rx.LocalStorage()
|
24
|
+
|
25
|
+
def on_success(self, id_token: dict):
|
26
|
+
self.id_token_json = json.dumps(id_token)
|
27
|
+
|
28
|
+
@rx.cached_var
|
29
|
+
def client_id(self) -> str:
|
30
|
+
return CLIENT_ID
|
31
|
+
|
32
|
+
@rx.cached_var
|
33
|
+
def tokeninfo(self) -> dict[str, str]:
|
34
|
+
try:
|
35
|
+
return verify_oauth2_token(
|
36
|
+
json.loads(self.id_token_json)["credential"],
|
37
|
+
requests.Request(),
|
38
|
+
self.client_id,
|
39
|
+
)
|
40
|
+
except Exception as exc:
|
41
|
+
if self.id_token_json:
|
42
|
+
print(f"Error verifying token: {exc}")
|
43
|
+
return {}
|
44
|
+
|
45
|
+
def logout(self):
|
46
|
+
self.id_token_json = ""
|
47
|
+
|
48
|
+
@rx.var
|
49
|
+
def token_is_valid(self) -> bool:
|
50
|
+
try:
|
51
|
+
return bool(
|
52
|
+
self.tokeninfo and int(self.tokeninfo.get("exp", 0)) > time.time()
|
53
|
+
)
|
54
|
+
except Exception:
|
55
|
+
return False
|
56
|
+
|
57
|
+
@rx.cached_var
|
58
|
+
def user_name(self) -> str:
|
59
|
+
return self.tokeninfo.get("name", "")
|
60
|
+
|
61
|
+
@rx.cached_var
|
62
|
+
def user_email(self) -> str:
|
63
|
+
return self.tokeninfo.get("email", "")
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: reflex-google-auth
|
3
|
+
Version: 0.0.3
|
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.2
|
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,7 +1,9 @@
|
|
1
1
|
README.md
|
2
2
|
pyproject.toml
|
3
3
|
custom_components/reflex_google_auth/__init__.py
|
4
|
+
custom_components/reflex_google_auth/decorator.py
|
4
5
|
custom_components/reflex_google_auth/google_auth.py
|
6
|
+
custom_components/reflex_google_auth/state.py
|
5
7
|
custom_components/reflex_google_auth.egg-info/PKG-INFO
|
6
8
|
custom_components/reflex_google_auth.egg-info/SOURCES.txt
|
7
9
|
custom_components/reflex_google_auth.egg-info/dependency_links.txt
|
@@ -0,0 +1,36 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = [
|
3
|
+
"setuptools",
|
4
|
+
"wheel",
|
5
|
+
]
|
6
|
+
build-backend = "setuptools.build_meta"
|
7
|
+
|
8
|
+
[project]
|
9
|
+
name = "reflex-google-auth"
|
10
|
+
version = "0.0.3"
|
11
|
+
description = "Reflex custom component google-auth"
|
12
|
+
readme = "README.md"
|
13
|
+
license = { text = "Apache-2.0" }
|
14
|
+
requires-python = ">=3.8"
|
15
|
+
authors = [{ name = "Masen Furer", email = "m_github@0x26.net" }]
|
16
|
+
keywords = [
|
17
|
+
"reflex",
|
18
|
+
"reflex-custom-components"]
|
19
|
+
|
20
|
+
dependencies = [
|
21
|
+
"reflex>=0.4.2",
|
22
|
+
"google-auth[requests]",
|
23
|
+
]
|
24
|
+
|
25
|
+
classifiers = [
|
26
|
+
"Development Status :: 4 - Beta",
|
27
|
+
]
|
28
|
+
|
29
|
+
[project.urls]
|
30
|
+
Homepage = "https://github.com/martinxu9/reflex-google-auth"
|
31
|
+
|
32
|
+
[project.optional-dependencies]
|
33
|
+
dev = ["build", "twine"]
|
34
|
+
|
35
|
+
[tool.setuptools.packages.find]
|
36
|
+
where = ["custom_components"]
|
@@ -1,74 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: reflex-google-auth
|
3
|
-
Version: 0.0.1
|
4
|
-
Summary: Reflex custom component google-auth
|
5
|
-
Author-email: Masen Furer <masen@reflex.dev>, Martin Xu <martin@reflex.dev>
|
6
|
-
License: Apache-2.0
|
7
|
-
Project-URL: Homepage, https://reflex.dev
|
8
|
-
Keywords: reflex,reflex-custom-components,oauth,google-auth
|
9
|
-
Classifier: Development Status :: 4 - Beta
|
10
|
-
Requires-Python: >=3.8
|
11
|
-
Description-Content-Type: text/markdown
|
12
|
-
Requires-Dist: reflex>=0.4.2
|
13
|
-
Provides-Extra: dev
|
14
|
-
Requires-Dist: build; extra == "dev"
|
15
|
-
Requires-Dist: twine; extra == "dev"
|
16
|
-
|
17
|
-
# Google-Auth
|
18
|
-
|
19
|
-
A Reflex custom component Google Auth.
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
Please go to this [blog post](https://reflex.dev/blog/2023-10-25-implementing-sign-in-with-google#implementing-sign-in-with-google) for how to use the component in a Reflex App.
|
24
|
-
|
25
|
-
Below is a short code example that goes to Google for authentication and redirects upon success. It still needs code to handle/store the tokens, etc.
|
26
|
-
|
27
|
-
```python
|
28
|
-
from rxconfig import config
|
29
|
-
|
30
|
-
import reflex as rx
|
31
|
-
|
32
|
-
from rx_google_auth import google_auth, google_login
|
33
|
-
from google.auth.transport import requests
|
34
|
-
from google.oauth2.id_token import verify_oauth2_token
|
35
|
-
|
36
|
-
CLIENT_ID = "YOUR_CLIENT_ID"
|
37
|
-
|
38
|
-
class State(rx.State):
|
39
|
-
"""The app state."""
|
40
|
-
|
41
|
-
def on_success(self, id_token: dict):
|
42
|
-
print(
|
43
|
-
verify_oauth2_token(
|
44
|
-
id_token["credential"],
|
45
|
-
requests.Request(),
|
46
|
-
CLIENT_ID,
|
47
|
-
)
|
48
|
-
)
|
49
|
-
|
50
|
-
|
51
|
-
def index() -> rx.Component:
|
52
|
-
return rx.center(
|
53
|
-
rx.theme_panel(),
|
54
|
-
rx.vstack(
|
55
|
-
rx.heading("Welcome to Reflex!", size="9"),
|
56
|
-
rx.text("Test your custom component by editing ", rx.code(filename)),
|
57
|
-
google_auth(
|
58
|
-
google_login(
|
59
|
-
on_success=State.on_success,
|
60
|
-
),
|
61
|
-
client_id=CLIENT_ID,
|
62
|
-
),
|
63
|
-
align="center",
|
64
|
-
spacing="7",
|
65
|
-
font_size="2em",
|
66
|
-
),
|
67
|
-
height="100vh",
|
68
|
-
)
|
69
|
-
|
70
|
-
|
71
|
-
# Add state and page to the app.
|
72
|
-
app = rx.App()
|
73
|
-
app.add_page(index)
|
74
|
-
```
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# Google-Auth
|
2
|
-
|
3
|
-
A Reflex custom component Google Auth.
|
4
|
-
|
5
|
-
## Usage
|
6
|
-
|
7
|
-
Please go to this [blog post](https://reflex.dev/blog/2023-10-25-implementing-sign-in-with-google#implementing-sign-in-with-google) for how to use the component in a Reflex App.
|
8
|
-
|
9
|
-
Below is a short code example that goes to Google for authentication and redirects upon success. It still needs code to handle/store the tokens, etc.
|
10
|
-
|
11
|
-
```python
|
12
|
-
from rxconfig import config
|
13
|
-
|
14
|
-
import reflex as rx
|
15
|
-
|
16
|
-
from rx_google_auth import google_auth, google_login
|
17
|
-
from google.auth.transport import requests
|
18
|
-
from google.oauth2.id_token import verify_oauth2_token
|
19
|
-
|
20
|
-
CLIENT_ID = "YOUR_CLIENT_ID"
|
21
|
-
|
22
|
-
class State(rx.State):
|
23
|
-
"""The app state."""
|
24
|
-
|
25
|
-
def on_success(self, id_token: dict):
|
26
|
-
print(
|
27
|
-
verify_oauth2_token(
|
28
|
-
id_token["credential"],
|
29
|
-
requests.Request(),
|
30
|
-
CLIENT_ID,
|
31
|
-
)
|
32
|
-
)
|
33
|
-
|
34
|
-
|
35
|
-
def index() -> rx.Component:
|
36
|
-
return rx.center(
|
37
|
-
rx.theme_panel(),
|
38
|
-
rx.vstack(
|
39
|
-
rx.heading("Welcome to Reflex!", size="9"),
|
40
|
-
rx.text("Test your custom component by editing ", rx.code(filename)),
|
41
|
-
google_auth(
|
42
|
-
google_login(
|
43
|
-
on_success=State.on_success,
|
44
|
-
),
|
45
|
-
client_id=CLIENT_ID,
|
46
|
-
),
|
47
|
-
align="center",
|
48
|
-
spacing="7",
|
49
|
-
font_size="2em",
|
50
|
-
),
|
51
|
-
height="100vh",
|
52
|
-
)
|
53
|
-
|
54
|
-
|
55
|
-
# Add state and page to the app.
|
56
|
-
app = rx.App()
|
57
|
-
app.add_page(index)
|
58
|
-
```
|
@@ -1 +0,0 @@
|
|
1
|
-
from .google_auth import *
|
@@ -1,34 +0,0 @@
|
|
1
|
-
"""Reflex custom component GoogleAuth."""
|
2
|
-
|
3
|
-
import reflex as rx
|
4
|
-
|
5
|
-
|
6
|
-
class GoogleAuth(rx.Component):
|
7
|
-
"""GoogleAuth component."""
|
8
|
-
|
9
|
-
# The React library to wrap.
|
10
|
-
library = "@react-oauth/google"
|
11
|
-
|
12
|
-
# The React component tag.
|
13
|
-
tag = "GoogleOAuthProvider"
|
14
|
-
|
15
|
-
# The Google OAuth Client ID: guide to how to create one at https://reflex.dev/blog/2023-10-25-implementing-sign-in-with-google#create-a-google-oauth-client-id
|
16
|
-
client_id: rx.Var[str]
|
17
|
-
|
18
|
-
|
19
|
-
class GoogleLogin(rx.Component):
|
20
|
-
"""GoogleLogin component."""
|
21
|
-
|
22
|
-
# The React library to wrap.
|
23
|
-
library = "@react-oauth/google"
|
24
|
-
|
25
|
-
# The React component tag.
|
26
|
-
tag = "GoogleLogin"
|
27
|
-
|
28
|
-
# Event triggers to pass its arguments directly to the Reflex event handler.
|
29
|
-
def get_event_triggers(self):
|
30
|
-
return {"on_success": lambda data: [data]}
|
31
|
-
|
32
|
-
|
33
|
-
google_auth = GoogleAuth.create
|
34
|
-
google_login = GoogleLogin.create
|
@@ -1,74 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: reflex-google-auth
|
3
|
-
Version: 0.0.1
|
4
|
-
Summary: Reflex custom component google-auth
|
5
|
-
Author-email: Masen Furer <masen@reflex.dev>, Martin Xu <martin@reflex.dev>
|
6
|
-
License: Apache-2.0
|
7
|
-
Project-URL: Homepage, https://reflex.dev
|
8
|
-
Keywords: reflex,reflex-custom-components,oauth,google-auth
|
9
|
-
Classifier: Development Status :: 4 - Beta
|
10
|
-
Requires-Python: >=3.8
|
11
|
-
Description-Content-Type: text/markdown
|
12
|
-
Requires-Dist: reflex>=0.4.2
|
13
|
-
Provides-Extra: dev
|
14
|
-
Requires-Dist: build; extra == "dev"
|
15
|
-
Requires-Dist: twine; extra == "dev"
|
16
|
-
|
17
|
-
# Google-Auth
|
18
|
-
|
19
|
-
A Reflex custom component Google Auth.
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
Please go to this [blog post](https://reflex.dev/blog/2023-10-25-implementing-sign-in-with-google#implementing-sign-in-with-google) for how to use the component in a Reflex App.
|
24
|
-
|
25
|
-
Below is a short code example that goes to Google for authentication and redirects upon success. It still needs code to handle/store the tokens, etc.
|
26
|
-
|
27
|
-
```python
|
28
|
-
from rxconfig import config
|
29
|
-
|
30
|
-
import reflex as rx
|
31
|
-
|
32
|
-
from rx_google_auth import google_auth, google_login
|
33
|
-
from google.auth.transport import requests
|
34
|
-
from google.oauth2.id_token import verify_oauth2_token
|
35
|
-
|
36
|
-
CLIENT_ID = "YOUR_CLIENT_ID"
|
37
|
-
|
38
|
-
class State(rx.State):
|
39
|
-
"""The app state."""
|
40
|
-
|
41
|
-
def on_success(self, id_token: dict):
|
42
|
-
print(
|
43
|
-
verify_oauth2_token(
|
44
|
-
id_token["credential"],
|
45
|
-
requests.Request(),
|
46
|
-
CLIENT_ID,
|
47
|
-
)
|
48
|
-
)
|
49
|
-
|
50
|
-
|
51
|
-
def index() -> rx.Component:
|
52
|
-
return rx.center(
|
53
|
-
rx.theme_panel(),
|
54
|
-
rx.vstack(
|
55
|
-
rx.heading("Welcome to Reflex!", size="9"),
|
56
|
-
rx.text("Test your custom component by editing ", rx.code(filename)),
|
57
|
-
google_auth(
|
58
|
-
google_login(
|
59
|
-
on_success=State.on_success,
|
60
|
-
),
|
61
|
-
client_id=CLIENT_ID,
|
62
|
-
),
|
63
|
-
align="center",
|
64
|
-
spacing="7",
|
65
|
-
font_size="2em",
|
66
|
-
),
|
67
|
-
height="100vh",
|
68
|
-
)
|
69
|
-
|
70
|
-
|
71
|
-
# Add state and page to the app.
|
72
|
-
app = rx.App()
|
73
|
-
app.add_page(index)
|
74
|
-
```
|
@@ -1,29 +0,0 @@
|
|
1
|
-
[build-system]
|
2
|
-
requires = ["setuptools", "wheel"]
|
3
|
-
build-backend = "setuptools.build_meta"
|
4
|
-
|
5
|
-
[project]
|
6
|
-
name = "reflex-google-auth"
|
7
|
-
version = "0.0.1"
|
8
|
-
description = "Reflex custom component google-auth"
|
9
|
-
readme = "README.md"
|
10
|
-
license = { text = "Apache-2.0" }
|
11
|
-
requires-python = ">=3.8"
|
12
|
-
authors = [
|
13
|
-
{ name = "Masen Furer", email = "masen@reflex.dev" },
|
14
|
-
{ name = "Martin Xu", email = "martin@reflex.dev" },
|
15
|
-
]
|
16
|
-
keywords = ["reflex", "reflex-custom-components", "oauth", "google-auth"]
|
17
|
-
|
18
|
-
dependencies = ["reflex>=0.4.2"]
|
19
|
-
|
20
|
-
classifiers = ["Development Status :: 4 - Beta"]
|
21
|
-
|
22
|
-
[project.urls]
|
23
|
-
Homepage = "https://reflex.dev"
|
24
|
-
|
25
|
-
[project.optional-dependencies]
|
26
|
-
dev = ["build", "twine"]
|
27
|
-
|
28
|
-
[tool.setuptools.packages.find]
|
29
|
-
where = ["custom_components"]
|
File without changes
|
File without changes
|
File without changes
|