plain.oauth 0.20.0__py3-none-any.whl → 0.21.0__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.
- plain/oauth/README.md +6 -4
- plain/oauth/models.py +4 -4
- plain/oauth/providers.py +7 -7
- plain/oauth/views.py +3 -2
- {plain_oauth-0.20.0.dist-info → plain_oauth-0.21.0.dist-info}/METADATA +7 -5
- {plain_oauth-0.20.0.dist-info → plain_oauth-0.21.0.dist-info}/RECORD +8 -8
- {plain_oauth-0.20.0.dist-info → plain_oauth-0.21.0.dist-info}/WHEEL +0 -0
- {plain_oauth-0.20.0.dist-info → plain_oauth-0.21.0.dist-info}/licenses/LICENSE +0 -0
plain/oauth/README.md
CHANGED
@@ -89,10 +89,12 @@ class ExampleOAuthProvider(OAuthProvider):
|
|
89
89
|
data = response.json()
|
90
90
|
return OAuthUser(
|
91
91
|
# The provider ID is required
|
92
|
-
|
93
|
-
#
|
94
|
-
|
95
|
-
|
92
|
+
provider_id=data["id"],
|
93
|
+
# Populate your User model fields using the user_model_fields dict
|
94
|
+
user_model_fields={
|
95
|
+
"email": data["email"],
|
96
|
+
"username": data["username"],
|
97
|
+
},
|
96
98
|
)
|
97
99
|
```
|
98
100
|
|
plain/oauth/models.py
CHANGED
@@ -76,7 +76,7 @@ class OAuthConnection(models.Model):
|
|
76
76
|
self.refresh_token_expires_at = oauth_token.refresh_token_expires_at
|
77
77
|
|
78
78
|
def set_user_fields(self, oauth_user: "OAuthUser"):
|
79
|
-
self.provider_user_id = oauth_user.
|
79
|
+
self.provider_user_id = oauth_user.provider_id
|
80
80
|
|
81
81
|
def access_token_expired(self) -> bool:
|
82
82
|
return (
|
@@ -97,7 +97,7 @@ class OAuthConnection(models.Model):
|
|
97
97
|
try:
|
98
98
|
connection = cls.objects.get(
|
99
99
|
provider_key=provider_key,
|
100
|
-
provider_user_id=oauth_user.
|
100
|
+
provider_user_id=oauth_user.provider_id,
|
101
101
|
)
|
102
102
|
connection.set_token_fields(oauth_token)
|
103
103
|
connection.save()
|
@@ -137,7 +137,7 @@ class OAuthConnection(models.Model):
|
|
137
137
|
connection = cls.objects.get(
|
138
138
|
user=user,
|
139
139
|
provider_key=provider_key,
|
140
|
-
provider_user_id=oauth_user.
|
140
|
+
provider_user_id=oauth_user.provider_id,
|
141
141
|
)
|
142
142
|
except cls.DoesNotExist:
|
143
143
|
# Create our own instance (not using get_or_create)
|
@@ -145,7 +145,7 @@ class OAuthConnection(models.Model):
|
|
145
145
|
connection = cls(
|
146
146
|
user=user,
|
147
147
|
provider_key=provider_key,
|
148
|
-
provider_user_id=oauth_user.
|
148
|
+
provider_user_id=oauth_user.provider_id,
|
149
149
|
)
|
150
150
|
|
151
151
|
connection.set_user_fields(oauth_user)
|
plain/oauth/providers.py
CHANGED
@@ -24,8 +24,8 @@ class OAuthToken:
|
|
24
24
|
*,
|
25
25
|
access_token: str,
|
26
26
|
refresh_token: str = "",
|
27
|
-
access_token_expires_at: datetime.datetime = None,
|
28
|
-
refresh_token_expires_at: datetime.datetime = None,
|
27
|
+
access_token_expires_at: datetime.datetime | None = None,
|
28
|
+
refresh_token_expires_at: datetime.datetime | None = None,
|
29
29
|
):
|
30
30
|
self.access_token = access_token
|
31
31
|
self.refresh_token = refresh_token
|
@@ -34,16 +34,16 @@ class OAuthToken:
|
|
34
34
|
|
35
35
|
|
36
36
|
class OAuthUser:
|
37
|
-
def __init__(self, *,
|
38
|
-
self.
|
39
|
-
self.user_model_fields = user_model_fields
|
37
|
+
def __init__(self, *, provider_id: str, user_model_fields: dict | None = None):
|
38
|
+
self.provider_id = provider_id # ID on the provider's system
|
39
|
+
self.user_model_fields = user_model_fields or {}
|
40
40
|
|
41
41
|
def __str__(self):
|
42
42
|
if "email" in self.user_model_fields:
|
43
43
|
return self.user_model_fields["email"]
|
44
44
|
if "username" in self.user_model_fields:
|
45
45
|
return self.user_model_fields["username"]
|
46
|
-
return str(self.
|
46
|
+
return str(self.provider_id)
|
47
47
|
|
48
48
|
|
49
49
|
class OAuthProvider:
|
@@ -181,7 +181,7 @@ class OAuthProvider:
|
|
181
181
|
redirect_url = self.get_login_redirect_url(request=request)
|
182
182
|
return self.get_redirect_response(redirect_url)
|
183
183
|
|
184
|
-
def login(self, *, request: HttpRequest, user: Any) ->
|
184
|
+
def login(self, *, request: HttpRequest, user: Any) -> None:
|
185
185
|
auth_login(request=request, user=user)
|
186
186
|
|
187
187
|
def get_login_redirect_url(self, *, request: HttpRequest) -> str:
|
plain/oauth/views.py
CHANGED
@@ -39,8 +39,9 @@ class OAuthCallbackView(TemplateView):
|
|
39
39
|
logger.exception("OAuth error")
|
40
40
|
self.oauth_error = e
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
response = super().get()
|
43
|
+
response.status_code = 400
|
44
|
+
return response
|
44
45
|
|
45
46
|
def get_template_context(self) -> dict:
|
46
47
|
context = super().get_template_context()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: plain.oauth
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.21.0
|
4
4
|
Summary: OAuth login and API access for Plain.
|
5
5
|
Author-email: Dave Gaeddert <dave.gaeddert@dropseed.dev>
|
6
6
|
License-Expression: BSD-3-Clause
|
@@ -103,10 +103,12 @@ class ExampleOAuthProvider(OAuthProvider):
|
|
103
103
|
data = response.json()
|
104
104
|
return OAuthUser(
|
105
105
|
# The provider ID is required
|
106
|
-
|
107
|
-
#
|
108
|
-
|
109
|
-
|
106
|
+
provider_id=data["id"],
|
107
|
+
# Populate your User model fields using the user_model_fields dict
|
108
|
+
user_model_fields={
|
109
|
+
"email": data["email"],
|
110
|
+
"username": data["username"],
|
111
|
+
},
|
110
112
|
)
|
111
113
|
```
|
112
114
|
|
@@ -1,13 +1,13 @@
|
|
1
|
-
plain/oauth/README.md,sha256=
|
1
|
+
plain/oauth/README.md,sha256=N8getAUUhLX6P4mg-5P0V41gk5EKBGb8v904OfP2Z9E,9961
|
2
2
|
plain/oauth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
plain/oauth/admin.py,sha256=rqrGRRUVxOlG9wiuXtndIyQxd1VT67cvFy6qWo7LF-Q,1278
|
4
4
|
plain/oauth/config.py,sha256=0Q4IILBKQbIaxqeL9WRTH5Cka-BO3c3SOj1AdQIAJgc,167
|
5
5
|
plain/oauth/default_settings.py,sha256=dlN1J9vSOjjxPNLp-0qe-cLTqwM4E69ZAx_8lpxMhaM,28
|
6
6
|
plain/oauth/exceptions.py,sha256=yoZsq8XgzstuwbE2ihoet0nzpw_sVZgDrwUauh6hhUs,546
|
7
|
-
plain/oauth/models.py,sha256=
|
8
|
-
plain/oauth/providers.py,sha256=
|
7
|
+
plain/oauth/models.py,sha256=_DS8Mv-dn_a9EO63aNb8oV8jxXUgHkoytrMkBritVhQ,6916
|
8
|
+
plain/oauth/providers.py,sha256=YDftJUMyyfXgsDCkyTNxGwrbwXAowL0Hg6KrwrAN5S0,7793
|
9
9
|
plain/oauth/urls.py,sha256=FYzpQwhvZdcat8n3f7RyA-1Q21finKb8JEyakSOjXXg,696
|
10
|
-
plain/oauth/views.py,sha256=
|
10
|
+
plain/oauth/views.py,sha256=J2NCa37YediBTi82CfRlmsb45hFT6gWN6zMaFHhsDMM,2410
|
11
11
|
plain/oauth/migrations/0001_initial.py,sha256=B9Finbn7ijEIUbkDy_B7UsKQLfMWaXd0Kx3oZrUENWc,1753
|
12
12
|
plain/oauth/migrations/0002_alter_oauthconnection_options_and_more.py,sha256=3Mb0IU9KDRQfog0PjVbzuNv_AxCs7UVHnA0F263AKNo,581
|
13
13
|
plain/oauth/migrations/0003_alter_oauthconnection_access_token_and_more.py,sha256=FyLfwxc2pRzF-CbdRFQRRSQTOCxc9l1womgStygm_lo,629
|
@@ -17,7 +17,7 @@ plain/oauth/migrations/0006_remove_oauthconnection_unique_oauth_provider_user_id
|
|
17
17
|
plain/oauth/migrations/0007_alter_oauthconnection_provider_key_and_more.py,sha256=B_LW6xG1o_uA13tqUs0KniXl1JBNbQu4wMh2pW8rq5I,675
|
18
18
|
plain/oauth/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
19
|
plain/oauth/templates/oauth/callback.html,sha256=4CJG0oAN0xYjw2IPkjaL7B4hwlf9um9LI4CTu50E-yE,173
|
20
|
-
plain_oauth-0.
|
21
|
-
plain_oauth-0.
|
22
|
-
plain_oauth-0.
|
23
|
-
plain_oauth-0.
|
20
|
+
plain_oauth-0.21.0.dist-info/METADATA,sha256=mdMZjbi7Tp69z0XeUxO2jDUEdLQpZcWqT7dseHafO0Y,10365
|
21
|
+
plain_oauth-0.21.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
22
|
+
plain_oauth-0.21.0.dist-info/licenses/LICENSE,sha256=cvKM3OlqHx3ijD6e34zsSUkPvzl-ya3Dd63A6EHL94U,1500
|
23
|
+
plain_oauth-0.21.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|