Class: OmniAuth::Strategies::Feishu

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/feishu.rb

Overview

飞书登录

飞书要求请求采用 json 格式主体,很多都需要自定义 官方文档: open.feishu.cn/document/ukTMukTMukTM/uETOwYjLxkDM24SM5AjN

Defined Under Namespace

Classes: NoAppAccessTokenError

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



51
52
53
54
55
# File 'lib/omniauth/strategies/feishu.rb', line 51

def authorize_params
  super.tap do |params|
    params[:app_id] = options.client_id
  end
end

#build_access_tokenObject

飞书采用非标准 OAuth 2 请求体和返回结构体,需要自定义



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/omniauth/strategies/feishu.rb', line 58

def build_access_token
  code = request.params['code']
  data = client.request(:post, options.client_options.token_url,
                        { body: {
                            code: code,
                            grant_type: 'authorization_code'
                          }.to_json,
                          headers: {
                            'Content-Type' => 'application/json; charset=utf-8',
                            'Authorization' => "Bearer #{app_access_token}"
                          }
                        })
                .parsed['data']

  ::OAuth2::AccessToken.from_hash(client, data)
end

#raw_infoObject



41
42
43
44
45
46
47
48
49
# File 'lib/omniauth/strategies/feishu.rb', line 41

def raw_info
  @raw_info ||= client.request(:get, options.client_options.,
                                { headers: {
                                    'Content-Type' => 'application/json; charset=utf-8',
                                    'Authorization' => "Bearer #{access_token.token}"
                                  }
                                })
                      .parsed['data']
end