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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f9f385bb13c3fd98b29292dacd34ab1b5fb45dcf
4
+ data.tar.gz: 7a370bf8584653df6b542e033465e85e515c6847
5
+ SHA512:
6
+ metadata.gz: b71d6fd49cfd9006c8b9b6dd36f0a4ec540ddfcb438d489f38b71ac5844ee3c4c0e5bbb69cc516a7fcf767757d37f773547720a74597360b40477b2076463c63
7
+ data.tar.gz: ec84e62b73d417863c4bf5fd8f87d1df403fcaf918ac20b9117472639376daab4b44dc48c4e5d5c29594f2c469bcce154785d0e9982b2aa4c1f432fb199abe1d
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ /pkg
13
+ rdoc
14
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-open_wechat.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # OmniAuth OpenWechat OAuth2
2
+
3
+ Read Weibo 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
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/[my-github-username]/omniauth-open_wechat/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -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['openid']
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 ||= 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,5 @@
1
+ module OmniAuth
2
+ module OpenWechat
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ # require "omniauth-open_wechat/version"
2
+ require 'omniauth/strategies/open_wechat'
@@ -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 = ["free1"]
6
+ gem.email = ["747549945@qq.com"]
7
+ gem.description = %q{OmniAuth strategy for OpenWechat.}
8
+ gem.summary = %q{OmniAuth strategy for OpenWechat.}
9
+ gem.homepage = "https://github.com/free1/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 = "omniauth-open_wechat"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniAuth::OpenWechat::VERSION
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,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-open_wechat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - free1
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-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
+ - 747549945@qq.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/free1/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
+ rubyforge_project:
82
+ rubygems_version: 2.4.6
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: OmniAuth strategy for OpenWechat.
86
+ test_files: []