forked from python-social-auth/social-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backends: Move Facebook Limited Login to separate module
This removes jose dependency from Facebook backend. Fixes python-social-auth#773
- Loading branch information
Showing
3 changed files
with
51 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
Facebook Limited Login backend, docs at: | ||
https://python-social-auth.readthedocs.io/en/latest/backends/facebook.html | ||
""" | ||
from ..exceptions import AuthTokenError | ||
from .open_id_connect import OpenIdConnectAuth | ||
|
||
|
||
class FacebookLimitedLogin(OpenIdConnectAuth): | ||
"""Facebook Limited Login (OIDC) backend""" | ||
|
||
name = "facebook-limited-login" | ||
OIDC_ENDPOINT = "https://www.facebook.com" | ||
ACCESS_TOKEN_URL = "https://facebook.com/dialog/oauth/" | ||
ID_TOKEN_MAX_AGE = 3600 | ||
|
||
def authenticate(self, *args, **kwargs): | ||
if ( | ||
"backend" not in kwargs | ||
or kwargs["backend"].name != self.name | ||
or "strategy" not in kwargs | ||
or "response" not in kwargs | ||
): | ||
return None | ||
|
||
# Replace response with the decoded JWT | ||
raw_jwt = kwargs.get("response", {}).get("access_token") | ||
kwargs["response"] = self.validate_and_return_id_token(raw_jwt, "") | ||
return super().authenticate(*args, **kwargs) | ||
|
||
def get_user_details(self, response): | ||
return { | ||
"fullname": response.get("name"), | ||
"email": response.get("email"), | ||
"picture": response.get("picture"), | ||
} | ||
|
||
def user_data(self, access_token, *args, **kwargs): | ||
# We don't have an access token to call any API for the user details. | ||
return None | ||
|
||
def validate_claims(self, id_token): | ||
try: | ||
super().validate_claims(id_token) | ||
except AuthTokenError as e: | ||
if "Incorrect id_token: nonce" in e.args: | ||
# Ignore errors about nonce. We can't validate it since it's not generated server-side. | ||
return | ||
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters