omniauth-goodgame 0.0.4 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e411f599f0ea95cd38842d919854edcdf1a4c05adc651487a2763668fb8ce9a1
4
- data.tar.gz: 311a27381db43067f26a614e0c82824b9e66846925da8b100197059346bc704a
3
+ metadata.gz: 4aff38db60ec33ad9b536d1f8e49f358bcea8b87449261ad4afc1b941a4882e1
4
+ data.tar.gz: a05d507800a2da66099297f3e29c9c1794c779ab5913cc85952a3c9849bb12c9
5
5
  SHA512:
6
- metadata.gz: e7d528d076239ecf71292c197e69eb431c767cfaaa5b9ed5dbe3018e8e34941a83e6b1b84d25c7ee148dabb3b88ca7357f7dcd3dc6a129011c9cedb50ee15014
7
- data.tar.gz: b62d6c67a00d91aaa54fa8a1b7c8595d9da79ebe07834dbc003407ed9c1d6e68f73b62db6098cb70a71aebafdabc91035f2a33d8fad36a320ed867a13ee4ad00
6
+ metadata.gz: 394475cc4f8f3378ad6bcc3d1be44230aea709c05b80ebbed9cd061f595f8d5242fb4c8360e6393463de9874ec9e7ee4e9e03d1e273c51798129338fa79c185d
7
+ data.tar.gz: a4b3e666d74e41e06c301fac958ff5daed39db3a5ec832aaeef266642c6fb42942df9401a119d6532c8f93a15dde0826ed2b75043b8da630e8133280a902e4a5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- omniauth-goodgame (0.0.4)
4
+ omniauth-goodgame (0.0.6)
5
5
  omniauth-oauth2 (~> 1.6)
6
6
 
7
7
  GEM
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 line to your application's Gemfile:
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
- TODO: Write usage instructions here
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
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/omniauth-goodgame. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/omniauth-goodgame/blob/master/CODE_OF_CONDUCT.md).
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
- Everyone interacting in the Omniauth::Goodgame project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/omniauth-goodgame/blob/master/CODE_OF_CONDUCT.md).
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>
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Omniauth
4
4
  module Goodgame
5
- VERSION = "0.0.4"
5
+ VERSION = "0.0.6"
6
6
  end
7
7
  end
@@ -1,60 +1,60 @@
1
- require "omniauth-oauth2"
1
+ require 'omniauth-oauth2'
2
2
 
3
3
  module OmniAuth
4
4
  module Strategies
5
5
  class Goodgame < OmniAuth::Strategies::OAuth2
6
- DEFAULT_SCOPE = ""
7
- option :name, "goodgame"
6
+ DEFAULT_SCOPE = ''
8
7
 
8
+ option :name, 'goodgame'
9
+ option :authorize_options, %i[scope display redirect_uri]
9
10
  option :client_options, {
10
- site: "https://goodgame.ru",
11
- authorize_url: "/oauth2/authorize",
12
- token_url: "/oauth2/token",
11
+ site: 'https://goodgame.ru',
12
+ authorize_url: '/oauth2/authorize',
13
+ token_url: '/oauth2/token',
13
14
  auth_scheme: :request_body
14
15
  }
15
-
16
16
  option :access_token_options, {
17
- header_format: "application/x-www-form-urlencoded",
18
- param_name: "access_token"
17
+ header_format: 'Bearer %s',
18
+ param_name: 'access_token'
19
19
  }
20
20
 
21
- option :authorize_options, [:scope]
22
-
23
21
  def request_phase
24
22
  redirect client.auth_code
25
23
  .authorize_url({ redirect_uri: callback_url }
26
- .merge(authorize_params)).gsub(/%2[b,B]/, "+")
24
+ .merge(authorize_params)).gsub(/%2[b,B]/, '+')
27
25
  end
28
26
 
29
27
  credentials do
30
- hash = { "token" => access_token.token }
31
- hash["refresh_token"] = access_token.refresh_token if access_token.refresh_token
32
- hash["expires_at"] = access_token.expires_at if access_token.expires?
33
- hash["expires"] = access_token.expires?
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?
34
32
  hash
35
33
  end
36
34
 
37
- uid { raw_info["id"] }
35
+ uid { raw_info['id'] }
38
36
 
39
37
  info do
40
38
  {
41
- name: raw_info["nickname"],
42
- email: raw_info["email"],
43
- nickname: raw_info["username"],
44
- description: raw_info["about"],
45
- image: raw_info["avatar"],
46
- urls: { Goodgame: raw_info["link"] }
39
+ name: raw_info['username'],
40
+ nickname: raw_info['nickname'],
41
+ email: raw_info['email'],
42
+ channel_id: raw_info['stream']['id']
47
43
  }
48
44
  end
45
+
49
46
  extra do
50
47
  {
51
- raw_info: raw_info
48
+ raw_info:
52
49
  }
53
50
  end
51
+
54
52
  def raw_info
55
- @raw_info ||=
56
- access_token.get("https://goodgame.ru/api/4/users/#{client.id}").parsed
57
- .fetch("data").fetch(0)
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
58
  end
59
59
 
60
60
  def build_access_token
@@ -78,7 +78,7 @@ module OmniAuth
78
78
  def authorize_params
79
79
  super.tap do |params|
80
80
  options[:authorize_options].each do |k|
81
- params[k] = request.params[k.to_s] unless [nil, ""].include?(request.params[k.to_s])
81
+ params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
82
82
  end
83
83
  params[:scope] = params[:scope] || DEFAULT_SCOPE
84
84
  end
@@ -86,3 +86,4 @@ module OmniAuth
86
86
  end
87
87
  end
88
88
  end
89
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-goodgame
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Seregin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-19 00:00:00.000000000 Z
11
+ date: 2023-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2
@@ -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