shixian-omniauth-open_wechat 0.0.1
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/README.md +83 -0
- data/Rakefile +2 -0
- data/lib/omniauth/strategies/open_wechat.rb +67 -0
- data/lib/omniauth-open_wechat/version.rb +5 -0
- data/lib/omniauth-open_wechat.rb +2 -0
- data/omniauth-open_wechat.gemspec +24 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ae77aeac9d84d0914d70707b1062a7aaedd2c94a4a0ba8f8f280e37f1fc1a390
|
4
|
+
data.tar.gz: 3af9f521d655df2e2257a4100a0316766e45cc6fd35a6dbdcc4517615e275959
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 393f6e17781979882dbeea1ad840e439948d0f04380a569ab1efe9dc36649f1f9845b7da4d49083e8a561aa1065d2aca017aa9d32f9ee23d1b94798ca08ed6e6
|
7
|
+
data.tar.gz: d15554883d73d4d0ceed6bbd98555e893c6c2d583114e39fd84573be210d84495973044b11118609a8fe359e931a7cbfe33acc0629c195a92f02796e84fdb33a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# OmniAuth OpenWechat OAuth2
|
2
|
+
|
3
|
+
Read Wechat OAuth2 docs for more details: [微信开放平台开发指南](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&lang=zh_CN)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'omniauth-open_wechat'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install omniauth-open_wechat
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Here's a quick example, adding the middleware to a Rails app in
|
24
|
+
`config/initializers/omniauth.rb:`
|
25
|
+
|
26
|
+
```
|
27
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
28
|
+
provider :open_wechat, ENV['OPEN_WECHAT_KEY'], ENV['OPEN_WECHAT_SECRET'], :scope => 'snsapi_login'
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
## Current Version
|
33
|
+
|
34
|
+
`0.0.2`
|
35
|
+
|
36
|
+
## Authentication Hash
|
37
|
+
|
38
|
+
Here's an example Authentication Hash available in `request.env['omniauth.auth']` :
|
39
|
+
|
40
|
+
```
|
41
|
+
{
|
42
|
+
"provider"=>"open_wechat",
|
43
|
+
"uid"=>"xxx...",
|
44
|
+
"unionid"=>"xxx...",
|
45
|
+
"info"=>{
|
46
|
+
"nickname"=>"free",
|
47
|
+
"sex"=>1,
|
48
|
+
"province"=>"",
|
49
|
+
"city"=>"",
|
50
|
+
"country"=>"CN",
|
51
|
+
"headimgurl"=>"http://wx.qlogo.cn/mmopen/574VdhMFwaGdhhGuGWZicMYibnBSnzYSU8S6c3mJrqneYpm1YmGkBjHX5T9xj4TdeRWfHPmXORTqIt7F0G2y4TJA/0",
|
52
|
+
"name"=>"free"
|
53
|
+
},
|
54
|
+
"credentials"=>{
|
55
|
+
"token"=>"xxx...",
|
56
|
+
"refresh_token"=>"xxx...",
|
57
|
+
"expires_at"=>2015-06-04 16:17:26 +0800,
|
58
|
+
"expires"=>true
|
59
|
+
},
|
60
|
+
"extra"=>{
|
61
|
+
"raw_info"=>{
|
62
|
+
"openid"=>"xxx...",
|
63
|
+
"nickname"=>"free",
|
64
|
+
"sex"=>1,
|
65
|
+
"language"=>"zh_CN",
|
66
|
+
"city"=>"",
|
67
|
+
"province"=>"",
|
68
|
+
"country"=>"CN",
|
69
|
+
"headimgurl"=>"http://wx.qlogo.cn/mmopen/574VdhMFwaGdhhGuGWZicMYibnBSnzYSU8S6c3mJrqneYpm1YmGkBjHX5T9xj4TdeRWfHPmXORTqIt7F0G2y4TJA/0",
|
70
|
+
"privilege"=>[],
|
71
|
+
"unionid"=>"xxx..."
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
```
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
1. Fork it ( https://github.com/[my-github-username]/omniauth-open_wechat/fork )
|
80
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
81
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
82
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
83
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class OpenWechat < OmniAuth::Strategies::OAuth2
|
6
|
+
|
7
|
+
option :name, "open_wechat"
|
8
|
+
|
9
|
+
option :client_options, {
|
10
|
+
site: "https://api.weixin.qq.com",
|
11
|
+
authorize_url: "https://open.weixin.qq.com/connect/qrconnect#wechat_redirect",
|
12
|
+
token_url: "/sns/oauth2/access_token",
|
13
|
+
token_method: :get
|
14
|
+
}
|
15
|
+
|
16
|
+
option :token_params, {
|
17
|
+
:parse => :json
|
18
|
+
}
|
19
|
+
|
20
|
+
uid do
|
21
|
+
raw_info['unionid']
|
22
|
+
end
|
23
|
+
|
24
|
+
info do
|
25
|
+
{
|
26
|
+
nickname: raw_info['nickname'],
|
27
|
+
sex: raw_info['sex'],
|
28
|
+
province: raw_info['province'],
|
29
|
+
city: raw_info['city'],
|
30
|
+
country: raw_info['country'],
|
31
|
+
headimgurl: raw_info['headimgurl']
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
extra do
|
36
|
+
{raw_info: raw_info}
|
37
|
+
end
|
38
|
+
|
39
|
+
def request_phase
|
40
|
+
params = client.auth_code.authorize_params.merge(redirect_uri: callback_url).merge(authorize_params)
|
41
|
+
params["appid"] = params.delete("client_id")
|
42
|
+
redirect client.authorize_url(params)
|
43
|
+
end
|
44
|
+
|
45
|
+
def raw_info
|
46
|
+
@uid ||= access_token["openid"]
|
47
|
+
access_token.options[:mode] = :query
|
48
|
+
access_token.options[:param_name] = 'access_token'
|
49
|
+
@raw_info ||= JSON access_token.get("/sns/userinfo", :params => {"openid" => @uid}).parsed
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def build_access_token
|
55
|
+
params = {
|
56
|
+
'appid' => client.id,
|
57
|
+
'secret' => client.secret,
|
58
|
+
'code' => request.params['code'],
|
59
|
+
'grant_type' => 'authorization_code',
|
60
|
+
:parse => :json
|
61
|
+
}
|
62
|
+
client.get_token(params)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/omniauth-open_wechat/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["kelby"]
|
6
|
+
gem.email = ["leekelby@gmail.com"]
|
7
|
+
gem.description = %q{OmniAuth strategy for OpenWechat.}
|
8
|
+
gem.summary = %q{OmniAuth strategy for OpenWechat.}
|
9
|
+
gem.homepage = "https://github.com/shixiancom/omniauth-open_wechat"
|
10
|
+
gem.license = "MIT"
|
11
|
+
|
12
|
+
# gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
13
|
+
gem.files = `git ls-files`.split("\n")
|
14
|
+
gem.name = "shixian-omniauth-open_wechat"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = "0.0.1"
|
17
|
+
|
18
|
+
gem.add_dependency 'omniauth', '~> 1.0'
|
19
|
+
gem.add_dependency 'omniauth-oauth2', '>= 1.1.1', '< 2.0'
|
20
|
+
# gem.add_development_dependency 'rspec', '~> 2.7'
|
21
|
+
# gem.add_development_dependency 'rack-test'
|
22
|
+
# gem.add_development_dependency 'simplecov'
|
23
|
+
# gem.add_development_dependency 'webmock'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shixian-omniauth-open_wechat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kelby
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: omniauth-oauth2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.1
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '2.0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.1.1
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.0'
|
47
|
+
description: OmniAuth strategy for OpenWechat.
|
48
|
+
email:
|
49
|
+
- leekelby@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- ".gitignore"
|
55
|
+
- Gemfile
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/omniauth-open_wechat.rb
|
59
|
+
- lib/omniauth-open_wechat/version.rb
|
60
|
+
- lib/omniauth/strategies/open_wechat.rb
|
61
|
+
- omniauth-open_wechat.gemspec
|
62
|
+
homepage: https://github.com/shixiancom/omniauth-open_wechat
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubygems_version: 3.5.18
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: OmniAuth strategy for OpenWechat.
|
85
|
+
test_files: []
|