Skip to content

Commit 51d8905

Browse files
committed
feature - Switch to support snsapi_userinfo scope NeverMin#26
1 parent 293e0f8 commit 51d8905

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Here's an example for adding the middleware to a Rails app in `config/initialize
3434

3535
```ruby
3636
Rails.application.config.middleware.use OmniAuth::Builder do
37-
provider :wechat, ENV["WECHAT_APP_ID"], ENV["WECHAT_APP_SECRET"]
37+
provider :wechat, ENV["WECHAT_APP_ID"], ENV["WECHAT_APP_SECRET"], scope: 'snsapi_userinfo'
3838
end
3939
```
4040

@@ -78,6 +78,7 @@ Here's an example of an authentication hash available in the callback by accessi
7878
},
7979
:extra => {
8080
:raw_info => {
81+
unionid: "unionid", #if exist
8182
openid: "openid"
8283
nickname: "Nickname",
8384
sex: 1,

lib/omniauth/strategies/wechat.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Wechat < OmniAuth::Strategies::OAuth2
77

88
option :client_options, {
99
site: "https://api.weixin.qq.com",
10-
authorize_url: "https://open.weixin.qq.com/connect/qrconnect?#wechat_redirect",
10+
authorize_url: "https://open.weixin.qq.com/connect/oauth2/authorize?#wechat_redirect"
1111
token_url: "/sns/oauth2/access_token",
1212
token_method: :get
1313
}

spec/omniauth/strategies/wechat_spec.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
end
2828

2929
specify 'has authorize_url' do
30-
expect(subject.client.options[:authorize_url]).to eq('https://open.weixin.qq.com/connect/qrconnect?#wechat_redirect')
30+
expect(subject.client.options[:authorize_url]).to eq('https://open.weixin.qq.com/connect/oauth2/authorize?#wechat_redirect')
3131
end
3232

3333
specify 'has token_url' do
@@ -99,8 +99,8 @@
9999

100100
context "when scope is snsapi_base" do
101101
let(:access_token) { OAuth2::AccessToken.from_hash(client, {
102-
"openid"=>"openid",
103-
"scope"=>"snsapi_base",
102+
"openid"=>"openid",
103+
"scope"=>"snsapi_base",
104104
"access_token"=>"access_token"
105105
})}
106106

@@ -112,8 +112,8 @@
112112

113113
context "when scope is snsapi_login" do
114114
let(:access_token) { OAuth2::AccessToken.from_hash(client, {
115-
"openid"=>"openid",
116-
"scope"=>"snsapi_login",
115+
"openid"=>"openid",
116+
"scope"=>"snsapi_login",
117117
"access_token"=>"access_token"
118118
})}
119119

@@ -124,18 +124,18 @@
124124
expect(opts[:params]).to eq("openid"=> "openid", "lang"=>"zh_CN", "access_token"=> "access_token")
125125
expect(opts[:parse]).to eq(:json)
126126
end.and_return(double("response", parsed:
127-
{
128-
"openid" => "OPENID",
129-
"nickname" => "NICKNAME",
130-
"sex" => "1",
131-
"province" => "PROVINCE",
132-
"city" => "CITY",
133-
"country" => "COUNTRY",
134-
"headimgurl" => "header_image_url",
135-
"privilege" => ["PRIVILEGE1", "PRIVILEGE2"],
136-
"unionid" => "UNIONID"
137-
}
138-
))
127+
{
128+
"openid" => "OPENID",
129+
"nickname" => "NICKNAME",
130+
"sex" => "1",
131+
"province" => "PROVINCE",
132+
"city" => "CITY",
133+
"country" => "COUNTRY",
134+
"headimgurl" => "header_image_url",
135+
"privilege" => ["PRIVILEGE1", "PRIVILEGE2"],
136+
"unionid" => "UNIONID"
137+
}
138+
))
139139

140140
expect(subject.raw_info).to eq(
141141
{

0 commit comments

Comments
 (0)