omniauth-goodgame 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +83 -16
- data/example/app.rb +31 -0
- data/example/example.html +1 -0
- data/example/goodgame.rb +88 -0
- data/lib/omniauth/goodgame/version.rb +1 -1
- data/lib/omniauth/strategies/goodgame.rb +5 -3
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4aff38db60ec33ad9b536d1f8e49f358bcea8b87449261ad4afc1b941a4882e1
|
4
|
+
data.tar.gz: a05d507800a2da66099297f3e29c9c1794c779ab5913cc85952a3c9849bb12c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 394475cc4f8f3378ad6bcc3d1be44230aea709c05b80ebbed9cd061f595f8d5242fb4c8360e6393463de9874ec9e7ee4e9e03d1e273c51798129338fa79c185d
|
7
|
+
data.tar.gz: a4b3e666d74e41e06c301fac958ff5daed39db3a5ec832aaeef266642c6fb42942df9401a119d6532c8f93a15dde0826ed2b75043b8da630e8133280a902e4a5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,10 @@
|
|
1
|
-
# Omniauth::Goodgame
|
2
|
-
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/omniauth/goodgame`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
1
|
## Installation
|
8
2
|
|
9
|
-
Add this
|
3
|
+
Add this lines to your application's Gemfile:
|
10
4
|
|
11
5
|
```ruby
|
12
6
|
gem 'omniauth-goodgame'
|
7
|
+
gem 'omniauth-rails_csrf_protection'
|
13
8
|
```
|
14
9
|
|
15
10
|
And then execute:
|
@@ -22,22 +17,94 @@ Or install it yourself as:
|
|
22
17
|
|
23
18
|
## Usage
|
24
19
|
|
25
|
-
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
20
|
+
Here is an example for adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
30
21
|
|
31
|
-
|
22
|
+
```ruby
|
23
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
24
|
+
provider :twitch, ENV["GOODGAME_CLIENT_ID"], ENV["GOODGAME_CLIENT_SECRET"]
|
25
|
+
end
|
26
|
+
```
|
32
27
|
|
33
28
|
## Contributing
|
34
29
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
30
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Alex1324522/omniauth-goodgame. This project is intended to be a safe, welcoming space for collaboration.
|
36
31
|
|
37
32
|
## License
|
38
33
|
|
39
34
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
35
|
|
41
36
|
## Code of Conduct
|
42
|
-
|
43
|
-
|
37
|
+
Here is an example of an Auth hash that is located in `request.env['omniauth.auth']`:
|
38
|
+
```ruby
|
39
|
+
{"provider"=>"goodgame",
|
40
|
+
"uid"=>uid,
|
41
|
+
"info"=>
|
42
|
+
{"name"=>"name",
|
43
|
+
"nickname"=>"nickname",
|
44
|
+
"email"=>"your@email",
|
45
|
+
"channelid"=>channelid},
|
46
|
+
"credentials"=>
|
47
|
+
{"token"=>
|
48
|
+
"token",
|
49
|
+
"refresh_token"=>
|
50
|
+
"refresh_token",
|
51
|
+
"expires_at"=>1695420157,
|
52
|
+
"expires"=>true},
|
53
|
+
"extra"=>
|
54
|
+
{"raw_info"=>
|
55
|
+
{"id"=>id,
|
56
|
+
"obj_key"=>"obj_key",
|
57
|
+
"nickname"=>"nickname",
|
58
|
+
"username"=>"username",
|
59
|
+
"avatar"=>"/files/avatars/av_avatar_elf.png",
|
60
|
+
"firstname"=>"firstname",
|
61
|
+
"lastname"=>"lastname",
|
62
|
+
"fullname"=>"fullname",
|
63
|
+
"birthday"=>nil,
|
64
|
+
"regdate"=>"2023-09-04T14:53:08+03:00",
|
65
|
+
"country"=>{"id"=>"68", "code"=>"ru", "title"=>"Россия"},
|
66
|
+
"city"=>{"id"=>"0", "title"=>nil},
|
67
|
+
"sex"=>0,
|
68
|
+
"website"=>"",
|
69
|
+
"about"=>"",
|
70
|
+
"background"=>"/images/profile/smile_pattern.png",
|
71
|
+
"timezone"=>{"id"=>0, "zone"=>false},
|
72
|
+
"activated"=>1,
|
73
|
+
"stream"=>
|
74
|
+
{"id"=>id,
|
75
|
+
"key"=>"key",
|
76
|
+
"preview"=>"https://goodgame.ru/files/logotypes/ch_204504_N2ai.png",
|
77
|
+
"title"=>"title",
|
78
|
+
"viewers"=>0,
|
79
|
+
"streamer"=>
|
80
|
+
{"id"=>id,
|
81
|
+
"obj_key"=>"obj_key",
|
82
|
+
"nickname"=>"nickname",
|
83
|
+
"username"=>"username",
|
84
|
+
"avatar"=>"/files/avatars/av_avatar_elf.png"},
|
85
|
+
"stream_key"=>"stream_key",
|
86
|
+
"status"=>0,
|
87
|
+
"game"=>{"id"=>0, "title"=>nil, "url"=>"/games/"},
|
88
|
+
"poster"=>"poster_link",
|
89
|
+
"hidden"=>true,
|
90
|
+
"adult"=>true,
|
91
|
+
"link"=>"https://goodgame.ru/channel/your_channel/",
|
92
|
+
"watch_together"=>false,
|
93
|
+
"lastseen"=>lastseen,
|
94
|
+
"premiums"=>lastseen,
|
95
|
+
"followers"=>lastseen,
|
96
|
+
"rating"=>{"value"=>value, "place"=>place}},
|
97
|
+
"room"=>
|
98
|
+
{"user_id"=>User_id,
|
99
|
+
"style"=>0,
|
100
|
+
"walls"=>
|
101
|
+
["/files/pics.png"],
|
102
|
+
"exp"=>600,
|
103
|
+
"level"=>4,
|
104
|
+
"snapshot"=>"",
|
105
|
+
"items"=>nil},
|
106
|
+
"bnet"=>false,
|
107
|
+
"rights"=>0,
|
108
|
+
"email"=>"your@email",
|
109
|
+
"phone"=>0}}}
|
110
|
+
```
|
data/example/app.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sinatra"
|
4
|
+
require "omniauth"
|
5
|
+
require "omniauth-goodgame"
|
6
|
+
|
7
|
+
configure do
|
8
|
+
set port: 3000
|
9
|
+
set :sessions, true
|
10
|
+
end
|
11
|
+
|
12
|
+
use OmniAuth::Builder do
|
13
|
+
provider :goodgame, ENV["GOODGAME_CLIENT_ID"], ENV["GOODGAME_CLIENT_SECRET"],
|
14
|
+
display: "popup",
|
15
|
+
redirect_uri: "http://127.0.0.1:3000/auth/goodgame/callback"
|
16
|
+
end
|
17
|
+
|
18
|
+
get "/" do
|
19
|
+
<<-HTML
|
20
|
+
<form method='post' action='/auth/goodgame'>
|
21
|
+
<button type='submit'>Login with goodgame</button>
|
22
|
+
<input type="hidden" name="authenticity_token" value='#{request.env["rack.session"]["csrf"]}'>
|
23
|
+
</form>
|
24
|
+
HTML
|
25
|
+
end
|
26
|
+
|
27
|
+
get "/auth/:provider/callback" do
|
28
|
+
content_type "text/plain"
|
29
|
+
pp request.env["omniauth.auth"]
|
30
|
+
request.env["omniauth.auth"].info.to_hash.inspect
|
31
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<a href="/auth/goodgame"> Goodgame</a>
|
data/example/goodgame.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Goodgame < OmniAuth::Strategies::OAuth2
|
6
|
+
DEFAULT_SCOPE = ''
|
7
|
+
|
8
|
+
option :name, 'goodgame'
|
9
|
+
option :authorize_options, [:scope]
|
10
|
+
option :client_options, {
|
11
|
+
site: 'https://goodgame.ru',
|
12
|
+
authorize_url: '/oauth2/authorize',
|
13
|
+
token_url: '/oauth2/token',
|
14
|
+
auth_scheme: :request_body
|
15
|
+
}
|
16
|
+
option :access_token_options, {
|
17
|
+
header_format: 'Bearer %s',
|
18
|
+
param_name: 'access_token'
|
19
|
+
}
|
20
|
+
|
21
|
+
def request_phase
|
22
|
+
redirect client.auth_code
|
23
|
+
.authorize_url({ redirect_uri: callback_url }
|
24
|
+
.merge(authorize_params)).gsub(/%2[b,B]/, '+')
|
25
|
+
end
|
26
|
+
|
27
|
+
credentials do
|
28
|
+
hash = { 'token' => access_token.token }
|
29
|
+
hash['refresh_token'] = access_token.refresh_token if access_token.refresh_token
|
30
|
+
hash['expires_at'] = access_token.expires_at if access_token.expires?
|
31
|
+
hash['expires'] = access_token.expires?
|
32
|
+
hash
|
33
|
+
end
|
34
|
+
|
35
|
+
uid { raw_info['id'] }
|
36
|
+
|
37
|
+
info do
|
38
|
+
{
|
39
|
+
name: raw_info['username'],
|
40
|
+
email: raw_info['email'],
|
41
|
+
nickname: raw_info['nickname'],
|
42
|
+
streamid: raw_info['stream']['id']
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
extra do
|
47
|
+
{
|
48
|
+
raw_info:
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def raw_info
|
53
|
+
id = access_token.get("https://goodgame.ru/api/4/users/@me2?access_token=#{access_token.token}",
|
54
|
+
headers: { 'Accept' => 'application/json' }).parsed.fetch('id')
|
55
|
+
@raw_info =
|
56
|
+
access_token.get("https://goodgame.ru/api/4/users/#{id}?access_token=#{access_token.token}",
|
57
|
+
headers: { 'Accept' => 'application/json' }).parsed
|
58
|
+
end
|
59
|
+
|
60
|
+
def build_access_token
|
61
|
+
super.tap do |token|
|
62
|
+
token.options.merge!(access_token_options)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def access_token_options
|
67
|
+
options.access_token_options.each_with_object({}) do |(k, v), h|
|
68
|
+
h[k.to_sym] = v
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def callback_url
|
73
|
+
return options[:redirect_uri] unless options[:redirect_uri].nil?
|
74
|
+
|
75
|
+
full_host + script_name + callback_path
|
76
|
+
end
|
77
|
+
|
78
|
+
def authorize_params
|
79
|
+
super.tap do |params|
|
80
|
+
options[:authorize_options].each do |k|
|
81
|
+
params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
|
82
|
+
end
|
83
|
+
params[:scope] = params[:scope] || DEFAULT_SCOPE
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -6,7 +6,7 @@ module OmniAuth
|
|
6
6
|
DEFAULT_SCOPE = ''
|
7
7
|
|
8
8
|
option :name, 'goodgame'
|
9
|
-
option :authorize_options, %i[scope display]
|
9
|
+
option :authorize_options, %i[scope display redirect_uri]
|
10
10
|
option :client_options, {
|
11
11
|
site: 'https://goodgame.ru',
|
12
12
|
authorize_url: '/oauth2/authorize',
|
@@ -36,8 +36,10 @@ module OmniAuth
|
|
36
36
|
|
37
37
|
info do
|
38
38
|
{
|
39
|
-
name: raw_info['
|
40
|
-
|
39
|
+
name: raw_info['username'],
|
40
|
+
nickname: raw_info['nickname'],
|
41
|
+
email: raw_info['email'],
|
42
|
+
channel_id: raw_info['stream']['id']
|
41
43
|
}
|
42
44
|
end
|
43
45
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-goodgame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Seregin
|
@@ -38,6 +38,9 @@ files:
|
|
38
38
|
- Gemfile.lock
|
39
39
|
- LICENSE.txt
|
40
40
|
- README.md
|
41
|
+
- example/app.rb
|
42
|
+
- example/example.html
|
43
|
+
- example/goodgame.rb
|
41
44
|
- lib/omniauth-goodgame.rb
|
42
45
|
- lib/omniauth/goodgame.rb
|
43
46
|
- lib/omniauth/goodgame/version.rb
|