2012-07-14 6 views
3

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 매개 변수 codestate와 응용 프로그램의 루트 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/

답변

3

드라이브 UI에서 앱을 시작하는 경우 해당 코드 경로는 절대 수정되지 않습니다. 승인 엔드 포인트로의 리디렉션은 드라이브에서 직접 시작됩니다. 즉, 경로는 다음과 같습니다

드라이브 -> 인증 -> DrEdit는 사용자가 이미 결정을했다 응용 프로그램에 도달하는 시간으로

에게. 상태는 상태 쿼리 매개 변수에서 전달됩니다.

작동중인 코드 경로를 보려면 다시 액세스 권한을 취소하십시오. 하지만 드라이브에서 시작하는 대신 앱을 직접로드 해보세요. 앱의 쿠키도 삭제해야 할 수 있습니다. 어쨌든, 그 경우에 사용자가 권한이없는 것을 감지 할 수 있습니다 때 응용 프로그램이로드되고 인증 엔드 포인트로 리디렉션 :

DrEdit -> 인증 - 도움> DrEdit

희망을.

관련 문제