futuresimple/dropbox-api — pull request #47 by disbelief (2014-05-10 23:43:24+00:00)
Title: OAuth2 Support

I needed to modify dropbox-api to support OAuth2 and figured I'd submit my changes as a PR. Dropbox mentions in their docs that:

> OAuth 1.0 continues to be supported for all API requests, but OAuth 2.0 is now preferred.

This change adds a new config setting `auth_type` which can be either `oauth` (default) or `oauth2`:

```ruby
Dropbox::API::Config.auth_type = "oauth2" # default is oauth
```
It also slightly changes the way that Access Tokens are requested when OAuth2 is used:

```ruby
## Manual Access Token retrieval:

consumer = ::Dropbox::API::OAuth2.consumer(:authorize)
authorize_uri = consumer.authorize_url(client_id: APP_KEY, response_type: 'code')
# open authorize_uri in browser, sign in, grant permission, copy code that is displayed
access_token = consumer.auth_code.get_token('code_from_dropbox')

# Browser-based Access Token retrieval:

consumer = ::Dropbox::API::OAuth2.consumer(:authorize)
authorize_uri = consumer.authorize_url(client_id: APP_KEY, response_type: 'code', redirect_uri: 'https://yoursite.com/dropbox_landing', state: 'optional string')
# redirect user to authorize_uri
# upon return to https://yoursite.com/dropbox_landing?code=SOME_CODE&uid=SOME_ID
access_token = consumer.auth_code.get_token('code_from_query_string')
```