scavin-weibo-oauth2 0.5.6 → 0.5.7
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/lib/omniauth/strategies/weibo.rb +5 -42
- data/lib/scavin-weibo-oauth2/version.rb +1 -1
- data/scavin-weibo-oauth2-0.5.6.gem +0 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee14837dc969fc19b8ff0496011aa51033331f48a9247fe463b38b45a3511db4
|
4
|
+
data.tar.gz: 80ad22f904f2a589a397e79f8bf57315986e0d282743ff1e69ba90359e888c3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9547014ecb3a1fe028a59d0510a3853e5aafd73fe0a4707b18d0df79015ba1372d184921f223db15d19540870fb83671cbc83676481dc986f59597f08c32c65b
|
7
|
+
data.tar.gz: 203cca9522e526bfba1e505ef5ce5427b77a55115521ebcc8f015c4ed06491c71a290a27b796547793bae943ad5f0d8efb204dbd7f67eeeaa50e9a39c8fc5d91
|
@@ -1,8 +1,11 @@
|
|
1
1
|
require "omniauth-oauth2"
|
2
|
+
require "oauth2"
|
2
3
|
|
3
4
|
module OmniAuth
|
4
5
|
module Strategies
|
5
6
|
class Weibo < OmniAuth::Strategies::OAuth2
|
7
|
+
class Error < OAuth2::Error; end
|
8
|
+
|
6
9
|
option :client_options, {
|
7
10
|
:site => "https://api.weibo.com",
|
8
11
|
:authorize_url => "/oauth2/authorize",
|
@@ -50,18 +53,14 @@ module OmniAuth
|
|
50
53
|
access_token.options[:param_name] = 'access_token'
|
51
54
|
@uid ||= access_token.get('/2/account/get_uid.json').parsed["uid"]
|
52
55
|
@raw_info ||= access_token.get("/2/users/show.json", :params => {:uid => @uid}).parsed
|
56
|
+
rescue ::OAuth2::Error => e
|
57
|
+
raise Error.new(e.response)
|
53
58
|
end
|
54
59
|
|
55
60
|
def find_image
|
56
61
|
raw_info[%w(avatar_hd avatar_large profile_image_url).find { |e| raw_info[e].present? }]
|
57
62
|
end
|
58
63
|
|
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
64
|
def image_url
|
66
65
|
image_size = options[:image_size] || :middle
|
67
66
|
case image_size.to_sym
|
@@ -76,13 +75,6 @@ module OmniAuth
|
|
76
75
|
end
|
77
76
|
end
|
78
77
|
|
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
78
|
def authorize_params
|
87
79
|
super.tap do |params|
|
88
80
|
%w[display with_offical_account forcelogin].each do |v|
|
@@ -90,7 +82,6 @@ module OmniAuth
|
|
90
82
|
params[v.to_sym] = request.params[v]
|
91
83
|
end
|
92
84
|
end
|
93
|
-
# Ensure state parameter is properly set for CSRF protection
|
94
85
|
session['omniauth.state'] = params[:state] = SecureRandom.hex(24)
|
95
86
|
end
|
96
87
|
end
|
@@ -101,34 +92,6 @@ module OmniAuth
|
|
101
92
|
end
|
102
93
|
super
|
103
94
|
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
95
|
end
|
133
96
|
end
|
134
97
|
end
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scavin-weibo-oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scavin
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- scavin-weibo-oauth2-0.5.3.gem
|
65
65
|
- scavin-weibo-oauth2-0.5.4.gem
|
66
66
|
- scavin-weibo-oauth2-0.5.5.gem
|
67
|
+
- scavin-weibo-oauth2-0.5.6.gem
|
67
68
|
- scavin-weibo-oauth2.gemspec
|
68
69
|
homepage: https://github.com/scavin/omniauth-weibo-oauth2
|
69
70
|
licenses:
|