Class: JPSClient::Auth
- Inherits:
-
Object
- Object
- JPSClient::Auth
- Defined in:
- lib/jpsclient/auth/auth.rb
Overview
JPS 中心化登录(BFF OIDC)。
流程(见 OIDC 接入文档 §5.2/§5.3):自生成一次性 code → 拉起系统浏览器打开 authorize → 浏览器侧完成飞书 SSO 并按 code 绑定登录态 → 客户端凭同一 code 轮询 /api/oidc/token 取回登录态。 拿到的 token 即会话凭证(业务请求作 SESSION Cookie 携带)。
Constant Summary collapse
- LOGIN_ENTRY_PATH =
'/auth/jwt/login'.freeze
- OIDC_TOKEN_PATH =
'/api/oidc/token'.freeze
- OIDC_STATE =
'oidc_login'.freeze
- POLL_INTERVAL =
轮询:覆盖用户在浏览器里扫码 + 飞书 SSO 的耗时,取宽松值
2.0- POLL_TIMEOUT =
300.0
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#avatar ⇒ Object
readonly
Returns the value of attribute avatar.
-
#lark_user_id ⇒ Object
readonly
Returns the value of attribute lark_user_id.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
-
#tenant_manager ⇒ Object
readonly
Returns the value of attribute tenant_manager.
-
#token_expire_timestamp ⇒ Object
readonly
Returns the value of attribute token_expire_timestamp.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#authorize ⇒ Object
兼容旧接口.
-
#get_token_data ⇒ Object
获取 token 数据(供 Token#save 使用,内部 snake 键).
- #get_username ⇒ Object
-
#initialize(config = nil) ⇒ Auth
constructor
A new instance of Auth.
-
#login ⇒ Object
主登录入口。成功返回 true,用户取消返回 :user_cancelled,失败返回 false.
Constructor Details
#initialize(config = nil) ⇒ Auth
Returns a new instance of Auth.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/jpsclient/auth/auth.rb', line 86 def initialize(config = nil) @config = config || LoginConfig.new # 从 config 推导 API / WEB 域,缺失时回退固定正式服地址 @api_base = Endpoints.origin_of(@config.api_endpoint, Endpoints::DEFAULT_API_BASE) @web_origin = Endpoints.origin_of(@config.redirect_uri, Endpoints::DEFAULT_WEB_ORIGIN) @access_token = nil @username = nil @user_id = nil @permissions = nil @lark_user_id = nil @tenant_manager = false @avatar = nil @token_expire_timestamp = 0 @verbose = JPSClient.debug? end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
74 75 76 |
# File 'lib/jpsclient/auth/auth.rb', line 74 def access_token @access_token end |
#avatar ⇒ Object (readonly)
Returns the value of attribute avatar.
76 77 78 |
# File 'lib/jpsclient/auth/auth.rb', line 76 def avatar @avatar end |
#lark_user_id ⇒ Object (readonly)
Returns the value of attribute lark_user_id.
75 76 77 |
# File 'lib/jpsclient/auth/auth.rb', line 75 def lark_user_id @lark_user_id end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
75 76 77 |
# File 'lib/jpsclient/auth/auth.rb', line 75 def @permissions end |
#tenant_manager ⇒ Object (readonly)
Returns the value of attribute tenant_manager.
75 76 77 |
# File 'lib/jpsclient/auth/auth.rb', line 75 def tenant_manager @tenant_manager end |
#token_expire_timestamp ⇒ Object (readonly)
Returns the value of attribute token_expire_timestamp.
76 77 78 |
# File 'lib/jpsclient/auth/auth.rb', line 76 def @token_expire_timestamp end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
75 76 77 |
# File 'lib/jpsclient/auth/auth.rb', line 75 def user_id @user_id end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
74 75 76 |
# File 'lib/jpsclient/auth/auth.rb', line 74 def username @username end |
Instance Method Details
#authorize ⇒ Object
兼容旧接口
115 116 117 |
# File 'lib/jpsclient/auth/auth.rb', line 115 def login end |
#get_token_data ⇒ Object
获取 token 数据(供 Token#save 使用,内部 snake 键)
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/jpsclient/auth/auth.rb', line 124 def get_token_data return nil unless @access_token { 'token' => @access_token, 'username' => @username, 'user_id' => @user_id, 'permissions' => @permissions, 'lark_user_id' => @lark_user_id, 'tenant_manager' => @tenant_manager, 'avatar' => @avatar, 'token_expire_timestamp' => @token_expire_timestamp } end |
#get_username ⇒ Object
119 120 121 |
# File 'lib/jpsclient/auth/auth.rb', line 119 def get_username @username end |
#login ⇒ Object
主登录入口。成功返回 true,用户取消返回 :user_cancelled,失败返回 false
106 107 108 109 110 111 112 |
# File 'lib/jpsclient/auth/auth.rb', line 106 def login puts "🔐 需要登录 JPS..." oidc_login rescue Interrupt puts "\n用户中断登录操作" :user_cancelled end |