Discord OAuth2 Strategy for OmniAuth
Ruby
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.rubocop.yml
.travis.yml
Gemfile
LICENSE.txt
README.md
Rakefile
omniauth-discord.gemspec

README.md

OmniAuth Discord

Discord OAuth2 Strategy for OmniAuth.

Read the Discord API documentation for more details: https://discordapp.com/developers/docs/topics/oauth2

Installing

Add to your Gemfile:

gem 'omniauth-discord'

Then bundle install.

Usage

OmniAuth::Strategies::Discord is simply a Rack middleware. Read the OmniAuth docs for detailed instructions: https://github.com/intridea/omniauth.

Here's a quick example, adding the middleware to a Rails app in config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :discord, ENV['DISCORD_CLIENT_ID'], ENV['DISCORD_CLIENT_SECRET']
end

By default, Discord does not return a user's email address. Their API uses scopes to provide access to certain resources of a user's account. For example, to get a user's email set the scope to email.

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :discord, ENV['DISCORD_CLIENT_ID'], ENV['DISCORD_CLIENT_SECRET'], scope: 'email'
end

You can pass multiple scopes in the same string. For example to get a user's Discord account info set the scope to email identify

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :discord, ENV['DISCORD_CLIENT_ID'], ENV['DISCORD_CLIENT_SECRET'], scope: 'email identify'
end

Specifying additional permissions

You can also request additional permissions from the user. See the permission help page for a list of all available options.

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :discord, ENV['DISCORD_CLIENT_ID'], ENV['DISCORD_CLIENT_SECRET'], scope: 'identify  bot', permissions: 0x00000010 + 0x10000000
end

This will request permission to the MANAGE_CHANNELS and the MANAGE_ROLES permissions.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/adaoraul/omniauth-discord.

License

The gem is available as open source under the terms of the MIT License.