art-solopov / omniauth-discord

Discord OAuth2 Strategy for OmniAuth

Home Page:http://adaoraul.github.io/omniauth-discord

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

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.

About

Discord OAuth2 Strategy for OmniAuth

http://adaoraul.github.io/omniauth-discord

License:MIT License


Languages

Language:Ruby 100.0%