-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
47 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,65 @@ | ||
# tfora_social_auth | ||
|
||
##### Easy django rest auth integration for social applications. (currently supports Google and Facebook) | ||
Easy django rest auth integration for social applications. (currently supports Google and Facebook) | ||
|
||
### Installation | ||
|
||
`pip install tfora-social-auth | ||
` | ||
###### INSTALLED_APPS = [ | ||
## Quick Setup | ||
|
||
Install package | ||
|
||
` 'tfora_social_auth' | ||
` | ||
pip install tfora-social-auth | ||
|
||
###### ] | ||
|
||
`python manage.py migrate` | ||
Add `tfora_social_auth` app to INSTALLED_APPS in your django settings.py: | ||
|
||
###### in urls | ||
```python | ||
INSTALLED_APPS = [ | ||
... | ||
'rest_framework', | ||
'tfora_social_auth', | ||
... | ||
] | ||
``` | ||
|
||
`from tfora_social_auth.views import ( | ||
GoogleSocialAuthView, | ||
FacebookSocialAuthView | ||
)` | ||
|
||
`path('social/google/', GoogleSocialAuthView.as_view()), | ||
` | ||
python manage.py migrate | ||
|
||
`path('social/facebook/', FacebookSocialAuthView.as_view()), | ||
` | ||
|
||
### For Google login | ||
#### Add URL patterns | ||
|
||
###### POST with "auth_token". | ||
```python | ||
from tfora_social_auth.views import ( GoogleSocialAuthView, FacebookSocialAuthView ) | ||
|
||
###### Send an "idtoken" as from google to get user information | ||
urlpatterns = [ | ||
path('social/google/', GoogleSocialAuthView.as_view()), | ||
path('social/facebook/', FacebookSocialAuthView.as_view()), | ||
] | ||
|
||
### For Facebook login | ||
``` | ||
|
||
###### POST with "auth_token". | ||
|
||
###### Send an access token as from facebook to get user information | ||
##### For Google login | ||
- POST with "auth_token". | ||
- Send an "idtoken" as from google to get user information | ||
|
||
##### For Facebook login | ||
- POST with "auth_token". | ||
- Send an access token as from facebook to get user information | ||
|
||
##### Extra token payload | ||
You can add extra payload data to access token by the following method | ||
|
||
```python | ||
from rest_framework_simplejwt.tokens import RefreshToken | ||
|
||
class CustomUserModel(AbstractUser): | ||
... | ||
@staticmethod | ||
def get_token(user): | ||
token = RefreshToken.for_user(user) | ||
token["extra_key"] = "extra_value" | ||
return token | ||
... | ||
|
||
|
||
``` |