clwy-omniauth-qq 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e5da09b54bd5c6542e7549a4a049cdcd6f7087996a4269d312600315dd851102
4
+ data.tar.gz: 2a35029801317a314fe0d0c7fd45097a44417810ee03a5e8aabbfa40c5c4e132
5
+ SHA512:
6
+ metadata.gz: abe94de8792ee85ad945f43c198714fbb9cb3ecff649bad748b2bd8ac57b8e2b26fb11b0c77664a2a266ff6341ec435b5dddadc36fbf72a6e8da821b128b6473
7
+ data.tar.gz: 9835a70a96733624ca5f0c6376a7cb2dbe374ac766d650b644d3116a71dea0cafaed36a02f5d0a58062d6b193fde250fa4c8e4bc530b6ff3534260db100e9427
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
19
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in clwy-omniauth-qq.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # Omniauth QQ
2
+
3
+ This is QQ strategies collection for OmniAuth 2.0, which includes TQQ and QQ-Connect.
4
+
5
+ This gem package is forked from [beenhero/omniauth-qq](https://github.com/beenhero/omniauth-qq).
6
+ Since the original package has not been maintained for a long time, the dependent omniauth version has fallen seriously behind.
7
+ It conflicts with packages like omniauth-github within the same project. Therefore, it was forked and modified for maintenance purposes.
8
+
9
+ ## [TQQ](http://open.t.qq.com/) OAuth
10
+ Strategy from https://github.com/ballantyne/omniauth-tqq, credit go to Scott Ballantyne.
11
+ Please note that some modifies had written into for my own purpose, like: raw_info attributes rewrote.
12
+
13
+ ## [QQ-Connect](http://connect.qq.com/intro/login/) OAuth2
14
+ Strategy from https://github.com/kaichen/omniauth-qq-connect, credit go to Kai Chen.
15
+
16
+ ## Installation
17
+
18
+ Add to your `Gemfile`:
19
+
20
+ ```ruby
21
+ gem "clwy-clwy-omniauth-qq"
22
+ ```
23
+
24
+ Then `bundle install`.
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install clwy-omniauth-qq
29
+
30
+ ## Usage
31
+
32
+ `OmniAuth::Strategies::Qq` is simply a Rack middleware. Read the OmniAuth 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.
33
+
34
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
35
+
36
+ ```ruby
37
+ Rails.application.config.middleware.use OmniAuth::Builder do
38
+ provider :tqq, ENV['TQQ_KEY'], ENV['TQQ_SECRET']
39
+ provider :qq_connect, ENV['QQ_CONNECT_KEY'], ENV['QQ_CONNECT_SECRET']
40
+ end
41
+ ```
42
+
43
+ ## Authentication Hash
44
+
45
+ Here's an example *Authentication Hash* available in `request.env['omniauth.auth']`:
46
+
47
+ ### TQQ returns:
48
+
49
+ ```ruby
50
+ {
51
+ :provider => 'tqq',
52
+ :uid => 'B11630C4...', # QQ call it openid
53
+ :info => {
54
+ :nickname => 'beenhero',
55
+ :email => '',
56
+ :name => 'beenhero',
57
+ :location => '杭州',
58
+ :image => 'http://app.qlogo.cn/mbloghead/b8bc8cee839d42d1824c/40',
59
+ :description => '碳水化合物而已',
60
+ :urls => { :Tqq => 't.qq.com/beenhero' },
61
+ },
62
+ :credentials => {
63
+ :token => '2.00JjgzmBd7F...', # OAuth access_token, which you may wish to store
64
+ :secret => 'ac737720847e...',
65
+ },
66
+ :extra => {
67
+ :raw_info => {
68
+ :data => {
69
+ ... # data from http://open.t.qq.com/api/user/info?format=json, check by yourself
70
+ },
71
+ # extracted some general named attribute from [date]
72
+ :gender => 'm', # m: male, f: female, '': none
73
+ :followers_count: 53,
74
+ :friends_count: 14,
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ ### QQ-Connect returns:
81
+
82
+ ```ruby
83
+ {
84
+ :provider => 'qq_connect',
85
+ :uid => 'B11630C4...', # QQ call it openid
86
+ :info => {
87
+ :nickname => 'beenhero',
88
+ :image => 'http://qzapp.qlogo.cn/qzapp/100250034/B11630C4AAC8C17B57ECFEA80852C813/50',
89
+ # so little info !? I think so, QQ-Connect only provides so, you can check from the raw_info below. Or you can try TQQ instead :)
90
+ },
91
+ :credentials => {
92
+ :token => '2.00JjgzmBd7F...', # OAuth 2.0 access_token, which you may wish to store
93
+ :expires_at => 1331780640, # when the access token expires (if it expires)
94
+ :expires => true # if you request `offline_access` this will be false
95
+ },
96
+ :extra => {
97
+ :raw_info => {
98
+ ... # little info from https://graph.qq.com/user/get_user_info
99
+ }
100
+ }
101
+ }
102
+ ```
103
+
104
+ ## License
105
+
106
+ MIT License
107
+
108
+ Permission is hereby granted, free of charge, to any person obtaining
109
+ a copy of this software and associated documentation files (the
110
+ "Software"), to deal in the Software without restriction, including
111
+ without limitation the rights to use, copy, modify, merge, publish,
112
+ distribute, sublicense, and/or sell copies of the Software, and to
113
+ permit persons to whom the Software is furnished to do so, subject to
114
+ the following conditions:
115
+
116
+ The above copyright notice and this permission notice shall be
117
+ included in all copies or substantial portions of the Software.
118
+
119
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
120
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
121
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
122
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
123
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
124
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
125
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/clwy-omniauth-qq/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Liu Dong"]
6
+ gem.email = ["support@clwy.cn"]
7
+ gem.description = %q{OmniAuth strategies for TQQ and QQ Connect).}
8
+ gem.summary = %q{OmniAuth strategies for TQQ and QQ Connect).}
9
+ gem.homepage = "https://github.com/clwy-cn/clwy-omniauth-qq"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "clwy-omniauth-qq"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = ClwyOmniauth::QQ::VERSION
17
+
18
+ gem.add_dependency 'omniauth', '~> 2.0'
19
+ gem.add_dependency 'omniauth-oauth', '~> 1.2'
20
+ gem.add_dependency 'omniauth-oauth2', '~> 1.8'
21
+ gem.add_dependency 'multi_json'
22
+ end
@@ -0,0 +1,5 @@
1
+ module ClwyOmniauth
2
+ module QQ
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require "clwy-omniauth-qq/version"
2
+ require 'omniauth/strategies/qq_connect'
3
+ require 'omniauth/strategies/tqq'
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ require 'omniauth/strategies/oauth2'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class QQConnect < OmniAuth::Strategies::OAuth2
8
+ option :name, "qq_connect"
9
+
10
+ option :client_options, {
11
+ :site => 'https://graph.qq.com/oauth2.0/',
12
+ :authorize_url => '/oauth2.0/authorize',
13
+ :token_url => "/oauth2.0/token"
14
+ }
15
+
16
+ option :token_params, {
17
+ :state => 'foobar',
18
+ :parse => :query
19
+ }
20
+
21
+ uid do
22
+ @uid ||= begin
23
+ access_token.options[:mode] = :query
24
+ access_token.options[:param_name] = :access_token
25
+ # Response Example: "callback( {\"client_id\":\"11111\",\"openid\":\"000000FFFF\"} );\n"
26
+ response = access_token.get('/oauth2.0/me')
27
+ #TODO handle error case
28
+ matched = response.body.match(/"openid":"(?<openid>\w+)"/)
29
+ matched[:openid]
30
+ end
31
+ end
32
+
33
+ info do
34
+ {
35
+ :nickname => raw_info['nickname'],
36
+ :name => raw_info['nickname'],
37
+ :image => raw_info['figureurl_1'],
38
+ }
39
+ end
40
+
41
+ extra do
42
+ {
43
+ :raw_info => raw_info
44
+ }
45
+ end
46
+
47
+ def raw_info
48
+ @raw_info ||= begin
49
+ #TODO handle error case
50
+ #TODO make info request url configurable
51
+ client.request(:get, "https://graph.qq.com/user/get_user_info", :params => {
52
+ :format => :json,
53
+ :openid => uid,
54
+ :oauth_consumer_key => options[:client_id],
55
+ :access_token => access_token.token
56
+ }, :parse => :json).parsed
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ OmniAuth.config.add_camelization('qq_connect', 'QQConnect')
@@ -0,0 +1,83 @@
1
+ require 'omniauth-oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Tqq < OmniAuth::Strategies::OAuth
7
+ option :name, 'tqq'
8
+ option :sign_in, true
9
+ def initialize(*args)
10
+ super
11
+ # taken from https://github.com/intridea/omniauth/blob/0-3-stable/oa-oauth/lib/omniauth/strategies/oauth/tqq.rb#L15-24
12
+ options.client_options = {
13
+ :access_token_path => '/cgi-bin/access_token',
14
+ :authorize_path => '/cgi-bin/authorize',
15
+ :http_method => :get,
16
+ :nonce => nonce,
17
+ :realm => 'OmniAuth',
18
+ :request_token_path => '/cgi-bin/request_token',
19
+ :scheme => :query_string,
20
+ :site => 'https://open.t.qq.com',
21
+ }
22
+ end
23
+
24
+ # https://github.com/intridea/omniauth/blob/0-3-stable/oa-oauth/lib/omniauth/strategies/oauth/tqq.rb#L28-30
25
+ def nonce
26
+ Base64.encode64(OpenSSL::Random.random_bytes(32)).gsub(/\W/, '')[0, 32]
27
+ end
28
+
29
+ def consumer
30
+ consumer = ::OAuth::Consumer.new(options.consumer_key, options.consumer_secret, options.client_options)
31
+ consumer
32
+ end
33
+
34
+ uid { raw_info['data']['openid'] }
35
+
36
+ info do
37
+ {
38
+ :nickname => raw_info['data']['nick'],
39
+ :email => (raw_info['data']['email'] if raw_info['data']['email'].present?),
40
+ :name => raw_info['data']['name'],
41
+ :location => raw_info['data']['location'],
42
+ :image => (raw_info['data']['head']+'/40' if raw_info['data']['head'].present?),
43
+ :description => raw_info['data']['introduction'],
44
+ :urls => {
45
+ 'Tqq' => 't.qq.com/' + raw_info['data']['name']
46
+ }
47
+ }
48
+ end
49
+
50
+ extra do
51
+ # rename some attribute to my own needs.
52
+ raw_info['gender'] ||= raw_info['data']['sex'] == 1 ? 'm' : (raw_info['data']['sex'] == 2 ? 'f' : '')
53
+ raw_info['followers_count'] ||= raw_info['data']['fansnum']
54
+ raw_info['friends_count'] ||= raw_info['data']['idolnum']
55
+ { :raw_info => raw_info }
56
+ end
57
+
58
+ #taken from https://github.com/intridea/omniauth/blob/0-3-stable/oa-oauth/lib/omniauth/strategies/oauth/tsina.rb#L52-67
59
+ def request_phase
60
+ request_token = consumer.get_request_token(:oauth_callback => callback_url)
61
+ session['oauth'] ||= {}
62
+ session['oauth'][name.to_s] = {'callback_confirmed' => true, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
63
+
64
+ if request_token.callback_confirmed?
65
+ redirect request_token.authorize_url(options[:authorize_params])
66
+ else
67
+ redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url))
68
+ end
69
+
70
+ rescue ::Timeout::Error => e
71
+ fail!(:timeout, e)
72
+ rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
73
+ fail!(:service_unavailable, e)
74
+ end
75
+
76
+ def raw_info
77
+ @raw_info ||= MultiJson.decode(access_token.get('http://open.t.qq.com/api/user/info?format=json').body)
78
+ rescue ::Errno::ETIMEDOUT
79
+ raise ::Timeout::Error
80
+ end
81
+ end
82
+ end
83
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clwy-omniauth-qq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Liu Dong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: omniauth-oauth2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: multi_json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: OmniAuth strategies for TQQ and QQ Connect).
70
+ email:
71
+ - support@clwy.cn
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - README.md
79
+ - Rakefile
80
+ - clwy-omniauth-qq.gemspec
81
+ - lib/clwy-omniauth-qq.rb
82
+ - lib/clwy-omniauth-qq/version.rb
83
+ - lib/omniauth/strategies/qq_connect.rb
84
+ - lib/omniauth/strategies/tqq.rb
85
+ homepage: https://github.com/clwy-cn/clwy-omniauth-qq
86
+ licenses: []
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubygems_version: 3.5.3
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: OmniAuth strategies for TQQ and QQ Connect).
107
+ test_files: []