omniauth-wework-oauth2 1.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/README.md +21 -0
- data/lib/omniauth/strategies/wework.rb +72 -0
- data/lib/omniauth-wechat-oauth2.rb +1 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 902acad19e77bb6bbdffdc27ad73d0c754c58cc6
|
4
|
+
data.tar.gz: e105b7b83047492449df882d731f47f224536bed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 890c7bed5ec262b493739cc7d8b1ebf2c6b16b8efd677eec1ee5c1eef2a1e6e172bc4ab984300980b6537eedb63612658e756d36561dc391bf6c213885900306
|
7
|
+
data.tar.gz: 52a6befe99e6ae8eddff46792a2dc7a7903053089d5b40338925d747998b99dce45742eac6122ec5a48d835bb052f867e415aa983c30f685f3342a1de4b90cd7
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Omniauth::Wework::Oauth2
|
2
|
+
|
3
|
+
Omniauth Strategy for https://work.weixin.qq.com
|
4
|
+
企业微信的Omniauth Strategy
|
5
|
+
|
6
|
+
## 安装
|
7
|
+
```ruby
|
8
|
+
gem "omniauth-wework-oauth2", git: 'git@luckyzune.com:gitlabhq/omniauth-wework-oauth2.git'
|
9
|
+
```
|
10
|
+
|
11
|
+
## 使用
|
12
|
+
|
13
|
+
在Rail app中添加中间件的例子 `config/initializers/omniauth.rb`:
|
14
|
+
```ruby
|
15
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
16
|
+
provider :wework, ENV["WEWORK_APP_ID"], ENV["WEWORK_APP_SECRET"]
|
17
|
+
:authorize_params => {:agentid => ENV["WEWORK_AGENT_ID"]}
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
现在可以访问OmniAuth Wework OAuth2 URL: `/auth/wework`
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "omniauth-oauth2"
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Wework < OmniAuth::Strategies::OAuth2
|
6
|
+
# Give your strategy a name.
|
7
|
+
option :name, "wework"
|
8
|
+
|
9
|
+
# This is where you pass the options you would pass when
|
10
|
+
# initializing your consumer from the OAuth gem.
|
11
|
+
option :client_options, {
|
12
|
+
site: "https://api.weixin.qq.com",
|
13
|
+
authorize_url: "https://open.work.weixin.qq.com/wwopen/sso/qrconnect",
|
14
|
+
token_url: "/sns/oauth2/access_token",
|
15
|
+
token_method: :get
|
16
|
+
}
|
17
|
+
|
18
|
+
option :authorize_params, {scope: "snsapi_login"}
|
19
|
+
|
20
|
+
option :token_params, {parse: :json}
|
21
|
+
|
22
|
+
# These are called after authentication has succeeded. If
|
23
|
+
# possible, you should try to set the UID without making
|
24
|
+
# additional calls (if the user id is returned with the token
|
25
|
+
# or as a URI parameter). This may not be possible with all
|
26
|
+
# providers.
|
27
|
+
uid { raw_info['openid'] }
|
28
|
+
|
29
|
+
info do
|
30
|
+
{
|
31
|
+
nickname: raw_info['nickname'],
|
32
|
+
sex: raw_info['sex'],
|
33
|
+
province: raw_info['province'],
|
34
|
+
city: raw_info['city'],
|
35
|
+
country: raw_info['country'],
|
36
|
+
headimgurl: raw_info['headimgurl'],
|
37
|
+
unionid: raw_info['unionid'],
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
extra do
|
42
|
+
{raw_info: raw_info}
|
43
|
+
end
|
44
|
+
|
45
|
+
def request_phase
|
46
|
+
params = client.auth_code.authorize_params.merge(redirect_uri: callback_url).merge(authorize_params)
|
47
|
+
params["appid"] = params.delete("client_id")
|
48
|
+
redirect client.authorize_url(params)
|
49
|
+
end
|
50
|
+
|
51
|
+
def raw_info
|
52
|
+
@uid ||= access_token["openid"]
|
53
|
+
@raw_info ||= begin
|
54
|
+
access_token.options[:mode] = :query
|
55
|
+
response = access_token.get("/sns/userinfo", :params => {"openid" => @uid}, parse: :text)
|
56
|
+
@raw_info = JSON.parse(response.body.gsub(/[\u0000-\u001f]+/, ''))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
def build_access_token
|
62
|
+
params = {
|
63
|
+
'appid' => client.id,
|
64
|
+
'secret' => client.secret,
|
65
|
+
'code' => request.params['code'],
|
66
|
+
'grant_type' => 'authorization_code'
|
67
|
+
}.merge(token_params.to_hash(symbolize_keys: true))
|
68
|
+
client.get_token(params, deep_symbolize(options.auth_token_params))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "omniauth/strategies/wework"
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-wework-oauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luckyzune Inc., luckyqm
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-06 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.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.7'
|
55
|
+
description: 使用OAuth2认证微信企业用户
|
56
|
+
email: mq@luckyzune.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- README.md
|
62
|
+
- lib/omniauth/strategies/wework.rb
|
63
|
+
- lib/omniauth-wechat-oauth2.rb
|
64
|
+
homepage: https://luckyzune.com/gitlabhq/omniauth-wework-oauth2
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.9.3
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.8.23
|
82
|
+
requirements:
|
83
|
+
- none
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.0.14.1
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Omniauth strategy for open.work.weixin.qq.com
|
89
|
+
test_files: []
|