omniauth-dropbox2 provides a Dropbox OAuth2 strategy for OmniAuth.
Add this line to your application's Gemfile:
gem 'omniauth-dropbox2'Then run:
bundle installConfigure OmniAuth in your Rack/Rails app:
use OmniAuth::Builder do
provider :dropbox, ENV.fetch('DROPBOX_APP_KEY'), ENV.fetch('DROPBOX_APP_SECRET')
end- Dropbox app console: https://www.dropbox.com/developers/apps
- Register callback URL (example):
https://your-app.example.com/auth/dropbox/callback
- Request-phase query options can be passed directly to
/auth/dropboxwhen supported by Dropbox OAuth endpoints.
Example payload from request.env['omniauth.auth'] (real flow shape, anonymized):
{
"uid": "dbid:sample-account-id",
"info": {
"name": "Sample User"
},
"credentials": {
"token": "sample-access-token",
"refresh_token": "sample-refresh-token",
"expires": false,
"scope": "files.metadata.read"
},
"extra": {
"raw_info": {
"account_id": "dbid:sample-account-id",
"name": {
"given_name": "Sample",
"surname": "User",
"familiar_name": "Sample",
"display_name": "Sample User",
"abbreviated_name": "SU"
},
"email": "sample@example.test",
"email_verified": true,
"disabled": false,
"country": "IT",
"locale": "en",
"referral_link": "https://www.dropbox.com/referrals/AABsample",
"is_paired": false,
"account_type": {
".tag": "basic"
},
"root_info": {
".tag": "user",
"root_namespace_id": "123456",
"home_namespace_id": "123456"
}
}
}
}Notes:
uidis mapped fromraw_info.account_idinfo.nameis mapped fromraw_info.name.display_namecredentialsincludestoken, plusrefresh_tokenwhen provided by Dropboxextra.raw_infois the fullusers/get_current_accountresponse
bundle install
bundle exec rakeThe default Rake task runs:
rake lint(RuboCop)rake test_unit(strategy/unit Minitest suite)
Run Rails integration tests with an explicit Rails version:
RAILS_VERSION='~> 8.1.0' bundle install
RAILS_VERSION='~> 8.1.0' bundle exec rake test_rails_integrationtest/omniauth_dropbox2_test.rb: strategy/unit behaviortest/rails_integration_test.rb: full Rack/Rails request+callback flowtest/test_helper.rb: shared test bootstrap
- Ruby:
>= 3.2(tested on3.2,3.3,3.4,4.0) omniauth-oauth2:>= 1.8,< 2.0- Rails integration lanes:
~> 7.1.0,~> 7.2.0,~> 8.0.0,~> 8.1.0
Tag releases as vX.Y.Z; GitHub Actions publishes the gem to RubyGems.
MIT