omniauth-discord 0.1.3 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/gem-push.yml +33 -0
- data/.github/workflows/rspec.yml +25 -0
- data/.rubocop.yml +8 -1146
- data/.travis.yml +17 -10
- data/README.md +50 -2
- data/Rakefile +4 -7
- data/example/Gemfile +5 -0
- data/example/Gemfile.lock +60 -0
- data/example/app.rb +23 -0
- data/example/config.ru +11 -0
- data/lib/omniauth/discord/version.rb +1 -1
- data/lib/omniauth/discord.rb +1 -1
- data/lib/omniauth/strategies/discord.rb +13 -16
- data/omniauth-discord.gemspec +16 -17
- metadata +19 -15
- data/.codeclimate.yml +0 -16
data/.travis.yml
CHANGED
@@ -1,21 +1,28 @@
|
|
1
|
+
env:
|
2
|
+
global:
|
3
|
+
- CC_TEST_REPORTER_ID=ABC123
|
4
|
+
|
1
5
|
language: ruby
|
2
6
|
before_install: gem install bundler
|
3
7
|
|
4
8
|
rvm:
|
9
|
+
- 2.6.1
|
5
10
|
- 2.3.0
|
6
|
-
- 2.2
|
7
|
-
- 2.1
|
8
|
-
- 2.0
|
9
11
|
- jruby-head
|
10
|
-
|
11
|
-
|
12
|
+
|
12
13
|
gemfile:
|
13
14
|
- Gemfile
|
14
15
|
|
15
16
|
notifications:
|
16
|
-
email:
|
17
|
+
email: true
|
18
|
+
|
19
|
+
before_script:
|
20
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
21
|
+
- chmod +x ./cc-test-reporter
|
22
|
+
- ./cc-test-reporter before-build
|
23
|
+
|
24
|
+
script:
|
25
|
+
- bundle exec rspec
|
17
26
|
|
18
|
-
|
19
|
-
|
20
|
-
repo_token:
|
21
|
-
secure: "1a6ae0e7db7aaab5f54e634a64bf9278084fca24f3558871356b559b724ce8bf"
|
27
|
+
after_script:
|
28
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# OmniAuth Discord
|
1
|
+
# OmniAuth Discord
|
2
2
|
|
3
3
|
Discord OAuth2 Strategy for OmniAuth.
|
4
4
|
|
@@ -22,10 +22,58 @@ Here's a quick example, adding the middleware to a Rails app in `config/initiali
|
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
25
|
-
provider :discord, ENV['
|
25
|
+
provider :discord, ENV['DISCORD_CLIENT_ID'], ENV['DISCORD_CLIENT_SECRET']
|
26
26
|
end
|
27
27
|
```
|
28
28
|
|
29
|
+
By default, Discord does not return a user's email address. Their API uses
|
30
|
+
[scopes](https://discordapp.com/developers/docs/topics/oauth2#scopes) to provide
|
31
|
+
access to certain resources of a user's account. For example, to get a user's
|
32
|
+
email set the scope to `email`.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
36
|
+
provider :discord, ENV['DISCORD_CLIENT_ID'], ENV['DISCORD_CLIENT_SECRET'], scope: 'email'
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
You can pass multiple scopes in the same string. For example to get a user's
|
41
|
+
Discord account info set the scope to `email identify`
|
42
|
+
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
46
|
+
provider :discord, ENV['DISCORD_CLIENT_ID'], ENV['DISCORD_CLIENT_SECRET'], scope: 'email identify'
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
You can set callback url
|
51
|
+
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
55
|
+
provider :discord, ENV['DISCORD_CLIENT_ID'], ENV['DISCORD_CLIENT_SECRET'], scope: 'email identify', callback_url: 'https://someurl.com/users/auth/discord/callback'
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
## Specifying additional permissions
|
60
|
+
|
61
|
+
You can also request additional permissions from the user. See the
|
62
|
+
[permission help page](https://discordapp.com/developers/docs/topics/permissions#bitwise-permission-flags) for a list of all available options.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
66
|
+
provider :discord, ENV['DISCORD_CLIENT_ID'], ENV['DISCORD_CLIENT_SECRET'], scope: 'identify bot', permissions: 0x00000010 + 0x10000000
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
This will request permission to the MANAGE_CHANNELS and the MANAGE_ROLES
|
71
|
+
permissions.
|
72
|
+
|
73
|
+
## Specifying the prompt options
|
74
|
+
|
75
|
+
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.
|
76
|
+
|
29
77
|
## Contributing
|
30
78
|
|
31
79
|
Bug reports and pull requests are welcome on GitHub at https://github.com/adaoraul/omniauth-discord.
|
data/Rakefile
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
-
require '
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
|
4
|
-
|
5
|
-
task.libs << 'lib'
|
6
|
-
task.libs << 'test'
|
7
|
-
task.test_files = FileList['test/*_test.rb']
|
8
|
-
end
|
4
|
+
RSpec::Core::RakeTask.new
|
9
5
|
|
10
|
-
|
6
|
+
desc 'Run specs'
|
7
|
+
task default: :spec
|
data/example/Gemfile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
omniauth-discord (1.0.0)
|
5
|
+
omniauth
|
6
|
+
omniauth-oauth2
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
backports (3.15.0)
|
12
|
+
faraday (0.15.4)
|
13
|
+
multipart-post (>= 1.2, < 3)
|
14
|
+
hashie (3.6.0)
|
15
|
+
jwt (2.2.1)
|
16
|
+
multi_json (1.13.1)
|
17
|
+
multi_xml (0.6.0)
|
18
|
+
multipart-post (2.1.1)
|
19
|
+
mustermann (1.0.3)
|
20
|
+
oauth2 (1.4.1)
|
21
|
+
faraday (>= 0.8, < 0.16.0)
|
22
|
+
jwt (>= 1.0, < 3.0)
|
23
|
+
multi_json (~> 1.3)
|
24
|
+
multi_xml (~> 0.5)
|
25
|
+
rack (>= 1.2, < 3)
|
26
|
+
omniauth (1.9.0)
|
27
|
+
hashie (>= 3.4.6, < 3.7.0)
|
28
|
+
rack (>= 1.6.2, < 3)
|
29
|
+
omniauth-oauth2 (1.6.0)
|
30
|
+
oauth2 (~> 1.1)
|
31
|
+
omniauth (~> 1.9)
|
32
|
+
rack (2.2.3)
|
33
|
+
rack-protection (2.0.5)
|
34
|
+
rack
|
35
|
+
sinatra (2.0.5)
|
36
|
+
mustermann (~> 1.0)
|
37
|
+
rack (~> 2.0)
|
38
|
+
rack-protection (= 2.0.5)
|
39
|
+
tilt (~> 2.0)
|
40
|
+
sinatra-contrib (2.0.5)
|
41
|
+
backports (>= 2.8.2)
|
42
|
+
multi_json
|
43
|
+
mustermann (~> 1.0)
|
44
|
+
rack-protection (= 2.0.5)
|
45
|
+
sinatra (= 2.0.5)
|
46
|
+
tilt (>= 1.3, < 3)
|
47
|
+
sinatra-reloader (1.0)
|
48
|
+
sinatra-contrib
|
49
|
+
tilt (2.0.9)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
omniauth-discord!
|
56
|
+
sinatra
|
57
|
+
sinatra-reloader
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
2.0.2
|
data/example/app.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require "sinatra/reloader"
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
# configure sinatra
|
6
|
+
set :run, false
|
7
|
+
set :raise_errors, true
|
8
|
+
|
9
|
+
get '/' do
|
10
|
+
content_type 'text/html'
|
11
|
+
<<-HTML
|
12
|
+
<html>
|
13
|
+
<body>
|
14
|
+
<a href="/auth/discord">Connect to Discord!</a>
|
15
|
+
</body>
|
16
|
+
</html>
|
17
|
+
HTML
|
18
|
+
end
|
19
|
+
|
20
|
+
get '/auth/:provider/callback' do
|
21
|
+
content_type 'application/json'
|
22
|
+
MultiJson.encode(request.env)
|
23
|
+
end
|
data/example/config.ru
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'omniauth-discord'
|
3
|
+
require './app.rb'
|
4
|
+
|
5
|
+
use Rack::Session::Cookie, secret: '123456789'
|
6
|
+
|
7
|
+
use OmniAuth::Builder do
|
8
|
+
provider :discord, ENV['DISCORD_CLIENT_ID'], ENV['DISCORD_CLIENT_ID'], scope: ENV['SCOPE']
|
9
|
+
end
|
10
|
+
|
11
|
+
run Sinatra::Application
|
data/lib/omniauth/discord.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'omniauth/discord/version'
|
2
|
-
require 'omniauth/strategies/discord'
|
2
|
+
require 'omniauth/strategies/discord'
|
@@ -3,27 +3,25 @@ require 'omniauth-oauth2'
|
|
3
3
|
module OmniAuth
|
4
4
|
module Strategies
|
5
5
|
class Discord < OmniAuth::Strategies::OAuth2
|
6
|
-
DEFAULT_SCOPE = 'identify'
|
6
|
+
DEFAULT_SCOPE = 'identify'.freeze
|
7
7
|
|
8
8
|
option :name, 'discord'
|
9
9
|
|
10
|
-
option :client_options,
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
10
|
+
option :client_options,
|
11
|
+
site: 'https://discord.com/api',
|
12
|
+
authorize_url: 'oauth2/authorize',
|
13
|
+
token_url: 'oauth2/token'
|
15
14
|
|
16
|
-
option :authorize_options, [
|
15
|
+
option :authorize_options, %i[scope permissions prompt]
|
17
16
|
|
18
17
|
uid { raw_info['id'] }
|
19
18
|
|
20
19
|
info do
|
21
20
|
{
|
22
|
-
:
|
23
|
-
:
|
24
|
-
|
25
|
-
:avatar
|
26
|
-
:verified => raw_info['verified']
|
21
|
+
name: raw_info['username'],
|
22
|
+
email: raw_info['verified'] ? raw_info['email'] : nil,
|
23
|
+
# CDN is still cdn.discordapp.com
|
24
|
+
image: raw_info['avatar'].present? ? "https://cdn.discordapp.com/avatars/#{raw_info['id']}/#{raw_info['avatar']}" : nil,
|
27
25
|
}
|
28
26
|
end
|
29
27
|
|
@@ -34,21 +32,20 @@ module OmniAuth
|
|
34
32
|
end
|
35
33
|
|
36
34
|
def raw_info
|
37
|
-
@raw_info
|
35
|
+
@raw_info ||= access_token.get('users/@me').parsed
|
38
36
|
end
|
39
37
|
|
40
38
|
def callback_url
|
41
39
|
# Discord does not support query parameters
|
42
|
-
full_host + script_name + callback_path
|
40
|
+
options[:callback_url] || (full_host + script_name + callback_path)
|
43
41
|
end
|
44
42
|
|
45
43
|
def authorize_params
|
46
44
|
super.tap do |params|
|
47
45
|
options[:authorize_options].each do |option|
|
48
|
-
params[option] = request.params[option.to_s]
|
46
|
+
params[option] = request.params[option.to_s] if request.params[option.to_s]
|
49
47
|
end
|
50
48
|
|
51
|
-
params[:redirect_uri] = options[:redirect_uri] unless options[:redirect_uri].nil?
|
52
49
|
params[:scope] ||= DEFAULT_SCOPE
|
53
50
|
end
|
54
51
|
end
|
data/omniauth-discord.gemspec
CHANGED
@@ -1,29 +1,28 @@
|
|
1
|
-
|
2
|
-
$:.push File.expand_path('../lib', __FILE__)
|
1
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
3
2
|
require 'omniauth/discord/version'
|
4
3
|
|
5
4
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
5
|
+
spec.name = 'omniauth-discord'
|
7
6
|
spec.version = Omniauth::Discord::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
7
|
+
spec.authors = ['Adão Raul']
|
8
|
+
spec.email = ['adao.raul@gmail.com']
|
10
9
|
|
11
|
-
spec.summary =
|
10
|
+
spec.summary = 'Discord OAuth2 Strategy for OmniAuth'
|
12
11
|
spec.description = spec.summary
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
12
|
+
spec.homepage = 'http://github.com/adaoraul/omniauth-discord'
|
13
|
+
spec.license = 'MIT'
|
15
14
|
|
16
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
17
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
18
|
+
spec.require_paths = ['lib']
|
20
19
|
|
21
|
-
spec.add_runtime_dependency 'omniauth
|
20
|
+
spec.add_runtime_dependency 'omniauth', '~> 2.0.4'
|
21
|
+
spec.add_runtime_dependency 'omniauth-oauth2'
|
22
22
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency "mocha"
|
23
|
+
spec.add_development_dependency 'rack-test'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'simplecov'
|
27
|
+
spec.add_development_dependency 'webmock'
|
29
28
|
end
|
metadata
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-discord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adão Raul
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: omniauth
|
14
|
+
name: omniauth
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.0.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.0.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: omniauth-oauth2
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
|
-
type: :
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rack-test
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: webmock
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -115,7 +115,8 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- ".
|
118
|
+
- ".github/workflows/gem-push.yml"
|
119
|
+
- ".github/workflows/rspec.yml"
|
119
120
|
- ".gitignore"
|
120
121
|
- ".rubocop.yml"
|
121
122
|
- ".travis.yml"
|
@@ -123,6 +124,10 @@ files:
|
|
123
124
|
- LICENSE.txt
|
124
125
|
- README.md
|
125
126
|
- Rakefile
|
127
|
+
- example/Gemfile
|
128
|
+
- example/Gemfile.lock
|
129
|
+
- example/app.rb
|
130
|
+
- example/config.ru
|
126
131
|
- lib/omniauth-discord.rb
|
127
132
|
- lib/omniauth/discord.rb
|
128
133
|
- lib/omniauth/discord/version.rb
|
@@ -147,8 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
152
|
- !ruby/object:Gem::Version
|
148
153
|
version: '0'
|
149
154
|
requirements: []
|
150
|
-
|
151
|
-
rubygems_version: 2.5.1
|
155
|
+
rubygems_version: 3.1.4
|
152
156
|
signing_key:
|
153
157
|
specification_version: 4
|
154
158
|
summary: Discord OAuth2 Strategy for OmniAuth
|