/Django-Rest-Social-OAuth2-Tutorial

Django Rest Framework 를 사용할 때 간편하게 Social Login 을 사용할 수 있도록 도와주는 튜토리얼입니다

Primary LanguagePython

Django Rest Framework 에서 Social Login 으로 방황하는 당신을 위한 가이드

해당 라이브러리를 사용하면 간단하게 Social Login 과 통합할 수 있습니다.

https://github.com/RealmTeam/django-rest-framework-social-oauth2

공통 세팅

  1. 설치
pip install django-rest-framework-social-oauth2
  1. settings.py 에 INSTALLED_APPS 에 추가
INSTALLED_APPS = (
    '...',
    'oauth2_provider',
    'social_django',
    'rest_framework_social_oauth2',
)
  1. urls.py 에 로그인 URL 등록
urlpatterns = patterns(
    '...',
    (r'^auth/', include('rest_framework_social_oauth2.urls')),
)
  1. 인증 설정 추가
# 1. REST FRAMEWORK Authentication 설정 추가
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
        'rest_framework_social_oauth2.authentication.SocialAuthentication',
    ),
}

# 2. Django 기본 Authentication 설정 추가
AUTHENTICATION_BACKENDS = (
    'social_core.backends.google.GoogleOAuth2',
    'rest_framework_social_oauth2.backends.DjangoOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)

Sample Backends

각 Social Login 별로 Tutorial 을 작성해 놓은 문서입니다.