usos-api 0.1.2__tar.gz → 0.1.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.
- {usos_api-0.1.2 → usos_api-0.1.3}/PKG-INFO +1 -1
- {usos_api-0.1.2 → usos_api-0.1.3}/pyproject.toml +1 -1
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/auth.py +8 -1
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/client.py +16 -5
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/services/users.py +1 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/README.md +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/__init__.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/connection.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/exceptions.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/logger.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/models/__init__.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/models/consumer.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/models/course.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/models/grade.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/models/group.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/models/lang_dict.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/models/programme.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/models/term.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/models/user.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/services/__init__.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/services/api_server.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/services/groups.py +0 -0
- {usos_api-0.1.2 → usos_api-0.1.3}/usos_api/utils/__init__.py +0 -0
|
@@ -18,6 +18,7 @@ class AuthManager:
|
|
|
18
18
|
AUTHORIZE_SUFFIX = "services/oauth/authorize"
|
|
19
19
|
ACCESS_TOKEN_SUFFIX = "services/oauth/access_token"
|
|
20
20
|
REVOKE_TOKEN_SUFFIX = "services/oauth/revoke_token"
|
|
21
|
+
# List of available scopes can be found at https://apps.usos.edu.pl/developers/api/authorization/#scopes
|
|
21
22
|
SCOPES = "|".join(["offline_access", "studies"])
|
|
22
23
|
|
|
23
24
|
def __init__(self, api_base_address: str, consumer_key: str, consumer_secret: str):
|
|
@@ -94,13 +95,19 @@ class AuthManager:
|
|
|
94
95
|
self._oauth_client.resource_owner_secret = self._request_token_secret
|
|
95
96
|
_LOGGER.info(f"New request token generated: {self._request_token}")
|
|
96
97
|
|
|
97
|
-
async def get_authorization_url(
|
|
98
|
+
async def get_authorization_url(
|
|
99
|
+
self, callback_url: str, confirm_user: bool = False
|
|
100
|
+
) -> str:
|
|
98
101
|
"""
|
|
99
102
|
Get the authorization URL.
|
|
100
103
|
|
|
101
104
|
:param callback_url: The callback URL.
|
|
105
|
+
:param confirm_user: Whether to confirm the user.
|
|
106
|
+
:return: The authorization URL.
|
|
102
107
|
"""
|
|
103
108
|
await self._generate_request_token(callback_url)
|
|
109
|
+
if confirm_user:
|
|
110
|
+
return f"{self.base_address}{self.AUTHORIZE_SUFFIX}?oauth_token={self._request_token}&interactivity=confirm_user"
|
|
104
111
|
return f"{self.base_address}{self.AUTHORIZE_SUFFIX}?oauth_token={self._request_token}"
|
|
105
112
|
|
|
106
113
|
async def authorize(self, verifier: str, request_token, request_token_secret):
|
|
@@ -94,7 +94,9 @@ class USOSClient:
|
|
|
94
94
|
[s for s in self.connection.auth_manager.SCOPES.split("|") if s != scope]
|
|
95
95
|
)
|
|
96
96
|
|
|
97
|
-
async def authorize(
|
|
97
|
+
async def authorize(
|
|
98
|
+
self, verifier: str, request_token: str = None, request_token_secret: str = None
|
|
99
|
+
) -> tuple[str, str]:
|
|
98
100
|
"""
|
|
99
101
|
Authorize the client with verifier and optionally token and token secret.
|
|
100
102
|
|
|
@@ -105,16 +107,23 @@ class USOSClient:
|
|
|
105
107
|
:param request_token_secret: The OAuth token secret obtained from the previous step.
|
|
106
108
|
:return: The access token and secret.
|
|
107
109
|
"""
|
|
108
|
-
return await self.connection.auth_manager.authorize(
|
|
110
|
+
return await self.connection.auth_manager.authorize(
|
|
111
|
+
verifier, request_token, request_token_secret
|
|
112
|
+
)
|
|
109
113
|
|
|
110
|
-
async def get_authorization_url(
|
|
114
|
+
async def get_authorization_url(
|
|
115
|
+
self, callback_url: str = "oob", confirm_user: bool = False
|
|
116
|
+
) -> str:
|
|
111
117
|
"""
|
|
112
118
|
Get the URL to authorize the client.
|
|
113
119
|
|
|
114
120
|
:param callback_url: The URL to redirect to after authorization, leave as "oob" for pin-based authorization.
|
|
121
|
+
:param confirm_user: Whether to confirm the user before authorizing the client.
|
|
115
122
|
:return: The URL to authorize the client.
|
|
116
123
|
"""
|
|
117
|
-
return await self.connection.auth_manager.get_authorization_url(
|
|
124
|
+
return await self.connection.auth_manager.get_authorization_url(
|
|
125
|
+
callback_url, confirm_user
|
|
126
|
+
)
|
|
118
127
|
|
|
119
128
|
def load_access_token(self, access_token: str, access_token_secret: str):
|
|
120
129
|
"""
|
|
@@ -164,7 +173,9 @@ class USOSClient:
|
|
|
164
173
|
"""
|
|
165
174
|
if not file_path.endswith(".json"):
|
|
166
175
|
raise ValueError("File must be a JSON file.")
|
|
167
|
-
access_token, access_token_secret =
|
|
176
|
+
access_token, access_token_secret = (
|
|
177
|
+
self.connection.auth_manager.get_access_token()
|
|
178
|
+
)
|
|
168
179
|
json_data = {
|
|
169
180
|
"access_token": access_token,
|
|
170
181
|
"access_token_secret": access_token_secret,
|
|
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
|