From 3c51d69555d6a32a1484f4007e5c27043c708e62 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 09:57:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4Bot=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 29 +++++++++++++++++---- config/routes.rb | 4 ++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 40efa3c90..6e66431be 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -6,6 +6,25 @@ class InstallationsController < ApplicationController @install_bots = BotInstall.where(:installer_id => current_user.id) end + def update_secret + ActiveRecord::Base.transaction do + bot = Bot.find params[:id] + application = Doorkeeper::Application.find_by(uid: bot.client_id, secret: bot.client_secret) + bot.client_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate + bot.save! + application.secret = bot.client_secret + application.save! + render_ok + end + end + + def update_private_key + bot = Bot.find params[:id] + bot.private_key = OpenSSL::PKey::RSA::generate(2048).to_s + bot.save! + render_ok + end + def auth_active begin @bot = Bot.find params[:id] @@ -35,11 +54,11 @@ class InstallationsController < ApplicationController if @application.present? # 给bot生成token,因为bot是机器人操作 @access_token = Doorkeeper::AccessToken.create!({ :application_id => @application.id, - :resource_owner_id => @bot.uid, - :scopes => "public write", - :expires_in => "604800", - :use_refresh_token => true - }) + :resource_owner_id => @bot.uid, + :scopes => "public write", + :expires_in => "604800", + :use_refresh_token => true + }) end render_ok(token: @access_token.token) end diff --git a/config/routes.rb b/config/routes.rb index d6e73aebb..3d6cc8f55 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1048,7 +1048,9 @@ Rails.application.routes.draw do resources :commit_logs, :only => [:create] scope '/app' do - post 'auth_active', to: 'installations#auth_active' + post ':id/auth_active', to: 'installations#auth_active' + post ':id/update_private_key', to: 'installations#update_private_key' + post ':id/update_secret', to: 'installations#update_secret' resources :installations do get :repositories, on: :collection member do