Skip to content

Commit

Permalink
feature - Switch to support snsapi_userinfo scope NeverMin#26
Browse files Browse the repository at this point in the history
  • Loading branch information
NaiveCAI committed Feb 10, 2021
1 parent 293e0f8 commit 104ddd0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Here's an example for adding the middleware to a Rails app in `config/initialize

```ruby
Rails.application.config.middleware.use OmniAuth::Builder do
provider :wechat, ENV["WECHAT_APP_ID"], ENV["WECHAT_APP_SECRET"]
provider :wechat, ENV["WECHAT_APP_ID"], ENV["WECHAT_APP_SECRET"], scope: 'snsapi_userinfo'
end
```

Expand Down Expand Up @@ -78,6 +78,7 @@ Here's an example of an authentication hash available in the callback by accessi
},
:extra => {
:raw_info => {
unionid: "unionid", #if exist
openid: "openid"
nickname: "Nickname",
sex: 1,
Expand Down
2 changes: 1 addition & 1 deletion lib/omniauth/strategies/wechat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Wechat < OmniAuth::Strategies::OAuth2

option :client_options, {
site: "https://api.weixin.qq.com",
authorize_url: "https://open.weixin.qq.com/connect/qrconnect?#wechat_redirect",
authorize_url: "https://open.weixin.qq.com/connect/oauth2/authorize?#wechat_redirect",
token_url: "/sns/oauth2/access_token",
token_method: :get
}
Expand Down
34 changes: 17 additions & 17 deletions spec/omniauth/strategies/wechat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
end

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

specify 'has token_url' do
Expand Down Expand Up @@ -99,8 +99,8 @@

context "when scope is snsapi_base" do
let(:access_token) { OAuth2::AccessToken.from_hash(client, {
"openid"=>"openid",
"scope"=>"snsapi_base",
"openid"=>"openid",
"scope"=>"snsapi_base",
"access_token"=>"access_token"
})}

Expand All @@ -112,8 +112,8 @@

context "when scope is snsapi_login" do
let(:access_token) { OAuth2::AccessToken.from_hash(client, {
"openid"=>"openid",
"scope"=>"snsapi_login",
"openid"=>"openid",
"scope"=>"snsapi_login",
"access_token"=>"access_token"
})}

Expand All @@ -124,18 +124,18 @@
expect(opts[:params]).to eq("openid"=> "openid", "lang"=>"zh_CN", "access_token"=> "access_token")
expect(opts[:parse]).to eq(:json)
end.and_return(double("response", parsed:
{
"openid" => "OPENID",
"nickname" => "NICKNAME",
"sex" => "1",
"province" => "PROVINCE",
"city" => "CITY",
"country" => "COUNTRY",
"headimgurl" => "header_image_url",
"privilege" => ["PRIVILEGE1", "PRIVILEGE2"],
"unionid" => "UNIONID"
}
))
{
"openid" => "OPENID",
"nickname" => "NICKNAME",
"sex" => "1",
"province" => "PROVINCE",
"city" => "CITY",
"country" => "COUNTRY",
"headimgurl" => "header_image_url",
"privilege" => ["PRIVILEGE1", "PRIVILEGE2"],
"unionid" => "UNIONID"
}
))

expect(subject.raw_info).to eq(
{
Expand Down

0 comments on commit 104ddd0

Please sign in to comment.