client id and client owner in token model

This commit is contained in:
mahdavi 2024-07-04 15:52:47 +03:30
parent c2fbfd70a9
commit e3c1d010df

View file

@ -125,6 +125,37 @@ class OAuth2Validator(BaseOAuth2Validator): # pylint: disable=w0223
return None
if "active" in content and content["active"] is True:
try:
application_introspection_url = introspection_url.rstrip("/") + "_application/"
response = requests.post(application_introspection_url, data={"client_id": content['client_id']}, headers=headers)
except requests.exceptions.RequestException:
log.exception("Introspection: Failed POST to %r in token lookup", introspection_url)
return None
if response.status_code != http.client.OK:
log.exception(
"Application introspection: Failed to get a valid response "
"from authentication server. Status code: {}, "
"Reason: {}.".format(response.status_code, response.reason)
)
return None
try:
application_introspection_content = response.json()
except ValueError:
log.exception("Introspection: Failed to parse response as json")
return None
client_owner_value = None
if "active" in application_introspection_content and application_introspection_content["active"] is True:
if "client_owner" in application_introspection_content:
client_owner_value = application_introspection_content["client_owner"]
if client_owner_value:
client_owner, _ = UserModel.objects.get_or_create(pk=client_owner_value)
else:
client_owner = None
if "username" in content:
user = self.get_or_create_user_from_content(content)
else:
@ -154,7 +185,7 @@ class OAuth2Validator(BaseOAuth2Validator): # pylint: disable=w0223
defaults={
"user": user,
"client_id": content.get("client_id", ""),
"client_owner": user,
"client_owner": client_owner,
"application": None,
"scope": scope,
"expires": expires,