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
You can set callback url
Rails.application.config.middleware.use OmniAuth::Builder do
provider :discord, ENV['DISCORD_CLIENT_ID'], ENV['DISCORD_CLIENT_SECRET'], scope: 'email identify', callback_url: 'https://someurl.com/users/auth/discord/callback'
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.
Specifying the prompt options
Discord looks for the prompt option to indicate if the user should be prompted to reauthorize on sign in. Valid options are 'consent' and 'none'. Note that the use is always prompted to authorize on sign up.
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.