DrEdit 샘플 앱에 제시된대로 인증 과정에서 리디렉션 개념을 파악하는 데 문제가 있습니다. 여기 REDIRECT_URL가 요청 URL에서 모든 매개 변수를 제거하여 설정됩니다Python의 OAuth 흐름에 대한 설명 Google 드라이브 샘플 애플리케이션 (DrEdit)
def CreateOAuthFlow(self):
"""Create OAuth2.0 flow controller
This controller can be used to perform all parts of the OAuth 2.0 dance
including exchanging an Authorization code.
Args:
request: HTTP request to create OAuth2.0 flow for
Returns:
OAuth2.0 Flow instance suitable for performing OAuth2.0.
"""
flow = flow_from_clientsecrets('client_secrets.json', scope='')
# Dynamically set the redirect_uri based on the request URL. This is extremely
# convenient for debugging to an alternative host without manually setting the
# redirect URI.
flow.redirect_uri = self.request.url.split('?', 1)[0].rsplit('/', 1)[0]
return flow
응용 프로그램이 Google 드라이브 UI (GET 매개 변수 code
및 state
와 응용 프로그램의 루트 URL에 GET 요청)에서 호출되는 애플리케이션은 Google 드라이브에 요청할 권한이 있는지 확인합니다. 액세스가 취소되었습니다하는 경우, 그것은 다음과 같은 코드를 사용하여 자체 권한을 부여 다시 시도, 저는 믿습니다 :
creds = self.GetCodeCredentials()
if not creds:
return self.RedirectAuth()
RedirectAuth()
는 다음과 같이 정의된다 :
def RedirectAuth(self):
"""Redirect a handler to an authorization page.
Used when a handler fails to fetch credentials suitable for making Drive API
requests. The request is redirected to an OAuth 2.0 authorization approval
page and on approval, are returned to application.
Args:
handler: webapp.RequestHandler to redirect.
"""
flow = self.CreateOAuthFlow()
# Manually add the required scopes. Since this redirect does not originate
# from the Google Drive UI, which authomatically sets the scopes that are
# listed in the API Console.
flow.scope = ALL_SCOPES
# Create the redirect URI by performing step 1 of the OAuth 2.0 web server
# flow.
uri = flow.step1_get_authorize_url(flow.redirect_uri)
# Perform the redirect.
self.redirect(uri)
내 문제는 때 I 내 Google 대시 보드에서 애플리케이션 액세스를 취소하고 Google 드라이브 UI를 통해 열려고 시도하면 인증 페이지로 리디렉션 된 다음 승인 한 후에 다시 애플리케이션으로 리디렉션되지만 상태를 유지 관리합니다 (전달 된 매개 변수 가져 오기 드라이브 UI). 나는 이것이 코드가 기술하는 것과 일치하지 않는다고 생각하며,이 행동에 대한 설명이 있는지 궁금해하고 있었다. DrEdit 앱의 호스팅 버전은 다음에서 찾을 수 있습니다. http://idning-gdrive-test.appspot.com/