omniauth-feishu 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/omniauth/feishu/version.rb +1 -1
- data/lib/omniauth/strategies/feishu.rb +49 -41
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac97f7c1d2639fdb1b2812ec5d6cb66cc636be214d17b69a89c00e32e3981551
|
4
|
+
data.tar.gz: 02ddf74e3a7255059390cc9dbf268572050f52ad00a9fc9ede60fdc1e60998ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa62ebaa035fa8c04b2e27ab8064340fb2d5209a20dfc85de806ddcf6413608a68e6378647c5ce92e090295392b9e6fb1783217cd247ffb0ae6f16136394db08
|
7
|
+
data.tar.gz: 1ba97b40558d0c54f4cba6bbfaa155082620a090dc6420f3dcc9103c2fd18b44c59956336a05526ea19f2ffdef6f5077ada17563a0232fe9efd491449e18c981
|
@@ -2,19 +2,22 @@ require 'omniauth-oauth2'
|
|
2
2
|
|
3
3
|
module OmniAuth
|
4
4
|
module Strategies
|
5
|
+
|
6
|
+
# 飞书登录
|
7
|
+
#
|
8
|
+
# 飞书要求请求采用 json 格式主体,很多都需要自定义
|
9
|
+
# 官方文档: https://open.feishu.cn/document/ukTMukTMukTM/uETOwYjLxkDM24SM5AjN
|
5
10
|
class Feishu < OmniAuth::Strategies::OAuth2
|
6
11
|
class NoAppAccessTokenError < StandardError; end
|
7
12
|
|
8
|
-
attr_reader :app_access_token
|
9
|
-
|
10
13
|
option :name, 'feishu'
|
11
14
|
|
12
15
|
option :client_options, {
|
13
|
-
site: 'https://open.feishu.cn',
|
14
|
-
authorize_url:
|
15
|
-
token_url:
|
16
|
-
app_access_token_url:
|
17
|
-
user_info_url:
|
16
|
+
site: 'https://open.feishu.cn/open-apis/authen/v1/',
|
17
|
+
authorize_url: 'user_auth_page_beta',
|
18
|
+
token_url: 'access_token',
|
19
|
+
app_access_token_url: 'https://open.feishu.cn/open-apis/auth/v3/app_access_token/internal',
|
20
|
+
user_info_url: 'user_info'
|
18
21
|
}
|
19
22
|
|
20
23
|
uid { raw_info['user_id'] }
|
@@ -31,21 +34,18 @@ module OmniAuth
|
|
31
34
|
user_id: raw_info['user_id'],
|
32
35
|
union_id: raw_info['union_id'],
|
33
36
|
open_id: raw_info['open_id'],
|
34
|
-
en_name: raw_info['en_name']
|
35
|
-
app_access_token: @app_access_token
|
37
|
+
en_name: raw_info['en_name']
|
36
38
|
}
|
37
39
|
end
|
38
40
|
|
39
41
|
def raw_info
|
40
|
-
@raw_info ||=
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
response_body['data']
|
48
|
-
end
|
42
|
+
@raw_info ||= client.request(:get, options.client_options.user_info_url,
|
43
|
+
{ headers: {
|
44
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
45
|
+
'Authorization' => "Bearer #{access_token.token}"
|
46
|
+
}
|
47
|
+
})
|
48
|
+
.parsed['data']
|
49
49
|
end
|
50
50
|
|
51
51
|
def authorize_params
|
@@ -54,35 +54,43 @@ module OmniAuth
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
# 飞书采用非标准 OAuth 2 请求体和返回结构体,需要自定义
|
57
58
|
def build_access_token
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
59
|
+
code = request.params['code']
|
60
|
+
data = client.request(:post, options.client_options.token_url,
|
61
|
+
{ body: {
|
62
|
+
code: code,
|
63
|
+
grant_type: 'authorization_code'
|
64
|
+
}.to_json,
|
65
|
+
headers: {
|
66
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
67
|
+
'Authorization' => "Bearer #{app_access_token}"
|
68
|
+
}
|
69
|
+
})
|
70
|
+
.parsed['data']
|
66
71
|
|
67
|
-
|
68
|
-
get_app_access_token
|
69
|
-
super
|
72
|
+
::OAuth2::AccessToken.from_hash(client, data)
|
70
73
|
end
|
71
74
|
|
72
75
|
private
|
73
76
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
77
|
+
def app_access_token
|
78
|
+
return @app_access_token if @app_access_token
|
79
|
+
|
80
|
+
@app_access_token ||= client.request(:post, options.client_options.app_access_token_url,
|
81
|
+
{ body: {
|
82
|
+
app_id: options.client_id,
|
83
|
+
app_secret: options.client_secret
|
84
|
+
}.to_json,
|
85
|
+
headers: {
|
86
|
+
'Content-Type' => 'application/json; charset=utf-8'
|
87
|
+
}
|
88
|
+
})
|
89
|
+
.parsed['app_access_token']
|
90
|
+
|
91
|
+
raise NoAppAccessTokenError, 'No app access token' unless @app_access_token
|
92
|
+
|
93
|
+
@app_access_token
|
86
94
|
end
|
87
95
|
end
|
88
96
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-feishu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-oauth2
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
|
-
rubygems_version: 3.
|
69
|
+
rubygems_version: 3.1.4
|
70
70
|
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: Lark(Feishu) OAuth2 Strategy for OmniAuth
|