omniauth-wechat-oauth2 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +12 -3
- data/lib/omniauth-wechat-oauth2.rb +1 -0
- data/lib/omniauth/strategies/wechat.rb +4 -1
- data/lib/omniauth/strategies/wechat_qiye.rb +80 -0
- metadata +17 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 90919b05aecd6b3de0d6d41e1c0e18bac5abbc10d70a2d59c406a4acc139cb99
|
4
|
+
data.tar.gz: 70f0b3689eabd805a81e15c4ecc7ea80e68c2f1dfde663472d8f74807b9aa5df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec12ab658d9e4a71ad8d7fee8af7e2a14d6884fb13fa92f70004becd5598bbffdc6a668b21089ef74d9e7a7c39e9138f2754f43eac7d67b5fadd8c3e133feef8
|
7
|
+
data.tar.gz: 940c92c6ea780000f4b0a3cc1c207cee2828f2c7ae635825ae0e63a9ed1d32869de39fd75dfed0bef60f49675a95ec6900ca3e7ae0b8da8d902f62b19ae26f34
|
data/README.md
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
Omniauth-wechat-oauth2
|
2
2
|
======================
|
3
3
|
|
4
|
-
|
4
|
+
[![Gem Version](https://img.shields.io/gem/v/omniauth-wechat-oauth2.svg)][gem]
|
5
|
+
[![Security Check](https://hakiri.io/github/NeverMin/omniauth-wechat-oauth2/master.svg)][security]
|
6
|
+
[![Build Status](https://travis-ci.org/NeverMin/omniauth-wechat-oauth2.svg)][travis]
|
5
7
|
|
6
|
-
|
8
|
+
[gem]: https://rubygems.org/gems/omniauth-weibo-oauth2
|
9
|
+
[security]: https://hakiri.io/github/NeverMin/omniauth-wechat-oauth2/master
|
10
|
+
[travis]: https://travis-ci.org/NeverMin/omniauth-wechat-oauth2
|
7
11
|
|
8
|
-
|
12
|
+
|
13
|
+
Wechat OAuth2 Strategy for OmniAuth 1.0.
|
14
|
+
|
15
|
+
You need to get a wechat API key at: https://mp.weixin.qq.com
|
16
|
+
|
17
|
+
Wechat oauth2 specification can be found at: https://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
|
9
18
|
|
10
19
|
## Installation
|
11
20
|
|
@@ -46,9 +46,12 @@ module OmniAuth
|
|
46
46
|
@raw_info ||= begin
|
47
47
|
access_token.options[:mode] = :query
|
48
48
|
if access_token["scope"] == "snsapi_userinfo"
|
49
|
-
|
49
|
+
response = access_token.get("/sns/userinfo", :params => {"openid" => @uid, "lang" => "zh_CN"}, parse: :text)
|
50
|
+
@raw_info = JSON.parse(response.body.gsub(/[\u0000-\u001f]+/, ''))
|
50
51
|
else
|
51
52
|
@raw_info = {"openid" => @uid }
|
53
|
+
@raw_info.merge!("unionid" => access_token["unionid"]) if access_token["unionid"]
|
54
|
+
@raw_info
|
52
55
|
end
|
53
56
|
end
|
54
57
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require "omniauth-oauth2"
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class WechatQiye < OmniAuth::Strategies::OAuth2
|
6
|
+
option :name, "wechat_qiye"
|
7
|
+
|
8
|
+
option :client_options, {
|
9
|
+
:site => "https://qyapi.weixin.qq.com",
|
10
|
+
authorize_url: "https://open.weixin.qq.com/connect/oauth2/authorize#wechat_redirect",
|
11
|
+
token_url: "/cgi-bin/gettoken",
|
12
|
+
token_method: :get,
|
13
|
+
connection_opts: {
|
14
|
+
ssl: { verify: false }
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
option :authorize_params, {scope: "snsapi_userinfo"}
|
19
|
+
option :token_params, {parse: :json}
|
20
|
+
|
21
|
+
uid do
|
22
|
+
raw_info['userid']
|
23
|
+
end
|
24
|
+
|
25
|
+
info do
|
26
|
+
{
|
27
|
+
userid: raw_info['userid'],
|
28
|
+
name: raw_info['name'],
|
29
|
+
department: raw_info['department'],
|
30
|
+
gender: raw_info['gender'],
|
31
|
+
weixinid: raw_info['weixinid'],
|
32
|
+
avatar: raw_info['avatar'],
|
33
|
+
status: raw_info['status'],
|
34
|
+
extattr: raw_info['extattr']
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
extra do
|
39
|
+
{ raw_info: raw_info }
|
40
|
+
end
|
41
|
+
|
42
|
+
def request_phase
|
43
|
+
params = client.auth_code.authorize_params.merge(redirect_uri: callback_url).merge(authorize_params)
|
44
|
+
params["appid"] = params.delete("client_id")
|
45
|
+
redirect client.authorize_url(params)
|
46
|
+
end
|
47
|
+
|
48
|
+
def raw_info
|
49
|
+
# step 2: get userid via code and access_token
|
50
|
+
@code ||= access_token[:code]
|
51
|
+
|
52
|
+
# step 3: get user info via userid
|
53
|
+
@uid ||= begin
|
54
|
+
access_token.options[:mode] = :query
|
55
|
+
response = access_token.get('/cgi-bin/user/getuserinfo', :params => {'code' => @code}, parse: :json)
|
56
|
+
response.parsed['UserId']
|
57
|
+
end
|
58
|
+
|
59
|
+
@raw_info ||= begin
|
60
|
+
access_token.options[:mode] = :query
|
61
|
+
response = access_token.get("/cgi-bin/user/get", :params => {"userid" => @uid}, parse: :json)
|
62
|
+
response.parsed
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
def build_access_token
|
68
|
+
# step 0: wechat respond code
|
69
|
+
code = request.params['code']
|
70
|
+
|
71
|
+
# step 1: get access token
|
72
|
+
params = {
|
73
|
+
'corpid' => client.id,
|
74
|
+
'corpsecret' => client.secret,
|
75
|
+
}.merge(token_params.to_hash(symbolize_keys: true))
|
76
|
+
client.get_token(params, deep_symbolize(options.auth_token_params.merge({code: code})))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-wechat-oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Skinnyworm
|
8
|
+
- Never Min
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2019-03-15 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: omniauth
|
@@ -16,28 +17,28 @@ dependencies:
|
|
16
17
|
requirements:
|
17
18
|
- - ~>
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
+
version: 1.3.2
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - ~>
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
+
version: 1.3.2
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: omniauth-oauth2
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
32
|
- - ~>
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
+
version: 1.1.1
|
34
35
|
type: :runtime
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
39
|
- - ~>
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
+
version: 1.1.1
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: rspec
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,7 +55,9 @@ dependencies:
|
|
54
55
|
version: '2.7'
|
55
56
|
description: Using OAuth2 to authenticate wechat user when web resources being viewed
|
56
57
|
within wechat(weixin) client.
|
57
|
-
email:
|
58
|
+
email:
|
59
|
+
- askinnyworm@gmail.com
|
60
|
+
- Never.Min@gmail.com
|
58
61
|
executables: []
|
59
62
|
extensions: []
|
60
63
|
extra_rdoc_files: []
|
@@ -62,8 +65,10 @@ files:
|
|
62
65
|
- README.md
|
63
66
|
- lib/omniauth-wechat-oauth2.rb
|
64
67
|
- lib/omniauth/strategies/wechat.rb
|
65
|
-
|
66
|
-
|
68
|
+
- lib/omniauth/strategies/wechat_qiye.rb
|
69
|
+
homepage: https://github.com/nevermin/omniauth-wechat-oauth2
|
70
|
+
licenses:
|
71
|
+
- MIT
|
67
72
|
metadata: {}
|
68
73
|
post_install_message:
|
69
74
|
rdoc_options: []
|
@@ -73,16 +78,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
78
|
requirements:
|
74
79
|
- - '>='
|
75
80
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
81
|
+
version: 2.0.0
|
77
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
83
|
requirements:
|
79
84
|
- - '>='
|
80
85
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
86
|
+
version: '0'
|
82
87
|
requirements:
|
83
88
|
- none
|
84
89
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.7.9
|
86
91
|
signing_key:
|
87
92
|
specification_version: 4
|
88
93
|
summary: Omniauth strategy for wechat(weixin)
|