Django에서 python-social-auth
을 통해 추가 범위를 추가하는 것은 기본적으로는 아니지만 (two ways described here) 어렵지 않습니다. 첫 번째 옵션을 선택하고 get_scope
메소드를 덮어 썼습니다.
는 views.py
, 나는
flow = client.flow_from_clientsecrets(
CLIENT_SECRET_FILE,
scope=SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPES,
redirect_uri='https://yourdomain.com/callbacklinkforgmail')
을 설정하고
redirect_uri
구글 콘솔에서 리디렉션 된 URL과 일치해야합니다.
요청 권한은 어딘가에 저장된 자격 증명을 기반으로 수행됩니다. 내 경우에는 하나의 모델입니다.
이 단계를 수행
# model with variable/column 'credentials'
storage = Storage(YourModel, 'id', request.user, 'credentials')
credential = storage.get()
if credential is None or credential.invalid is True:
flow.params['state'] = xsrfutil.generate_token(SOCIAL_AUTH_GOOGLE_OAUTH2_KEY,
request.user)
authorize_url = flow.step1_get_authorize_url()
return HttpResponseRedirect(authorize_url)
else:
http = credential.authorize(httplib2.Http())
service = discovery.build('gmail', 'v1', http=http)
, 일치를 확인하는 기능에 redirect_uri
리디렉션. 제 경우에는 views.py
입니다. 내 응용 프로그램의 urls.py
에서
@login_required
def auth_return(request):
if not xsrfutil.validate_token(SOCIAL_AUTH_GOOGLE_OAUTH2_KEY, request.GET['state'].encode('utf-8'), request.user):
return HttpResponseBadRequest()
credential = flow.step2_exchange(request.GET)
storage = Storage(YourModel, 'id', request.user, 'credentials')
storage.put(credential)
return HttpResponseRedirect("/")
및 항목은
url(r'^callbacklinkforgmail/$', views.auth_return, name='mailsend')
클라이언트 ID는이 API를 사용 섹션에서 사용 가능 한 모든 API에 액세스 할 수 있습니다. 사용자가 범위 이메일 (나는 그것이 하나 또는 gmail이라고 생각한다)로 인증하는 한 원하는만큼 많은 API에 대해 동일한 클라이언트 ID를 사용할 수 있습니다. 액세스 할 수있는 것을 결정하는 인증의 범위. 위의 메시지는 나에게 많은 것을 말하지 않습니다. 노래를 부를 YouTube 동영상을 볼 수 있습니다. – DaImTo
@DaImTo 현재 내 정의 된 범위는 [' 'https://www.googleapis.com/auth/gmail.send''](https://developers.google.com)입니다./gmail/api/auth/scopes). 나는 "로그인"범위를 추가 할 수있는 곳을 보지 못했습니다 (이전 링크 참조). 그 youtube 비디오를 직접보고 싶습니다. 편집 : 흠, 어쩌면 [이] (https://developers.google.com/identity/protocols/googlescopes), 특히 Google 로그인에서'프로필'과'로그인'? –
잠시 있었지만 로그인은 더 잘될 것이라고 생각합니다. https://developers.google.com/+/web/api/rest/oauth btw Gmail은 고통을 말하고 있습니다. 나는 여러분을 가리키고있는 비단뱀 사람이 아닙니다. 올바른 방향으로 – DaImTo