0

google_drive で login_with_oauth2 を使用しようとしていますが、 #google_drive.rb doc の認証コードがわかりません

client = OAuth2::Client.new(
    "522807807986-gjotv2np4tdqp4do8sq0gds0p2bqugtf.apps.googleusercontent.com",
    'fmWlfzejvx_UtS3CKq2Sl-WQ',
    :site => "https://accounts.google.com",
    :token_url => "/o/oauth2/token",
    :authorize_url => "/o/oauth2/auth"
)

auth_url = client.auth_code.authorize_url(
    :redirect_uri => "urn:ietf:wg:oauth:2.0:oob
http://localhost"
)

# Redirect the user to auth_url and get authorization code from redirect URL.

authorization_code = ''
auth_token = client.auth_code.get_token(
    authorization_code, :redirect_uri => "urn:ietf:wg:oauth:2.0:oob
http://localhost")
session = GoogleDrive.login_with_oauth(auth_token.token, 'http://localhost:8087')
4

1 に答える 1

0

OAuth2は、2 段階の承認メカニズムです。AFAIU、公式ドキュメントからコードをコピーして貼り付けただけですが、残念ながらそれは機能するコードではありません。これはほんの一例です。でマークされたコメントを見てください。これは非常に重要です。

# Redirect the user to auth_url and get authorization code from redirect URL.

Google サーバーが応答を送信するための正しい pingback URI を指定する必要がありますauthorization_code(現在、 が表示localhostされています。これは、Google がフィードバックを送信するために IP を理解するのに問題があります。)

要約すると、Google に資格情報を提供すると、指定したアドレスへの情報を含む JSON がauthorization_code返されます。このフェーズが正常に完了したら、リクエストに進むことができますauth_token

于 2013-09-21T13:25:43.900 に答える