Skip to content

Commit ac44fbe

Browse files
authored
Merge pull request #483 from vthorey/vthorey/installation-doc
Vthorey/installation doc
2 parents 3925282 + e891a76 commit ac44fbe

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

docs/installation.rst

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Twitter
131131

132132
If you are using Twitter for your social authentication, it is a bit different since Twitter uses OAuth 1.0.
133133

134-
3. Create new view as a subclass of ``rest_auth.views.LoginView`` with ``TwitterOAuthAdapter`` adapter and ``TwitterLoginSerializer`` as an attribute:
134+
3. Create new view as a subclass of ``rest_auth.registration.views.SocialLoginView`` with ``TwitterOAuthAdapter`` adapter and ``TwitterLoginSerializer`` as an attribute:
135135

136136
.. code-block:: python
137137
@@ -154,6 +154,34 @@ If you are using Twitter for your social authentication, it is a bit different s
154154
155155
.. note:: Starting from v0.21.0, django-allauth has dropped support for context processors. Check out http://django-allauth.readthedocs.org/en/latest/changelog.html#from-0-21-0 for more details.
156156

157+
158+
GitHub
159+
######
160+
161+
If you are using GitHub for your social authentication, it uses code and not AccessToken directly.
162+
163+
3. Create new view as a subclass of ``rest_auth.views.SocialLoginView`` with ``GitHubOAuth2Adapter`` adapter, an ``OAuth2Client`` and a callback_url as attributes:
164+
165+
.. code-block:: python
166+
167+
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter
168+
from allauth.socialaccount.providers.oauth2.client import OAuth2Client
169+
from rest_auth.registration.views import SocialLoginView
170+
171+
class GithubLogin(SocialLoginView):
172+
adapter_class = GitHubOAuth2Adapter
173+
callback_url = CALLBACK_URL_YOU_SET_ON_GITHUB
174+
client_class = OAuth2Client
175+
176+
4. Create url for GitHubLogin view:
177+
178+
.. code-block:: python
179+
180+
urlpatterns += [
181+
...,
182+
url(r'^rest-auth/github/$', GitHubLogin.as_view(), name='github_login')
183+
]
184+
157185
Additional Social Connect Views
158186
###############################
159187

@@ -162,6 +190,9 @@ If you want to allow connecting existing accounts in addition to login, you can
162190
.. code-block:: python
163191
164192
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
193+
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter
194+
from allauth.socialaccount.providers.twitter.views import TwitterOAuthAdapter
195+
from allauth.socialaccount.providers.oauth2.client import OAuth2Client
165196
from rest_auth.registration.views import SocialConnectView
166197
from rest_auth.social_serializers import TwitterConnectSerializer
167198
@@ -172,6 +203,12 @@ If you want to allow connecting existing accounts in addition to login, you can
172203
serializer_class = TwitterConnectSerializer
173204
adapter_class = TwitterOAuthAdapter
174205
206+
class GithubConnect(SocialConnectView):
207+
adapter_class = GitHubOAuth2Adapter
208+
callback_url = CALLBACK_URL_YOU_SET_ON_GITHUB
209+
client_class = OAuth2Client
210+
211+
175212
In urls.py:
176213

177214
.. code-block:: python
@@ -180,6 +217,7 @@ In urls.py:
180217
...,
181218
url(r'^rest-auth/facebook/connect/$', FacebookConnect.as_view(), name='fb_connect')
182219
url(r'^rest-auth/twitter/connect/$', TwitterConnect.as_view(), name='twitter_connect')
220+
url(r'^rest-auth/github/connect/$', GithubConnect.as_view(), name='github_connect')
183221
]
184222
185223
You can also use the following views to check all social accounts attached to the current authenticated user and disconnect selected social accounts:

0 commit comments

Comments
 (0)