diff --git a/README.md b/README.md index 23b555d..8cb4ea8 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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, diff --git a/lib/omniauth/strategies/wechat.rb b/lib/omniauth/strategies/wechat.rb index 2302d24..bc7334b 100644 --- a/lib/omniauth/strategies/wechat.rb +++ b/lib/omniauth/strategies/wechat.rb @@ -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 } diff --git a/spec/omniauth/strategies/wechat_spec.rb b/spec/omniauth/strategies/wechat_spec.rb index 7f5d3fa..96b97b1 100644 --- a/spec/omniauth/strategies/wechat_spec.rb +++ b/spec/omniauth/strategies/wechat_spec.rb @@ -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 @@ -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" })} @@ -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" })} @@ -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( {