调整Bot授权接口
This commit is contained in:
parent
1d9df770b5
commit
3c51d69555
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue