token解密异常处理

This commit is contained in:
xxq250 2023-04-04 17:40:53 +08:00
parent bbc113ec1b
commit 13148890ec
1 changed files with 4 additions and 1 deletions

View File

@ -19,7 +19,7 @@ class InstallationsController < ApplicationController
def repositories def repositories
# 与github差异所以取安装用户和bot对应所有的仓库 # 与github差异所以取安装用户和bot对应所有的仓库
# 必须使用access_tokens获取到bot的token才能查询 # 必须使用access_tokens获取到bot的token才能查询
tip_exception "Token无效" if current_user.platform != "bot" tip_exception "无效Token" if current_user.platform != "bot"
bot = Bot.find_by(uid: current_user.id) bot = Bot.find_by(uid: current_user.id)
@install_bots = BotInstall.where(bot_id: bot.id).where(installer_id: params[:id]) @install_bots = BotInstall.where(bot_id: bot.id).where(installer_id: params[:id])
end end
@ -118,6 +118,9 @@ class InstallationsController < ApplicationController
decoded_token = JWT.decode token, nil, false decoded_token = JWT.decode token, nil, false
# 前面已验证token有效期和正确性 # 前面已验证token有效期和正确性
decoded_token[0]["iss"] decoded_token[0]["iss"]
rescue JWT::DecodeError
Rails.logger.error "jwt token decode error:#{token}"
tip_exception("无效Token")
end end
end end