oauth2_dingtalk 0.1.1 → 0.2.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 +4 -4
- data/.rspec +1 -1
- data/README.md +38 -22
- data/lib/oauth2_dingtalk/version.rb +1 -1
- data/lib/omniauth/strategies/dingding.rb +30 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f094f2ae0851b8d3ef012277cd7b19604caa24f5
|
4
|
+
data.tar.gz: 554102e2502536878ac3bbecd23ff668f5a41776
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0df169d104797d520f06e6174a2fe58545c5564daa02805c1564e77672e94868ab85eba446954707c0f339fe2554dc41bb47e204541dd6b5e68d276c792ee441
|
7
|
+
data.tar.gz: a5dee3785d82e17a08228f202f53f28c7dc9382bbd1a1809e2a5f263e8b207c51a2719e0d6ff2a32813c276496c5d966d511541bc6a4e19e1ff67fd4af3c36fe
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--format
|
1
|
+
--format progress
|
2
2
|
--color
|
data/README.md
CHANGED
@@ -1,36 +1,52 @@
|
|
1
|
-
|
1
|
+
[](https://badge.fury.io/rb/oauth2_dingtalk)
|
2
2
|
|
3
|
-
|
3
|
+
# Omniauth DingTalk Strategies
|
4
4
|
|
5
|
-
|
5
|
+
Strategy to authenticate with DingTalk via OAuth2 in OmniAuth.
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
```
|
7
|
+
Get your API key at: http://open-dev.dingtalk.com/ Note the appId and the appSecret.
|
8
|
+
|
9
|
+
For more details, read the DingTalk docs: https://open-doc.dingtalk.com/docs/doc.htm?spm=0.0.0.0.oVQWJc&treeId=168&articleId=104878&docType=1
|
11
10
|
|
12
|
-
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add to your `Gemfile`:
|
13
14
|
|
14
15
|
```ruby
|
15
|
-
|
16
|
-
Rails.application.config.middleware.use OmniAuth::Builder do
|
17
|
-
provider :dingding, "Your_OAuth_App_ID", "Your_OAuth_App_Secret"
|
18
|
-
end
|
16
|
+
gem 'oauth2_dingtalk'
|
19
17
|
```
|
20
18
|
|
21
|
-
|
19
|
+
Then `bundle install`.
|
20
|
+
|
21
|
+
## appId & appSecret
|
22
|
+
|
23
|
+
Go to: https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.o96KrM&treeId=168&articleId=104882&docType=1
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Here's an example for adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
22
28
|
|
23
29
|
```ruby
|
24
|
-
|
30
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
31
|
+
provider :dingding, "Your_OAuth_App_ID", "Your_OAuth_App_Secret"
|
32
|
+
end
|
25
33
|
```
|
26
34
|
|
27
|
-
|
35
|
+
You can now access the OmniAuth DingTalk OAuth2 URL: /auth/dingding
|
28
36
|
|
29
|
-
|
30
|
-
```
|
31
|
-
auth = request.env["omniauth.auth"]
|
32
|
-
auth["provider"] # dingding
|
33
|
-
auth["uid"] # 用户在当前开放应用内的唯一标识
|
34
|
-
```
|
37
|
+
For more examples please check out example/config.ru
|
35
38
|
|
36
|
-
|
39
|
+
## Auth Hash
|
40
|
+
|
41
|
+
Here's an example of an authentication hash available in the callback by accessing `request.env['omniauth.auth']`:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
{
|
45
|
+
"provider": "dingding",
|
46
|
+
"uid": "uid",
|
47
|
+
"info": {
|
48
|
+
"name": "liukun",
|
49
|
+
"ding_id": "ding_id"
|
50
|
+
}
|
51
|
+
}
|
52
|
+
```
|
@@ -10,17 +10,20 @@ module OmniAuth
|
|
10
10
|
authorize_url: '/connect/qrconnect',
|
11
11
|
token_url: '/sns/gettoken',
|
12
12
|
persistent_url: '/sns/get_persistent_code',
|
13
|
+
sns_token: '/sns/get_sns_token',
|
14
|
+
user_info: '/sns/getuserinfo',
|
13
15
|
token_method: :get
|
14
16
|
|
15
17
|
option :authorize_params, scope: 'snsapi_login'
|
16
18
|
|
17
19
|
uid do
|
18
|
-
raw_info['
|
20
|
+
raw_info['user_info']['unionid']
|
19
21
|
end
|
20
22
|
|
21
23
|
info do
|
22
24
|
{
|
23
|
-
|
25
|
+
name: raw_info['user_info']['nick'],
|
26
|
+
ding_id: raw_info['user_info']['dingId']
|
24
27
|
}
|
25
28
|
end
|
26
29
|
|
@@ -35,11 +38,9 @@ module OmniAuth
|
|
35
38
|
end
|
36
39
|
|
37
40
|
def raw_info
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
req.body = "{\"tmp_auth_code\":\"#{request.params['code']}\"}"
|
42
|
-
end.parsed
|
41
|
+
return persistent_code if persistent_code['errcode'] != 0
|
42
|
+
return sns_token if sns_token['errcode'] != 0
|
43
|
+
user_info
|
43
44
|
end
|
44
45
|
|
45
46
|
protected
|
@@ -51,6 +52,28 @@ module OmniAuth
|
|
51
52
|
}
|
52
53
|
client.get_token(params)
|
53
54
|
end
|
55
|
+
|
56
|
+
def persistent_code
|
57
|
+
@persistent_code ||=
|
58
|
+
access_token.post(options.client_options.persistent_url + "?access_token=#{access_token.token}") do |req|
|
59
|
+
req.headers['Content-Type'] = 'application/json'
|
60
|
+
req.body = "{\"tmp_auth_code\":\"#{request.params['code']}\"}"
|
61
|
+
end.parsed
|
62
|
+
end
|
63
|
+
|
64
|
+
def sns_token
|
65
|
+
@sns_token ||=
|
66
|
+
access_token.post(options.client_options.sns_token + "?access_token=#{access_token.token}") do |req|
|
67
|
+
req.headers['Content-Type'] = 'application/json'
|
68
|
+
req.body = "{\"openid\":\"#{@persistent_code['openid']}\",
|
69
|
+
\"persistent_code\":\"#{@persistent_code['persistent_code']}\"}"
|
70
|
+
end.parsed
|
71
|
+
end
|
72
|
+
|
73
|
+
def user_info
|
74
|
+
@user_info ||=
|
75
|
+
access_token.get(options.client_options.user_info + "?sns_token=#{@sns_token['sns_token']}").parsed
|
76
|
+
end
|
54
77
|
end
|
55
78
|
end
|
56
79
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth2_dingtalk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- liukun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|