scavin-weibo-oauth2 0.5.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '083f92de3768df8a8d555578e960323c4d9703eb3b4fcbd8de6305de8c701269'
4
+ data.tar.gz: 5260aa704d6ace7722c2332cf8912a61926528c80064ffc3ab834d532d0d95a7
5
+ SHA512:
6
+ metadata.gz: 6aeebccf9159930199f3168c301499e8889433f5ffd0ba6b7b826a6cbd4d3c277154d9c61c9235245ca63354ee776fe781913a44f5d4fc651515595aea86c853
7
+ data.tar.gz: 22c81db39c2d89f43ac2e3f6e0b231df40c817a2f5cd3b4d0c4eb2b15fe1a10fc17c47e6867617d9326cf8677cc8e35a46f624143f8c68d8ddb6db848640eb82
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ *.swp
3
+ .gem
4
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ before_install:
2
+ - gem update --system 2.1.11
3
+ language: ruby
4
+ rvm:
5
+ - "2.4.1"
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-weibo-oauth2.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'rb-fsevent'
11
+ gem 'growl'
12
+ gem 'rake'
13
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2012-2017 Bin He
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # Status
2
+ [![Gem Version](https://img.shields.io/gem/v/omniauth-weibo-oauth2.svg)][gem]
3
+ [![Security Check](https://hakiri.io/github/beenhero/omniauth-weibo-oauth2/master.svg)][security]
4
+ [![Percentage of issues still open](https://isitmaintained.com/badge/open/beenhero/omniauth-weibo-oauth2.svg)][OpenIssues]
5
+ [![Average time to resolve an issue](https://isitmaintained.com/badge/resolution/beenhero/omniauth-weibo-oauth2.svg)][IssueResolution]
6
+ [![Build Status](https://travis-ci.org/NeverMin/omniauth-weibo-oauth2.svg?branch=master)][travis]
7
+
8
+ [gem]: https://rubygems.org/gems/omniauth-weibo-oauth2
9
+ [security]: https://hakiri.io/github/beenhero/omniauth-weibo-oauth2/master
10
+ [OpenIssues]: https://isitmaintained.com/project/beenhero/omniauth-weibo-oauth2
11
+ [IssueResolution]: https://isitmaintained.com/project/beenhero/omniauth-weibo-oauth2
12
+ [travis]: https://travis-ci.org/NeverMin/omniauth-weibo-oauth2
13
+
14
+
15
+
16
+ # OmniAuth Weibo OAuth2
17
+
18
+ Weibo OAuth2 Strategy for OmniAuth 1.0.
19
+
20
+ Read Weibo OAuth2 docs for more details: https://open.weibo.com/wiki/授权机制
21
+
22
+ ## Security
23
+
24
+ - CVE-2019-17268 [Issue #36](https://github.com/beenhero/omniauth-weibo-oauth2/issues/36)
25
+
26
+ ## Installing
27
+
28
+ Add to your `Gemfile`:
29
+
30
+ ```ruby
31
+ gem 'omniauth-weibo-oauth2'
32
+ ```
33
+
34
+ Then `bundle install`.
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install omniauth-weibo-oauth2
39
+
40
+ ## Usage
41
+
42
+ `OmniAuth::Strategies::Weibo` is simply a Rack middleware. Read the OmniAuth 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.
43
+
44
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
45
+
46
+ ```ruby
47
+ Rails.application.config.middleware.use OmniAuth::Builder do
48
+ provider :weibo, ENV['WEIBO_KEY'], ENV['WEIBO_SECRET']
49
+ end
50
+ ```
51
+ ## Configuration
52
+
53
+ you can set up redirect_uri in `omniauth.rb` as following:
54
+
55
+ ```ruby
56
+ provider :weibo, ENV['WEIBO_KEY'], ENV['WEIBO_SECRET'],
57
+ token_params: {redirect_uri: "http://127.0.0.1:3000/auth/weibo/callback" }
58
+ ```
59
+
60
+ ## Authentication Option
61
+ * **image_size**: This option defines the size of the user's image in *Authentication Hash* (info['image']). Valid options include `small` (30x30), `middle` (50x50), `large` (180x180) and `original` (the size of the image originally uploaded). Default is `middle`.
62
+
63
+ ```ruby
64
+ Rails.application.config.middleware.use OmniAuth::Builder do
65
+ provider :weibo, ENV['WEIBO_KEY'], ENV['WEIBO_SECRET'], :image_size => 'original'
66
+ end
67
+ ```
68
+
69
+ ## Authentication Hash
70
+
71
+ Here's an example *Authentication Hash* available in `request.env['omniauth.auth']`:
72
+
73
+ ```ruby
74
+ {
75
+ :provider => 'weibo',
76
+ :uid => '1234567890',
77
+ :info => {
78
+ :nickname => 'beenhero',
79
+ :name => 'beenhero',
80
+ :location => '浙江 杭州',
81
+ :image => 'http://tp4.sinaimg.cn/1640099215/50/1287016234/1',
82
+ :description => '移步twitter@beenhero',
83
+ :urls => { :Blog => 'http://beenhero.com'
84
+ :Weibo => 'http://weibo.com/beenhero'
85
+ },
86
+ },
87
+ :credentials => {
88
+ :token => '2.00JjgzmBd7F...', # OAuth 2.0 access_token, which you may wish to store
89
+ :expires_at => 1331780640, # when the access token expires (if it expires)
90
+ :expires => true # if you request `offline_access` this will be false
91
+ },
92
+ :extra => {
93
+ :raw_info => {
94
+ ... # data from /2/users/show.json, check by yourself
95
+ }
96
+ }
97
+ }
98
+ ```
99
+ *PS.* Built and tested on MRI Ruby 2.4.2
100
+
101
+ ## Build&pulish gem
102
+ ```
103
+ gem build omniauth-weibo-oauth2.gemspec
104
+ ```
105
+
106
+ ```
107
+ gem push omniauth-weibo-oauth2-VERSION.gem
108
+ ```
109
+
110
+ ## Contributing
111
+
112
+ 1. Fork it
113
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
114
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
115
+ 4. Push to the branch (`git push origin my-new-feature`)
116
+ 5. Create new Pull Request
117
+
118
+ ## License
119
+ Copyright (c) 2012-2017 by Bin He, See [LICENSE][] for details.
120
+
121
+ [license]: LICENSE.md
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require File.join('bundler', 'gem_tasks')
3
+ require File.join('rspec', 'core', 'rake_task')
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
Binary file
@@ -0,0 +1,136 @@
1
+ require "omniauth-oauth2"
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Weibo < OmniAuth::Strategies::OAuth2
6
+ option :client_options, {
7
+ :site => "https://api.weibo.com",
8
+ :authorize_url => "/oauth2/authorize",
9
+ :token_url => "/oauth2/access_token",
10
+ :token_method => :post
11
+ }
12
+ option :token_params, {
13
+ :parse => :json
14
+ }
15
+
16
+ uid do
17
+ raw_info['id']
18
+ end
19
+
20
+ info do
21
+ {
22
+ :nickname => raw_info['screen_name'],
23
+ :name => raw_info['name'],
24
+ :location => raw_info['location'],
25
+ :image => image_url,
26
+ :description => raw_info['description'],
27
+ :urls => {
28
+ 'Blog' => raw_info['url'],
29
+ 'Weibo' => raw_info['domain'].empty? ? "https://weibo.com/u/#{raw_info['id']}" : "https://weibo.com/#{raw_info['domain']}",
30
+ }
31
+ }
32
+ end
33
+
34
+ extra do
35
+ {
36
+ :raw_info => raw_info
37
+ }
38
+ end
39
+
40
+ def callback_url
41
+ token_params_redirect || (full_host + script_name + callback_path)
42
+ end
43
+
44
+ def token_params_redirect
45
+ token_params['redirect_uri'] || token_params[:redirect_uri]
46
+ end
47
+
48
+ def raw_info
49
+ access_token.options[:mode] = :query
50
+ access_token.options[:param_name] = 'access_token'
51
+ @uid ||= access_token.get('/2/account/get_uid.json').parsed["uid"]
52
+ @raw_info ||= access_token.get("/2/users/show.json", :params => {:uid => @uid}).parsed
53
+ end
54
+
55
+ def find_image
56
+ raw_info[%w(avatar_hd avatar_large profile_image_url).find { |e| raw_info[e].present? }]
57
+ end
58
+
59
+ #url: option: size:
60
+ #avatar_hd original original_size
61
+ #avatar_large large 180x180
62
+ #profile_image_url middle 50x50
63
+ # small 30x30
64
+ #default is middle
65
+ def image_url
66
+ image_size = options[:image_size] || :middle
67
+ case image_size.to_sym
68
+ when :original
69
+ url = raw_info['avatar_hd']
70
+ when :large
71
+ url = raw_info['avatar_large']
72
+ when :small
73
+ url = raw_info['avatar_large'].sub('/180/','/30/')
74
+ else
75
+ url = raw_info['profile_image_url']
76
+ end
77
+ end
78
+
79
+ ##
80
+ # You can pass +display+, +with_offical_account+ or +state+ params to the auth request, if
81
+ # you need to set them dynamically. You can also set these options
82
+ # in the OmniAuth config :authorize_params option.
83
+ #
84
+ # /auth/weibo?display=mobile&with_offical_account=1
85
+ #
86
+ def authorize_params
87
+ super.tap do |params|
88
+ %w[display with_offical_account forcelogin].each do |v|
89
+ if request.params[v]
90
+ params[v.to_sym] = request.params[v]
91
+ end
92
+ end
93
+ # Ensure state parameter is properly set for CSRF protection
94
+ session['omniauth.state'] = params[:state] = SecureRandom.hex(24)
95
+ end
96
+ end
97
+
98
+ def request_phase
99
+ if request.request_method != 'POST' && !OmniAuth.config.silence_get_warning
100
+ raise OmniAuth::NoSessionError.new("HTTP GET is not allowed for OmniAuth requests. See https://github.com/omniauth/omniauth/wiki/Resolving-CVE-2015-9284")
101
+ end
102
+ super
103
+ end
104
+
105
+ protected
106
+ def build_access_token
107
+ params = {
108
+ 'client_id' => client.id,
109
+ 'client_secret' => client.secret,
110
+ 'code' => request.params['code'],
111
+ 'grant_type' => 'authorization_code',
112
+ 'redirect_uri' => callback_url
113
+ }.merge(token_params.to_hash(symbolize_keys: true))
114
+ begin
115
+ client.get_token(params, deep_symbolize(options.token_params))
116
+ rescue ::OAuth2::Error => e
117
+ raise OmniAuth::Strategies::OAuth2::Error.new(e)
118
+ rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
119
+ raise OmniAuth::Strategies::OAuth2::Error.new(e)
120
+ end
121
+ end
122
+
123
+ def callback_phase
124
+ super
125
+ rescue ::OAuth2::Error => e
126
+ fail!(:invalid_credentials, e)
127
+ rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
128
+ fail!(:timeout, e)
129
+ rescue ::SocketError => e
130
+ fail!(:failed_to_connect, e)
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ OmniAuth.config.add_camelization "weibo", "Weibo"
@@ -0,0 +1,21 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ class WeiboPostMiddleware
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ # 检查是否是认证请求
10
+ if env['PATH_INFO'] =~ /\/auth\/weibo(\/callback)?/
11
+ # 如果是 GET 请求,将其转换为 POST 请求
12
+ if env['REQUEST_METHOD'] == 'GET'
13
+ env['REQUEST_METHOD'] = 'POST'
14
+ end
15
+ end
16
+
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module WeiboOauth2
3
+ VERSION = "0.5.3"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-weibo-oauth2/version"
2
+ require 'omniauth/strategies/weibo'
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-weibo-oauth2/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = "Scavin"
6
+ gem.email = "contact@appinn.com"
7
+ gem.description = %q{OmniAuth Oauth2 strategy for weibo.com.2025}
8
+ gem.summary = %q{OmniAuth Oauth2 strategy for weibo.com.}
9
+ gem.homepage = "https://github.com/scavin/omniauth-weibo-oauth2"
10
+ gem.license = "MIT"
11
+
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.name = "scavin-weibo-oauth2"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = OmniAuth::WeiboOauth2::VERSION
18
+
19
+ gem.add_dependency 'omniauth', '~> 2.0'
20
+ gem.add_dependency 'omniauth-oauth2', '~> 1.4', '>= 1.4.0'
21
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scavin-weibo-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.3
5
+ platform: ruby
6
+ authors:
7
+ - Scavin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-02-26 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-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.0
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '1.4'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.4.0
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.4'
47
+ description: OmniAuth Oauth2 strategy for weibo.com.2025
48
+ email: contact@appinn.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - ".gitignore"
54
+ - ".travis.yml"
55
+ - Gemfile
56
+ - LICENSE.md
57
+ - README.md
58
+ - Rakefile
59
+ - lib/omniauth-weibo-oauth2.rb
60
+ - lib/omniauth-weibo-oauth2/version.rb
61
+ - lib/omniauth/.DS_Store
62
+ - lib/omniauth/strategies/weibo.rb
63
+ - lib/omniauth/strategies/weibo_post_middleware.rb
64
+ - scavin-weibo-oauth2.gemspec
65
+ homepage: https://github.com/scavin/omniauth-weibo-oauth2
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.0.3.1
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: OmniAuth Oauth2 strategy for weibo.com.
88
+ test_files: []