3

DrEditサンプルアプリに示されている認証中のリダイレクトの概念を理解するのに問題があります。ここで、redirect_urlは、リクエストURLからすべてのパラメータを取り除くことによって設定されます。

  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パラメータを使用してアプリケーションのルートURLへのgetリクエストcodestate)、アプリケーションは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)

私の問題は、Googleダッシュボードからアプリケーションへのアクセスを取り消し、GoogleドライブUIを介してアプリケーションを開こうとすると、承認ページにリダイレクトされ、承認後にアプリケーションにリダイレクトされますが、状態は保持されます(ドライブUIから渡されたパラメータを取得します)。これはコードの説明と矛盾していると思います。この動作について何か説明があるのではないかと思いました。DrEditアプリのホストバージョンは、http://idning-gdrive-test.appspot.com/にあります

4

1 に答える 1

3

ドライブUIからアプリを起動する場合、そのコードパスに触れることはありません。承認エンドポイントへのリダイレクトは、ドライブから直接開始されます。つまり、パスは次のとおりです。

ドライブ->認証->DrEdit

アプリに到達するまでに、ユーザーはすでに決定を下しています。状態は、状態クエリパラメータで渡されます。

参照しているコードパスの動作を確認するには、アクセスを再度取り消します。ただし、ドライブから開始するのではなく、アプリを直接ロードしてみてください。アプリのCookieも削除する必要があるかもしれません。とにかく、その場合、アプリが読み込まれると、ユーザーが承認されていないことが検出され、認証エンドポイントにリダイレクトされます。

DrEdit-> auth-> DrEdit

お役に立てば幸いです。

于 2012-07-14T17:05:26.967 に答える