Skip to content

Instantly share code, notes, and snippets.

@XaviTorello
Created February 14, 2020 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XaviTorello/e7793b1c6f68fe60a0036d581d3cd361 to your computer and use it in GitHub Desktop.
Save XaviTorello/e7793b1c6f68fe60a0036d581d3cd361 to your computer and use it in GitHub Desktop.
AppleId custom new backends with different settings
# file: an_app/backends.py
from social_core.backends.apple import AppleIdAuth
"""
It provides 2 backends that extends the AppleID base auth
Useful to be able to define different configs depending on the singin scenario
The name will be used to fetch concrete settings and link it at the `provider` field (or the `/jwt-pair/$name` URI)
"""
class AppleIdAppAuth(AppleIdAuth):
"""
Default AppleID backend for app logins.
Will load SOCIAL_AUTH_APPLE_ID_FROM_APP_* settings and expose it as provider = "apple-id-from-app" (or your URL /jwt-pair/apple-id-from-app)
"""
name = "apple-id-from-app"
class AppleIdWebAuth(AppleIdAuth):
"""
Default AppleID backend for app logins.
Is the same than AppleIdAuth, but helps to ensure that provider name does not change.
"""
name = "apple-id"
#file: settings/__init__.py # or your backends loader
...
AUTHENTICATION_BACKENDS = [
...
# 'social_core.backends.apple.AppleIdAuth',
'users.backends.AppleIdAppAuth',
'users.backends.AppleIdWebAuth',
...
]
SOCIAL_AUTH_APPLE_ID = 'com.client.base'
SOCIAL_AUTH_APPLE_KEY = '...'
...
# FROM APP settings //
SOCIAL_AUTH_APPLE_ID_FROM_APP_CLIENT = 'com.client.app'
SOCIAL_AUTH_APPLE_ID_FROM_APP_KEY = '...'
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment