omniauth-wechat-oauth2 0.1.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -4
- data/lib/omniauth-wechat-oauth2.rb +1 -2
- data/lib/omniauth/strategies/wechat.rb +21 -15
- data/lib/omniauth/wechat.rb +2 -0
- metadata +21 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7957db81f8a3ca70305b81820dfad15f36eb1e4995ce4decb99515f9763539cf
|
4
|
+
data.tar.gz: d48c9cef8cb649a4b4c941f5d16328ea54cb13c21f8d9ab883a539defac22f99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a57cab028371e48d8f4e0c307e7172133c5b1a6715de8c8faaf63dc15702301e870a5192941427ed11c15f7b208b27af51ed260170002df34fc24d3d04fd74d1
|
7
|
+
data.tar.gz: 1a2af84613bf942a76a72d462e5196ab907378f7ef2ac6cf014ebf40eab41f7a22a743c3acff775e836bb5dc0dd7232b63157d6d98066d1e2ecf4a0dac2da205
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ Omniauth-wechat-oauth2
|
|
5
5
|
[![Security Check](https://hakiri.io/github/NeverMin/omniauth-wechat-oauth2/master.svg)][security]
|
6
6
|
[![Build Status](https://travis-ci.org/NeverMin/omniauth-wechat-oauth2.svg)][travis]
|
7
7
|
|
8
|
-
[gem]: https://rubygems.org/gems/omniauth-
|
8
|
+
[gem]: https://rubygems.org/gems/omniauth-wechat-oauth2
|
9
9
|
[security]: https://hakiri.io/github/NeverMin/omniauth-wechat-oauth2/master
|
10
10
|
[travis]: https://travis-ci.org/NeverMin/omniauth-wechat-oauth2
|
11
11
|
|
@@ -14,7 +14,8 @@ Wechat OAuth2 Strategy for OmniAuth 1.0.
|
|
14
14
|
|
15
15
|
You need to get a wechat API key at: https://mp.weixin.qq.com
|
16
16
|
|
17
|
-
Wechat oauth2 specification can be found at: https://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
|
17
|
+
* Wechat oauth2 specification can be found at: https://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
|
18
|
+
* Wechat Qiye oauth2 specification can be found at: http://qydev.weixin.qq.com/wiki/index.php?title=OAuth验证接口
|
18
19
|
|
19
20
|
## Installation
|
20
21
|
|
@@ -66,7 +67,8 @@ Here's an example of an authentication hash available in the callback by accessi
|
|
66
67
|
province: "Changning",
|
67
68
|
city: "Shanghai",
|
68
69
|
country: "China",
|
69
|
-
headimgurl: "http://image_url"
|
70
|
+
headimgurl: "http://image_url",
|
71
|
+
unionid: 'unionid'
|
70
72
|
},
|
71
73
|
:credentials => {
|
72
74
|
:token => "token",
|
@@ -82,12 +84,55 @@ Here's an example of an authentication hash available in the callback by accessi
|
|
82
84
|
province: "Changning",
|
83
85
|
city: "Shanghai",
|
84
86
|
country: "China",
|
85
|
-
headimgurl: "http://image_url"
|
87
|
+
headimgurl: "http://image_url",
|
88
|
+
unionid: 'unionid'
|
86
89
|
}
|
87
90
|
}
|
88
91
|
}
|
89
92
|
```
|
90
93
|
|
94
|
+
## Wechat Qiye OAuth2
|
91
95
|
|
96
|
+
Wechat Qiey usage and configuration are the same with normal account above.
|
92
97
|
|
98
|
+
```ruby
|
99
|
+
config.omniauth :wechat_qiye, ENV["WECHAT_APP_ID"], ENV["WECHAT_APP_SECRET"],
|
100
|
+
:authorize_params => {:scope => "snsapi_base"}
|
101
|
+
```
|
93
102
|
|
103
|
+
Auth hash `request.env["omniauth.auth"]`
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
{
|
107
|
+
:provider => "wechat_qiye",
|
108
|
+
:uid => "123456789",
|
109
|
+
:info => {
|
110
|
+
userid: "userid",
|
111
|
+
name: "name",
|
112
|
+
department: [2],
|
113
|
+
gender: "1",
|
114
|
+
weixinid: "weixinid",
|
115
|
+
avatar: "avatar",
|
116
|
+
status: 1,
|
117
|
+
extattr: {"foo" => "bar"}
|
118
|
+
},
|
119
|
+
:credentials => {
|
120
|
+
:token => "token",
|
121
|
+
:refresh_token => "another_token",
|
122
|
+
:expires_at => 7200,
|
123
|
+
:expires => true
|
124
|
+
},
|
125
|
+
:extra => {
|
126
|
+
:raw_info => {
|
127
|
+
userid: "userid",
|
128
|
+
name: "name",
|
129
|
+
department: [2],
|
130
|
+
gender: "1",
|
131
|
+
weixinid: "weixinid",
|
132
|
+
avatar: "avatar",
|
133
|
+
status: 1,
|
134
|
+
extattr: {"foo" => "bar"}}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
```
|
@@ -1,2 +1 @@
|
|
1
|
-
require "omniauth/
|
2
|
-
require "omniauth/strategies/wechat_qiye"
|
1
|
+
require "omniauth/wechat"
|
@@ -7,15 +7,19 @@ module OmniAuth
|
|
7
7
|
|
8
8
|
option :client_options, {
|
9
9
|
site: "https://api.weixin.qq.com",
|
10
|
-
authorize_url: "https://open.weixin.qq.com/connect/
|
10
|
+
authorize_url: "https://open.weixin.qq.com/connect/qrconnect?#wechat_redirect",
|
11
11
|
token_url: "/sns/oauth2/access_token",
|
12
12
|
token_method: :get
|
13
13
|
}
|
14
14
|
|
15
|
-
option :authorize_params, {scope: "
|
15
|
+
option :authorize_params, {scope: "snsapi_login"}
|
16
16
|
|
17
17
|
option :token_params, {parse: :json}
|
18
18
|
|
19
|
+
def callback_url
|
20
|
+
full_host + script_name + callback_path
|
21
|
+
end
|
22
|
+
|
19
23
|
uid do
|
20
24
|
raw_info['openid']
|
21
25
|
end
|
@@ -27,7 +31,9 @@ module OmniAuth
|
|
27
31
|
province: raw_info['province'],
|
28
32
|
city: raw_info['city'],
|
29
33
|
country: raw_info['country'],
|
30
|
-
headimgurl: raw_info['headimgurl']
|
34
|
+
headimgurl: raw_info['headimgurl'],
|
35
|
+
image: raw_info['headimgurl'],
|
36
|
+
unionid: raw_info['unionid']
|
31
37
|
}
|
32
38
|
end
|
33
39
|
|
@@ -36,8 +42,9 @@ module OmniAuth
|
|
36
42
|
end
|
37
43
|
|
38
44
|
def request_phase
|
39
|
-
params = client.auth_code.authorize_params.merge(
|
45
|
+
params = client.auth_code.authorize_params.merge(authorize_params)
|
40
46
|
params["appid"] = params.delete("client_id")
|
47
|
+
params["redirect_uri"] = callback_url
|
41
48
|
redirect client.authorize_url(params)
|
42
49
|
end
|
43
50
|
|
@@ -45,28 +52,27 @@ module OmniAuth
|
|
45
52
|
@uid ||= access_token["openid"]
|
46
53
|
@raw_info ||= begin
|
47
54
|
access_token.options[:mode] = :query
|
48
|
-
if access_token["scope"]
|
49
|
-
|
50
|
-
@raw_info = JSON.parse(response.body.gsub(/[\u0000-\u001f]+/, ''))
|
55
|
+
if access_token["scope"]&.include?("snsapi_login")
|
56
|
+
access_token.get("/sns/userinfo", :params => { "openid" => @uid, "lang" => "zh_CN" }, parse: :json).parsed
|
51
57
|
else
|
52
|
-
|
53
|
-
@raw_info.merge!("unionid" => access_token["unionid"]) if access_token["unionid"]
|
54
|
-
@raw_info
|
58
|
+
{ "openid" => @uid }
|
55
59
|
end
|
56
60
|
end
|
61
|
+
@raw_info
|
57
62
|
end
|
58
63
|
|
59
64
|
protected
|
60
65
|
def build_access_token
|
61
66
|
params = {
|
62
|
-
'appid'
|
63
|
-
'secret'
|
64
|
-
'code'
|
65
|
-
'grant_type'
|
67
|
+
'appid' => client.id,
|
68
|
+
'secret' => client.secret,
|
69
|
+
'code' => request.params['code'],
|
70
|
+
'grant_type' => 'authorization_code',
|
71
|
+
'redirect_uri' => callback_url
|
66
72
|
}.merge(token_params.to_hash(symbolize_keys: true))
|
67
73
|
client.get_token(params, deep_symbolize(options.auth_token_params))
|
68
74
|
end
|
69
75
|
|
70
76
|
end
|
71
77
|
end
|
72
|
-
end
|
78
|
+
end
|
metadata
CHANGED
@@ -1,63 +1,65 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-wechat-oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Alex Hu
|
8
8
|
- Never Min
|
9
|
-
|
9
|
+
- Eric Guo
|
10
|
+
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2020-06-12 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: omniauth
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
17
18
|
requirements:
|
18
|
-
- -
|
19
|
+
- - ">="
|
19
20
|
- !ruby/object:Gem::Version
|
20
21
|
version: 1.3.2
|
21
22
|
type: :runtime
|
22
23
|
prerelease: false
|
23
24
|
version_requirements: !ruby/object:Gem::Requirement
|
24
25
|
requirements:
|
25
|
-
- -
|
26
|
+
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
27
28
|
version: 1.3.2
|
28
29
|
- !ruby/object:Gem::Dependency
|
29
30
|
name: omniauth-oauth2
|
30
31
|
requirement: !ruby/object:Gem::Requirement
|
31
32
|
requirements:
|
32
|
-
- -
|
33
|
+
- - ">="
|
33
34
|
- !ruby/object:Gem::Version
|
34
35
|
version: 1.1.1
|
35
36
|
type: :runtime
|
36
37
|
prerelease: false
|
37
38
|
version_requirements: !ruby/object:Gem::Requirement
|
38
39
|
requirements:
|
39
|
-
- -
|
40
|
+
- - ">="
|
40
41
|
- !ruby/object:Gem::Version
|
41
42
|
version: 1.1.1
|
42
43
|
- !ruby/object:Gem::Dependency
|
43
44
|
name: rspec
|
44
45
|
requirement: !ruby/object:Gem::Requirement
|
45
46
|
requirements:
|
46
|
-
- - ~>
|
47
|
+
- - "~>"
|
47
48
|
- !ruby/object:Gem::Version
|
48
|
-
version: '2.
|
49
|
+
version: '2.99'
|
49
50
|
type: :development
|
50
51
|
prerelease: false
|
51
52
|
version_requirements: !ruby/object:Gem::Requirement
|
52
53
|
requirements:
|
53
|
-
- - ~>
|
54
|
+
- - "~>"
|
54
55
|
- !ruby/object:Gem::Version
|
55
|
-
version: '2.
|
56
|
+
version: '2.99'
|
56
57
|
description: Using OAuth2 to authenticate wechat user when web resources being viewed
|
57
58
|
within wechat(weixin) client.
|
58
59
|
email:
|
59
60
|
- askinnyworm@gmail.com
|
60
61
|
- Never.Min@gmail.com
|
62
|
+
- eric@cloud-mes.com
|
61
63
|
executables: []
|
62
64
|
extensions: []
|
63
65
|
extra_rdoc_files: []
|
@@ -66,29 +68,29 @@ files:
|
|
66
68
|
- lib/omniauth-wechat-oauth2.rb
|
67
69
|
- lib/omniauth/strategies/wechat.rb
|
68
70
|
- lib/omniauth/strategies/wechat_qiye.rb
|
71
|
+
- lib/omniauth/wechat.rb
|
69
72
|
homepage: https://github.com/nevermin/omniauth-wechat-oauth2
|
70
73
|
licenses:
|
71
74
|
- MIT
|
72
75
|
metadata: {}
|
73
|
-
post_install_message:
|
76
|
+
post_install_message:
|
74
77
|
rdoc_options: []
|
75
78
|
require_paths:
|
76
79
|
- lib
|
77
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
78
81
|
requirements:
|
79
|
-
- -
|
82
|
+
- - ">="
|
80
83
|
- !ruby/object:Gem::Version
|
81
|
-
version: 2.
|
84
|
+
version: 2.4.0
|
82
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
86
|
requirements:
|
84
|
-
- -
|
87
|
+
- - ">="
|
85
88
|
- !ruby/object:Gem::Version
|
86
89
|
version: '0'
|
87
90
|
requirements:
|
88
91
|
- none
|
89
|
-
|
90
|
-
|
91
|
-
signing_key:
|
92
|
+
rubygems_version: 3.1.4
|
93
|
+
signing_key:
|
92
94
|
specification_version: 4
|
93
95
|
summary: Omniauth strategy for wechat(weixin)
|
94
96
|
test_files: []
|