plain.oauth 0.29.1__tar.gz → 0.30.0__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.
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/PKG-INFO +1 -1
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/CHANGELOG.md +21 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/models.py +11 -10
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/providers.py +1 -1
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/views.py +5 -5
- {plain_oauth-0.29.1/tests/providers → plain_oauth-0.30.0/provider_examples}/bitbucket.py +10 -4
- {plain_oauth-0.29.1/tests/providers → plain_oauth-0.30.0/provider_examples}/github.py +10 -4
- {plain_oauth-0.29.1/tests/providers → plain_oauth-0.30.0/provider_examples}/gitlab.py +11 -4
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/pyproject.toml +1 -1
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/app/users/models.py +4 -3
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/.gitignore +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/LICENSE +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/README.md +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/README.md +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/__init__.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/admin.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/config.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/default_settings.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/exceptions.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/migrations/0001_initial.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/migrations/__init__.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/templates/oauth/callback.html +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/plain/oauth/urls.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/provider_examples/__init__.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/app/settings.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/app/templates/base.html +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/app/templates/index.html +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/app/templates/login.html +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/app/urls.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/app/users/migrations/0001_initial.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/app/users/migrations/__init__.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/provider_tests/__init__.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/provider_tests/test_github.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/providers/__init__.py +0 -0
- {plain_oauth-0.29.1/provider_examples → plain_oauth-0.30.0/tests/providers}/bitbucket.py +0 -0
- {plain_oauth-0.29.1/provider_examples → plain_oauth-0.30.0/tests/providers}/github.py +0 -0
- {plain_oauth-0.29.1/provider_examples → plain_oauth-0.30.0/tests/providers}/gitlab.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/test_backends.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/test_checks.py +0 -0
- {plain_oauth-0.29.1 → plain_oauth-0.30.0}/tests/test_providers.py +0 -0
@@ -1,5 +1,26 @@
|
|
1
1
|
# plain-oauth changelog
|
2
2
|
|
3
|
+
## [0.30.0](https://github.com/dropseed/plain/releases/plain-oauth@0.30.0) (2025-10-07)
|
4
|
+
|
5
|
+
### What's changed
|
6
|
+
|
7
|
+
- Model metadata is now defined using `model_options = models.Options(...)` instead of `class Meta` ([17a378d](https://github.com/dropseed/plain/commit/17a378d), [73ba469](https://github.com/dropseed/plain/commit/73ba469))
|
8
|
+
|
9
|
+
### Upgrade instructions
|
10
|
+
|
11
|
+
- No changes required
|
12
|
+
|
13
|
+
## [0.29.2](https://github.com/dropseed/plain/releases/plain-oauth@0.29.2) (2025-10-06)
|
14
|
+
|
15
|
+
### What's changed
|
16
|
+
|
17
|
+
- Added type annotations to improve IDE and type checker friendliness ([35fb8c4](https://github.com/dropseed/plain/commit/35fb8c4))
|
18
|
+
- Updated provider examples (Bitbucket, GitHub, GitLab) with proper type annotations ([50463b0](https://github.com/dropseed/plain/commit/50463b0))
|
19
|
+
|
20
|
+
### Upgrade instructions
|
21
|
+
|
22
|
+
- No changes required
|
23
|
+
|
3
24
|
## [0.29.1](https://github.com/dropseed/plain/releases/plain-oauth@0.29.1) (2025-10-02)
|
4
25
|
|
5
26
|
### What's changed
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import TYPE_CHECKING
|
1
|
+
from typing import TYPE_CHECKING, Any
|
2
2
|
|
3
3
|
from plain import models
|
4
4
|
from plain.auth import get_user_model
|
@@ -41,16 +41,17 @@ class OAuthConnection(models.Model):
|
|
41
41
|
access_token_expires_at = models.DateTimeField(required=False, allow_null=True)
|
42
42
|
refresh_token_expires_at = models.DateTimeField(required=False, allow_null=True)
|
43
43
|
|
44
|
-
|
45
|
-
constraints
|
44
|
+
model_options = models.Options(
|
45
|
+
constraints=[
|
46
46
|
models.UniqueConstraint(
|
47
47
|
fields=["provider_key", "provider_user_id"],
|
48
48
|
name="plainoauth_oauthconnection_unique_provider_key_user_id",
|
49
49
|
)
|
50
|
-
]
|
51
|
-
ordering
|
50
|
+
],
|
51
|
+
ordering=("provider_key",),
|
52
|
+
)
|
52
53
|
|
53
|
-
def __str__(self):
|
54
|
+
def __str__(self) -> str:
|
54
55
|
return f"{self.provider_key}[{self.user}:{self.provider_user_id}]"
|
55
56
|
|
56
57
|
def refresh_access_token(self) -> None:
|
@@ -69,13 +70,13 @@ class OAuthConnection(models.Model):
|
|
69
70
|
self.set_token_fields(refreshed_oauth_token)
|
70
71
|
self.save()
|
71
72
|
|
72
|
-
def set_token_fields(self, oauth_token: "OAuthToken"):
|
73
|
+
def set_token_fields(self, oauth_token: "OAuthToken") -> None:
|
73
74
|
self.access_token = oauth_token.access_token
|
74
75
|
self.refresh_token = oauth_token.refresh_token
|
75
76
|
self.access_token_expires_at = oauth_token.access_token_expires_at
|
76
77
|
self.refresh_token_expires_at = oauth_token.refresh_token_expires_at
|
77
78
|
|
78
|
-
def set_user_fields(self, oauth_user: "OAuthUser"):
|
79
|
+
def set_user_fields(self, oauth_user: "OAuthUser") -> None:
|
79
80
|
self.provider_user_id = oauth_user.provider_id
|
80
81
|
|
81
82
|
def access_token_expired(self) -> bool:
|
@@ -125,7 +126,7 @@ class OAuthConnection(models.Model):
|
|
125
126
|
def connect(
|
126
127
|
cls,
|
127
128
|
*,
|
128
|
-
user,
|
129
|
+
user: Any,
|
129
130
|
provider_key: str,
|
130
131
|
oauth_token: "OAuthToken",
|
131
132
|
oauth_user: "OAuthUser",
|
@@ -155,7 +156,7 @@ class OAuthConnection(models.Model):
|
|
155
156
|
return connection
|
156
157
|
|
157
158
|
@classmethod
|
158
|
-
def preflight(cls):
|
159
|
+
def preflight(cls) -> list[PreflightResult]:
|
159
160
|
"""
|
160
161
|
A system check for ensuring that provider_keys in the database are also present in settings.
|
161
162
|
"""
|
@@ -40,7 +40,7 @@ class OAuthUser:
|
|
40
40
|
self.provider_id = provider_id # ID on the provider's system
|
41
41
|
self.user_model_fields = user_model_fields or {}
|
42
42
|
|
43
|
-
def __str__(self):
|
43
|
+
def __str__(self) -> str:
|
44
44
|
if "email" in self.user_model_fields:
|
45
45
|
return self.user_model_fields["email"]
|
46
46
|
if "username" in self.user_model_fields:
|
@@ -2,7 +2,7 @@ import logging
|
|
2
2
|
|
3
3
|
from plain.auth.requests import get_request_user
|
4
4
|
from plain.auth.views import AuthViewMixin
|
5
|
-
from plain.http import ResponseRedirect
|
5
|
+
from plain.http import Response, ResponseRedirect
|
6
6
|
from plain.views import TemplateView, View
|
7
7
|
|
8
8
|
from .exceptions import (
|
@@ -14,7 +14,7 @@ logger = logging.getLogger(__name__)
|
|
14
14
|
|
15
15
|
|
16
16
|
class OAuthLoginView(View):
|
17
|
-
def post(self):
|
17
|
+
def post(self) -> Response:
|
18
18
|
request = self.request
|
19
19
|
provider = self.url_kwargs["provider"]
|
20
20
|
if get_request_user(request):
|
@@ -31,7 +31,7 @@ class OAuthCallbackView(TemplateView):
|
|
31
31
|
|
32
32
|
template_name = "oauth/callback.html"
|
33
33
|
|
34
|
-
def get(self):
|
34
|
+
def get(self) -> Response:
|
35
35
|
provider = self.url_kwargs["provider"]
|
36
36
|
provider_instance = get_oauth_provider_instance(provider_key=provider)
|
37
37
|
try:
|
@@ -51,7 +51,7 @@ class OAuthCallbackView(TemplateView):
|
|
51
51
|
|
52
52
|
|
53
53
|
class OAuthConnectView(AuthViewMixin, View):
|
54
|
-
def post(self):
|
54
|
+
def post(self) -> Response:
|
55
55
|
request = self.request
|
56
56
|
provider = self.url_kwargs["provider"]
|
57
57
|
provider_instance = get_oauth_provider_instance(provider_key=provider)
|
@@ -59,7 +59,7 @@ class OAuthConnectView(AuthViewMixin, View):
|
|
59
59
|
|
60
60
|
|
61
61
|
class OAuthDisconnectView(AuthViewMixin, View):
|
62
|
-
def post(self):
|
62
|
+
def post(self) -> Response:
|
63
63
|
request = self.request
|
64
64
|
provider = self.url_kwargs["provider"]
|
65
65
|
provider_instance = get_oauth_provider_instance(provider_key=provider)
|
@@ -1,15 +1,21 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
1
3
|
import datetime
|
4
|
+
from typing import TYPE_CHECKING, Any
|
2
5
|
|
3
6
|
import requests
|
4
7
|
|
5
8
|
from plain.oauth.providers import OAuthProvider, OAuthToken, OAuthUser
|
6
9
|
from plain.utils import timezone
|
7
10
|
|
11
|
+
if TYPE_CHECKING:
|
12
|
+
from plain.http import Request
|
13
|
+
|
8
14
|
|
9
15
|
class BitbucketOAuthProvider(OAuthProvider):
|
10
16
|
authorization_url = "https://bitbucket.org/site/oauth2/authorize"
|
11
17
|
|
12
|
-
def _get_token(self, request_data):
|
18
|
+
def _get_token(self, request_data: dict[str, Any]) -> OAuthToken:
|
13
19
|
response = requests.post(
|
14
20
|
"https://bitbucket.org/site/oauth2/access_token",
|
15
21
|
auth=(self.get_client_id(), self.get_client_secret()),
|
@@ -27,7 +33,7 @@ class BitbucketOAuthProvider(OAuthProvider):
|
|
27
33
|
+ datetime.timedelta(seconds=data["expires_in"]),
|
28
34
|
)
|
29
35
|
|
30
|
-
def get_oauth_token(self, *, code, request):
|
36
|
+
def get_oauth_token(self, *, code: str, request: Request) -> OAuthToken:
|
31
37
|
return self._get_token(
|
32
38
|
{
|
33
39
|
"grant_type": "authorization_code",
|
@@ -36,7 +42,7 @@ class BitbucketOAuthProvider(OAuthProvider):
|
|
36
42
|
}
|
37
43
|
)
|
38
44
|
|
39
|
-
def refresh_oauth_token(self, *, oauth_token):
|
45
|
+
def refresh_oauth_token(self, *, oauth_token: OAuthToken) -> OAuthToken:
|
40
46
|
return self._get_token(
|
41
47
|
{
|
42
48
|
"grant_type": "refresh_token",
|
@@ -44,7 +50,7 @@ class BitbucketOAuthProvider(OAuthProvider):
|
|
44
50
|
}
|
45
51
|
)
|
46
52
|
|
47
|
-
def get_oauth_user(self, *, oauth_token):
|
53
|
+
def get_oauth_user(self, *, oauth_token: OAuthToken) -> OAuthUser:
|
48
54
|
response = requests.get(
|
49
55
|
"https://api.bitbucket.org/2.0/user",
|
50
56
|
headers={
|
@@ -1,4 +1,7 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
1
3
|
import datetime
|
4
|
+
from typing import TYPE_CHECKING, Any
|
2
5
|
|
3
6
|
import requests
|
4
7
|
|
@@ -6,6 +9,9 @@ from plain.oauth.exceptions import OAuthError
|
|
6
9
|
from plain.oauth.providers import OAuthProvider, OAuthToken, OAuthUser
|
7
10
|
from plain.utils import timezone
|
8
11
|
|
12
|
+
if TYPE_CHECKING:
|
13
|
+
from plain.http import Request
|
14
|
+
|
9
15
|
|
10
16
|
class GitHubOAuthProvider(OAuthProvider):
|
11
17
|
authorization_url = "https://github.com/login/oauth/authorize"
|
@@ -14,7 +20,7 @@ class GitHubOAuthProvider(OAuthProvider):
|
|
14
20
|
github_user_url = "https://api.github.com/user"
|
15
21
|
github_emails_url = "https://api.github.com/user/emails"
|
16
22
|
|
17
|
-
def _get_token(self, request_data):
|
23
|
+
def _get_token(self, request_data: dict[str, Any]) -> OAuthToken:
|
18
24
|
response = requests.post(
|
19
25
|
self.github_token_url,
|
20
26
|
headers={
|
@@ -45,7 +51,7 @@ class GitHubOAuthProvider(OAuthProvider):
|
|
45
51
|
|
46
52
|
return oauth_token
|
47
53
|
|
48
|
-
def get_oauth_token(self, *, code, request):
|
54
|
+
def get_oauth_token(self, *, code: str, request: Request) -> OAuthToken:
|
49
55
|
return self._get_token(
|
50
56
|
{
|
51
57
|
"client_id": self.get_client_id(),
|
@@ -54,7 +60,7 @@ class GitHubOAuthProvider(OAuthProvider):
|
|
54
60
|
}
|
55
61
|
)
|
56
62
|
|
57
|
-
def refresh_oauth_token(self, *, oauth_token):
|
63
|
+
def refresh_oauth_token(self, *, oauth_token: OAuthToken) -> OAuthToken:
|
58
64
|
return self._get_token(
|
59
65
|
{
|
60
66
|
"client_id": self.get_client_id(),
|
@@ -64,7 +70,7 @@ class GitHubOAuthProvider(OAuthProvider):
|
|
64
70
|
}
|
65
71
|
)
|
66
72
|
|
67
|
-
def get_oauth_user(self, *, oauth_token):
|
73
|
+
def get_oauth_user(self, *, oauth_token: OAuthToken) -> OAuthUser:
|
68
74
|
response = requests.get(
|
69
75
|
self.github_user_url,
|
70
76
|
headers={
|
@@ -1,12 +1,19 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from typing import TYPE_CHECKING, Any
|
4
|
+
|
1
5
|
import requests
|
2
6
|
|
3
7
|
from plain.oauth.providers import OAuthProvider, OAuthToken, OAuthUser
|
4
8
|
|
9
|
+
if TYPE_CHECKING:
|
10
|
+
from plain.http import Request
|
11
|
+
|
5
12
|
|
6
13
|
class GitLabOAuthProvider(OAuthProvider):
|
7
14
|
authorization_url = "https://gitlab.com/oauth/authorize"
|
8
15
|
|
9
|
-
def _get_token(self, request_data):
|
16
|
+
def _get_token(self, request_data: dict[str, Any]) -> OAuthToken:
|
10
17
|
request_data["client_id"] = self.get_client_id()
|
11
18
|
request_data["client_secret"] = self.get_client_secret()
|
12
19
|
response = requests.post(
|
@@ -24,7 +31,7 @@ class GitLabOAuthProvider(OAuthProvider):
|
|
24
31
|
# expires_in is missing in response?
|
25
32
|
)
|
26
33
|
|
27
|
-
def get_oauth_token(self, *, code, request):
|
34
|
+
def get_oauth_token(self, *, code: str, request: Request) -> OAuthToken:
|
28
35
|
return self._get_token(
|
29
36
|
{
|
30
37
|
"grant_type": "authorization_code",
|
@@ -33,7 +40,7 @@ class GitLabOAuthProvider(OAuthProvider):
|
|
33
40
|
}
|
34
41
|
)
|
35
42
|
|
36
|
-
def refresh_oauth_token(self, *, oauth_token):
|
43
|
+
def refresh_oauth_token(self, *, oauth_token: OAuthToken) -> OAuthToken:
|
37
44
|
return self._get_token(
|
38
45
|
{
|
39
46
|
"grant_type": "refresh_token",
|
@@ -41,7 +48,7 @@ class GitLabOAuthProvider(OAuthProvider):
|
|
41
48
|
}
|
42
49
|
)
|
43
50
|
|
44
|
-
def get_oauth_user(self, *, oauth_token):
|
51
|
+
def get_oauth_user(self, *, oauth_token: OAuthToken) -> OAuthUser:
|
45
52
|
response = requests.get(
|
46
53
|
"https://gitlab.com/api/v4/user",
|
47
54
|
headers={
|
@@ -6,11 +6,12 @@ class User(models.Model):
|
|
6
6
|
email = models.EmailField()
|
7
7
|
username = models.CharField(max_length=100)
|
8
8
|
|
9
|
-
|
10
|
-
constraints
|
9
|
+
model_options = models.Options(
|
10
|
+
constraints=[
|
11
11
|
models.UniqueConstraint(fields=["email"], name="user_unique_email"),
|
12
12
|
models.UniqueConstraint(fields=["username"], name="user_unique_username"),
|
13
|
-
]
|
13
|
+
],
|
14
|
+
)
|
14
15
|
|
15
16
|
def __str__(self):
|
16
17
|
return self.username
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|