diff --git a/README.md b/README.md index b2878f3..e558c79 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,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 ``` @@ -76,7 +76,8 @@ Here's an example of an authentication hash available in the callback by accessi }, :extra => { :raw_info => { - openid: "openid" + unionid: "unionid", #if exist + openid: "openid", nickname: "Nickname", sex: 1, province: "Changning", @@ -87,7 +88,3 @@ Here's an example of an authentication hash available in the callback by accessi } } ``` - - - - diff --git a/lib/omniauth/strategies/wechat.rb b/lib/omniauth/strategies/wechat.rb index 6f166e5..bb9af1f 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 7418d3e..62b49a2 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_userinfo" do let(:access_token) { OAuth2::AccessToken.from_hash(client, { - "openid"=>"openid", - "scope"=>"snsapi_userinfo", + "openid"=>"openid", + "scope"=>"snsapi_userinfo", "access_token"=>"access_token" })} @@ -147,4 +147,4 @@ -end \ No newline at end of file +end