omniauth-feishu 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14956948973a6a76e4d5e65847275084f79a170ab3abf565c8b5db3d61d69600
4
- data.tar.gz: 6fc074425ce4a29bd5bae486c31e75442bafc5e2de4bb8227e793f79614b82f1
3
+ metadata.gz: ac97f7c1d2639fdb1b2812ec5d6cb66cc636be214d17b69a89c00e32e3981551
4
+ data.tar.gz: 02ddf74e3a7255059390cc9dbf268572050f52ad00a9fc9ede60fdc1e60998ea
5
5
  SHA512:
6
- metadata.gz: 59b6d8c254c147f8adf4d10a629819b3dec8f3c823cd551df80fef54d4bd06faeea27c42b372b6fecbf293c2ca222e2c217d50e8ac15777a088450af16fc5ca6
7
- data.tar.gz: c899115bc722d550f36d772621789b1004c26ac50d2e6a2c3cd9e7dc6d7dcd425c1d6fe7884438acf0931d7449098553bd713f535d8528357b480d30dc8da08f
6
+ metadata.gz: fa62ebaa035fa8c04b2e27ab8064340fb2d5209a20dfc85de806ddcf6413608a68e6378647c5ce92e090295392b9e6fb1783217cd247ffb0ae6f16136394db08
7
+ data.tar.gz: 1ba97b40558d0c54f4cba6bbfaa155082620a090dc6420f3dcc9103c2fd18b44c59956336a05526ea19f2ffdef6f5077ada17563a0232fe9efd491449e18c981
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Feishu
3
- VERSION = "0.1.7"
3
+ VERSION = "0.1.8"
4
4
  end
5
5
  end
@@ -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: "/open-apis/authen/v1/user_auth_page_beta",
15
- token_url: "https://open.feishu.cn/open-apis/authen/v1/access_token",
16
- app_access_token_url: "https://open.feishu.cn/open-apis/auth/v3/app_access_token/internal",
17
- user_info_url: "https://open.feishu.cn/open-apis/authen/v1/user_info"
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 ||= begin
41
- response = Faraday.get(
42
- options.client_options.user_info_url,
43
- nil,
44
- content_type: 'application/json', authorization: "Bearer #{access_token.token}"
45
- )
46
- response_body = JSON.parse(response.body)
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
- resp = Faraday.post(
59
- options.client_options.token_url,
60
- { code: request.params["code"], app_access_token: app_access_token, grant_type: "authorization_code" }.to_json,
61
- content_type: "application/json"
62
- )
63
- data = JSON.parse(resp.body)['data']
64
- ::OAuth2::AccessToken.from_hash(client, data)
65
- end
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
- def callback_phase
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 get_app_access_token
75
- resp = Faraday.post(
76
- options.client_options.app_access_token_url,
77
- { app_id: options.client_id, app_secret: options.client_secret }.to_json,
78
- content_type: "application/json"
79
- )
80
- response_body = JSON.parse(resp.body)
81
- if response_body.key?('app_access_token')
82
- @app_access_token = response_body['app_access_token']
83
- else
84
- raise NoAppAccessTokenError, "cannot get app_access_token."
85
- end
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.7
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-12 00:00:00.000000000 Z
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.0.9
69
+ rubygems_version: 3.1.4
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: Lark(Feishu) OAuth2 Strategy for OmniAuth