Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion social_core/backends/amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
https://python-social-auth.readthedocs.io/en/latest/backends/amazon.html
"""

from typing import Any

from .oauth import BaseOAuth2


Expand Down Expand Up @@ -31,7 +33,7 @@ def get_user_details(self, response):
"last_name": last_name,
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Grab user profile information from amazon."""
response = self.get_json(
"https://api.amazon.com/user/profile", params={"access_token": access_token}
Expand Down
4 changes: 3 additions & 1 deletion social_core/backends/angel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
https://python-social-auth.readthedocs.io/en/latest/backends/angel.html
"""

from typing import Any

from .oauth import BaseOAuth2


Expand All @@ -25,7 +27,7 @@ def get_user_details(self, response):
"email": email,
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Loads user data from service"""
return self.get_json(
"https://api.angel.co/1/me/", params={"access_token": access_token}
Expand Down
4 changes: 3 additions & 1 deletion social_core/backends/appsfuel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
https://python-social-auth.readthedocs.io/en/latest/backends/appsfuel.html
"""

from typing import Any

from .oauth import BaseOAuth2


Expand All @@ -28,7 +30,7 @@ def get_user_details(self, response):
"email": email,
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Loads user data from service"""
return self.get_json(
self.USER_DETAILS_URL, params={"access_token": access_token}
Expand Down
4 changes: 3 additions & 1 deletion social_core/backends/arcgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
ArcGIS OAuth2 backend
"""

from typing import Any

from .oauth import BaseOAuth2


Expand All @@ -22,7 +24,7 @@ def get_user_details(self, response):
"last_name": response.get("lastName"),
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Loads user data from service"""
return self.get_json(
"https://www.arcgis.com/sharing/rest/community/self",
Expand Down
2 changes: 1 addition & 1 deletion social_core/backends/asana.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_user_details(self, response):
"first_name": first_name,
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
return self.get_json(
self.USER_DATA_URL, headers={"Authorization": f"Bearer {access_token}"}
)
Expand Down
4 changes: 3 additions & 1 deletion social_core/backends/atlassian.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from social_core.backends.oauth import BaseOAuth2


Expand Down Expand Up @@ -28,7 +30,7 @@ def get_user_details(self, response):
"last_name": last_name,
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
resources = self.get_json(
"https://api.atlassian.com/oauth/token/accessible-resources",
headers={"Authorization": f"Bearer {access_token}"},
Expand Down
2 changes: 1 addition & 1 deletion social_core/backends/azuread.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_user_details(self, response):
"last_name": last_name,
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
response = kwargs.get("response")
if response and response.get("id_token"):
id_token = response.get("id_token")
Expand Down
2 changes: 1 addition & 1 deletion social_core/backends/azuread_b2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def get_public_key(self, kid):
return self.jwt_key_to_pem(key)
raise DecodeError(f"Cannot find kid={kid}")

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
response = kwargs["response"]

id_token = response["id_token"]
Expand Down
3 changes: 2 additions & 1 deletion social_core/backends/azuread_tenant.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
from typing import Any

from cryptography.hazmat.backends import default_backend
from cryptography.x509 import load_der_x509_certificate
Expand Down Expand Up @@ -85,7 +86,7 @@ def get_user_id(self, details, response):
"""Use subject (sub) claim as unique id."""
return response.get("sub")

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
response = kwargs.get("response")
if response and response.get("id_token"):
id_token = response.get("id_token")
Expand Down
4 changes: 3 additions & 1 deletion social_core/backends/battlenet.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from .oauth import BaseOAuth2

# This provides a backend for python-social-auth. This should not be confused
Expand Down Expand Up @@ -40,7 +42,7 @@ def get_user_details(self, response):
"""Return user details from Battle.net account"""
return {"battletag": response.get("battletag")}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Loads user data from service"""
return self.get_json(
"https://eu.api.battle.net/account/user",
Expand Down
4 changes: 3 additions & 1 deletion social_core/backends/beats.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
https://developer.beatsmusic.com/docs
"""

from typing import Any

from social_core.exceptions import AuthUnknownError
from social_core.utils import handle_http_errors

Expand Down Expand Up @@ -57,7 +59,7 @@ def get_user_details(self, response):
"last_name": last_name,
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Loads user data from service"""
return self.get_json(
"https://partner.api.beatsmusic.com/v1/api/me",
Expand Down
4 changes: 3 additions & 1 deletion social_core/backends/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from __future__ import annotations

from typing import Any

from social_core.exceptions import AuthForbidden

from .oauth import BaseOAuth2
Expand Down Expand Up @@ -42,7 +44,7 @@ def get_user_details(self, response):
"last_name": last_name,
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Return user data provided"""
emails = self._get_emails(access_token)
email = None
Expand Down
4 changes: 3 additions & 1 deletion social_core/backends/bitbucket_datacenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
https://confluence.atlassian.com/bitbucketserver/bitbucket-oauth-2-0-provider-api-1108483661.html
"""

from typing import Any

from .oauth import BaseOAuth2PKCE


Expand Down Expand Up @@ -81,7 +83,7 @@ def get_user_details(self, response) -> dict:
"avatar_url": user_data["avatarUrl"],
}

def user_data(self, access_token, *args, **kwargs) -> dict:
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Fetch user data from Bitbucket Data Center REST API"""
# At this point, we don't know the current user's username
# and Bitbucket doesn't provide any API to do so.
Expand Down
6 changes: 4 additions & 2 deletions social_core/backends/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
https://python-social-auth.readthedocs.io/en/latest/backends/box.html
"""

from typing import Any, cast

from .oauth import BaseOAuth2


Expand All @@ -23,7 +25,7 @@ class BoxOAuth2(BaseOAuth2):

def do_auth(self, access_token, response=None, *args, **kwargs):
response = response or {}
data = self.user_data(access_token)
data = cast("dict[str, Any]", self.user_data(access_token))

data["access_token"] = response.get("access_token")
data["refresh_token"] = response.get("refresh_token")
Expand All @@ -42,7 +44,7 @@ def get_user_details(self, response):
"last_name": last_name,
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Loads user data from service"""
params = self.setting("PROFILE_EXTRA_PARAMS", {})
params["access_token"] = access_token
Expand Down
4 changes: 3 additions & 1 deletion social_core/backends/bungie.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Bungie OAuth2 backend
"""

from typing import Any

from social_core.backends.oauth import BaseOAuth2


Expand Down Expand Up @@ -61,7 +63,7 @@ def do_auth(self, access_token, *args, **kwargs):
kwargs.update({"response": response, "backend": self})
return self.strategy.authenticate(*args, **kwargs)

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Grab user profile information from Bunige"""
membership_id = kwargs["response"]["membership_id"]
url = "https://www.bungie.net/Platform/User/GetBungieNetUser/"
Expand Down
6 changes: 4 additions & 2 deletions social_core/backends/cas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
implementation and the standard OIDC implementation in Python Social Auth.
"""

from typing import Any, cast

from .open_id_connect import OpenIdConnectAuth


Expand Down Expand Up @@ -36,7 +38,7 @@ def get_user_id(self, details, response):
self.log_debug("method: get_user_id, details: %s, %s", details, response)
return details.get("username")

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
data = self.get_json(
self.userinfo_url(), headers={"Authorization": f"Bearer {access_token}"}
)
Expand All @@ -46,7 +48,7 @@ def user_data(self, access_token, *args, **kwargs):
def get_user_details(self, response):
username_key = self.setting("USERNAME_KEY", self.USERNAME_KEY)
self.log_debug("username_key: %s", username_key)
attributes = self.user_data(response.get("access_token"))
attributes = cast("dict", self.user_data(response.get("access_token")))
return {
"username": attributes.get(username_key),
"email": attributes.get("email"),
Expand Down
4 changes: 3 additions & 1 deletion social_core/backends/changetip.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from .oauth import BaseOAuth2


Expand All @@ -20,7 +22,7 @@ def get_user_details(self, response):
"last_name": "",
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Loads user data from service"""
return self.get_json(
"https://api.changetip.com/v2/me/", params={"access_token": access_token}
Expand Down
4 changes: 3 additions & 1 deletion social_core/backends/chatwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Chatwork OAuth2 backend
"""

from typing import Any

from .oauth import BaseOAuth2


Expand Down Expand Up @@ -48,7 +50,7 @@ def get_user_details(self, response):
"last_name": last_name,
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Loads user data from service"""
headers = {"Authorization": "Bearer " + access_token}
return self.get_json(self.api_url("/me"), headers=headers)
Expand Down
6 changes: 4 additions & 2 deletions social_core/backends/cilogon.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from .oauth import BaseOAuth2


Expand All @@ -15,10 +17,10 @@ class CILogonOAuth2(BaseOAuth2):
REDIRECT_STATE = False
SCOPE_SEPARATOR = "+"

def user_data(self, token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Loads user data from endpoint"""
url = "https://cilogon.org/oauth2/userinfo"
data = {"access_token": token}
data = {"access_token": access_token}
try:
return self.get_json(url, method="POST", data=data)
except ValueError:
Expand Down
6 changes: 4 additions & 2 deletions social_core/backends/classlink.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from .oauth import BaseOAuth2


Expand Down Expand Up @@ -33,10 +35,10 @@ def get_user_details(self, response):
"last_name": last_name,
}

def user_data(self, token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Loads user data from service"""
url = "https://nodeapi.classlink.com/v2/my/info"
auth_header = {"Authorization": f"Bearer {token}"}
auth_header = {"Authorization": f"Bearer {access_token}"}
try:
return self.get_json(url, headers=auth_header)
except ValueError:
Expand Down
4 changes: 3 additions & 1 deletion social_core/backends/clef.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
values given by Clef application registration process.
"""

from typing import Any

from .oauth import BaseOAuth2


Expand Down Expand Up @@ -45,7 +47,7 @@ def get_user_details(self, response):
"phone_number": info.get("phone_number", ""),
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
return self.get_json(
"https://clef.io/api/v1/info", params={"access_token": access_token}
)
6 changes: 4 additions & 2 deletions social_core/backends/clever.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from .oauth import BaseOAuth2


Expand Down Expand Up @@ -45,10 +47,10 @@ def get_user_details(self, response):
"user_type": self.get_user_type(response),
}

def user_data(self, token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Loads user data from service"""
identity_url = "https://api.clever.com/v3.0/me"
auth_header = {"Authorization": f"Bearer {token}"}
auth_header = {"Authorization": f"Bearer {access_token}"}
try:
response = self.get_json(identity_url, headers=auth_header)
user_id = response.get("data", {}).get("id")
Expand Down
3 changes: 2 additions & 1 deletion social_core/backends/coding.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Coding OAuth2 backend, docs at:
"""

from typing import Any
from urllib.parse import urljoin

from .oauth import BaseOAuth2
Expand Down Expand Up @@ -32,7 +33,7 @@ def get_user_details(self, response):
"last_name": last_name,
}

def user_data(self, access_token, *args, **kwargs):
def user_data(self, access_token: str, *args, **kwargs) -> dict[str, Any] | None:
"""Loads user data from service"""
data = self._user_data(access_token)
if data.get("code") != 0:
Expand Down
Loading
Loading