omniauth-wechat 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mzk4NzUxYTdmZDc1NGI1N2Y0MTRhM2ExNzFjZjYxZGM1MjNmYWE2NA==
4
+ Njc1ZDViNzVlNDRmMDcxNjEyMTVmMWNhOTZlMWVlNzExZmUwYWFiZA==
5
5
  data.tar.gz: !binary |-
6
- MTUwMDUwYThmYzcwMGYxYmY4NDA5ZDE3YTdjNjU0N2YyZjRhZmVhNw==
6
+ MjljNDhlMTQzNjYwNTBiODZlNmU4MmJhYmZhMGZkN2U0NWU2NmVkMw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OWFmYzljNTU5ODhmNzFjZTA5ZjEyYWM3NTRiNWE2ZjUzYzVjNDFjZWRmNTU3
10
- MThiMzBjNWVhNjY3MTVkOWY2Y2YzNGZmZGEwNGFlNzZjY2Y2ODUwYjhhY2M4
11
- N2U0ZGQzOWQzOTAzN2ExNWM2ZDAwZDk1ZDc3MTFmNGU2YWFmODQ=
9
+ ZTMwZTA5YTdiOGM3Y2Q3Yzk5YmFlMGQyNTU1OTFmZThjYzFmMGRmMjk1ZGU1
10
+ ZjMzNzgzYzEzNjJlZjc2ZGVmNDkyZGUwYTExMTQ0YmE2OTJmNTVjMmQ4MzYw
11
+ NzQ1ODQ3OWEwMDc0NzM3MjI0N2M5NWQ4M2MwYWZiZjM1N2Y0NTA=
12
12
  data.tar.gz: !binary |-
13
- NGVjMGRkMTgyZTg3MGRjZThlMjc3NDZiY2M1YWE3NjMzYmFjNGYyZTA4ZTZi
14
- NDYyZjAyYTAzY2JkMGZiYzNmNWU4ZWFjZWI4NzY1ZTA2YTZjYTE0Yjg4ZGRi
15
- ZmZiOWYzMzQ1MjhjMWM3MTAwODk1NmVmY2ZiYTI4Nzc0Y2IyYzI=
13
+ NmI1M2U1OTBjMDkyM2Y0NTZhZjAxNGJmNGRiMmZkYzQwNzg5NDUwZTk0NDZh
14
+ NDg0OGJlYjRjZTBjNmYwMTkzNDFkZTQyMzRiZmQ1ZTQxZWRlZjIzMDdkMWMz
15
+ OWNjNzRkN2JiY2VkY2NjYmE0ODY1MWRjMjNjMDBkY2VkN2FhZGI=
@@ -9,16 +9,19 @@ module OmniAuth
9
9
  :authorize_url => 'https://open.weixin.qq.com/connect/oauth2/authorize',
10
10
  :token_url => "https://api.weixin.qq.com/sns/oauth2/access_token"
11
11
  }
12
- option :scope ,'snsapi_base'
13
12
 
14
13
  def request_phase
15
- redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))+'#wechat_redirect'
14
+ redirect client.auth_code.authorize_url(authorize_params)+'#wechat_redirect'
16
15
  end
17
16
  def authorize_params
18
17
  params = super
19
18
  params[:state]=request.params['state']
20
19
  session['omniauth.state'] = params[:state]
21
- params.merge({:appid=>options.client_id})
20
+ {:appid=>options.client_id,
21
+ :redirect_uri => callback_url,
22
+ :response_type => 'code',
23
+ :status => params[:state]
24
+ }
22
25
  end
23
26
 
24
27
  def token_params
@@ -26,6 +29,14 @@ module OmniAuth
26
29
  params.merge({:appid=>options.client_id,:secret=>options.client_secret})
27
30
  end
28
31
 
32
+ def build_access_token
33
+ client.auth_code.get_token(
34
+ request.params['code'],
35
+ {:redirect_uri => callback_url, :parse => :json}.merge(token_params.to_hash(:symbolize_keys => true)),
36
+ {:mode => :query, :param_name => 'access_token'}
37
+ )
38
+ end
39
+
29
40
  uid do
30
41
  @uid ||= begin
31
42
  access_token[:openid]
@@ -34,9 +45,9 @@ module OmniAuth
34
45
 
35
46
  info do
36
47
  {
37
- :nickname => access_token[:openid],
38
- :name => access_token[:openid],
39
- :image => '',
48
+ :nickname => raw_info[:nickname],
49
+ :name => raw_info[:nickname],
50
+ :image => raw_info[:headimgurl],
40
51
  }
41
52
  end
42
53
 
@@ -48,13 +59,12 @@ module OmniAuth
48
59
 
49
60
  def raw_info
50
61
  @raw_info ||= begin
51
- client.request(:get, "https://api.weixin.qq.com/sns/userinfo", :params => {
52
- :format => :json,
53
- :openid => uid,
54
- :oauth_consumer_key => options[:client_id],
55
- :access_token => access_token.token,
56
- :lang =>'zh-CN'
57
- }, :parse => :json).parsed
62
+ response = access_token.get(
63
+ '/sns/userinfo',
64
+ {:params => {:openid => uid,
65
+ :lang =>'zh-CN'},
66
+ :parse => :json}
67
+ ).parsed
58
68
  end
59
69
  end
60
70
  end
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Wechat
3
- VERSION = "0.0.9"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-wechat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - victor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-10 00:00:00.000000000 Z
11
+ date: 2014-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth