LoginSignup
0

More than 5 years have passed since last update.

Dropboxの認証コード

Last updated at Posted at 2017-06-29

古いiOSのブラウザではloginボタンが有効にならずにログインできないので、他の環境でログインと許可して、認証コードでOAuth2を使ってみました。

をredirect_uri無し,response_type=codeで叩くと以下のページに遷移してコードが取得できます。

スクリーンショット(2017-06-29 14.22.02).png

このコードを以下のAPIに放り込むとAccess Tokenが取得できます。

いろいろ試したら以下のようなエラーがあるようです。

{"error": "Call requires one of the following methods: POST, OPTIONS. Got GET."}

これはプログラムのミスでGETでアクセスしてしまったのでPOSTに直しました。

{"error_description": "code has expired (within the last hour)", "error": "invalid_grant"}

アクセスコードを払い出してから1時間以内でないと無効になるようです。

一度使ってしまった認証コードは使えないようです。

{"error_description": "code has already been used", "error": "invalid_grant"}

コードが空だとこんなエラーです。

{"error_description": "\"code\": must not be empty", "error": "invalid_request"}
{"access_token": "xxx", "token_type": "bearer", "uid": "yyy", "account_id": "zzz"}

正しくアクセスできると上記のように返ってきます。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0