forked from Gitlink/forgeplus
fixed bot安装仓库列表必须使用access_tokens获取到bot的token才能查询
This commit is contained in:
parent
04c30be5a6
commit
80fa5330b2
|
@ -18,7 +18,10 @@ class InstallationsController < ApplicationController
|
|||
|
||||
def repositories
|
||||
# 与github差异,所以取安装用户和bot对应所有的仓库
|
||||
@install_bots = BotInstall.where(bot_id: get_bot_id).where(installer_id: params[:id])
|
||||
# 必须使用access_tokens获取到bot的token才能查询
|
||||
tip_exception "Token无效" if current_user.platform != "bot"
|
||||
bot = Bot.find_by(uid: current_user.id)
|
||||
@install_bots = BotInstall.where(bot_id: bot.id).where(installer_id: params[:id])
|
||||
end
|
||||
|
||||
def update_secret
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
require 'openssl'
|
||||
require 'jwt' # https://rubygems.org/gems/jwt
|
||||
|
||||
# Private key contents
|
||||
private_pem = File.read("/Users/xxq/Documents/gitlink-webhook.2022-06-09.private-key.pem")
|
||||
private_key = OpenSSL::PKey::RSA.new(private_pem)
|
||||
|
||||
# Generate the JWT
|
||||
payload = {
|
||||
# issued at time, 60 seconds in the past to allow for clock drift
|
||||
iat: Time.now.to_i - 60,
|
||||
# JWT expiration time (10 minute maximum)
|
||||
exp: Time.now.to_i + (10 * 60),
|
||||
# GitHub App's identifier
|
||||
iss: "209248"
|
||||
}
|
||||
|
||||
jwt = JWT.encode(payload, private_key, "RS256")
|
||||
puts jwt
|
||||
# puts OpenSSL::PKey::RSA.new(private_key33).public_key.to_s
|
||||
#
|
||||
# rsa_private = OpenSSL::PKey::RSA.new(private_key33)
|
||||
# rsa_public = rsa_private.public_key
|
||||
#
|
||||
#
|
||||
|
||||
# puts decoded_token[0]
|
||||
# puts decoded_token[0]["iss"]
|
||||
|
||||
# serialized_private_key = OpenSSL::PKey::RSA::generate(2048).to_s
|
||||
|
||||
|
|
@ -2,12 +2,35 @@ require 'openssl'
|
|||
require 'jwt' # https://rubygems.org/gems/jwt
|
||||
|
||||
# Private key contents
|
||||
private_pem = File.read("/Users/xxq/Documents/gitlink-webhook.2022-06-09.private-key.pem")
|
||||
|
||||
private_key22="-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEApOebWmRV/ooNq5Ks04YnDU7pEezGShGvaiF0cIvn9jvmYHu0\nFialojvJV3VpB6xE6QBPXZ0Pi1lokZ9dMx8F5UWNx9WA7wf7xK3hAJLNml+GeewF\nou8vk/Ry7n6diLxETNVd7YzPvztn5qaMp/DXa+65i11H8a/XXqR7kCVnCevVlufh\nNr/Dp6dW31W8TInnDQasJFMZ8GY7f+tCwLXNc0M8p+TeDp9xmXHOrEB+S/mgbUOF\nXgRr6icbMmlT9bsAxYHrrDkcVxJhs0hq5vD3BaoK06gcZEnN7/HVNzgVSOYNsVNh\n9006cMgDSOwc9F8aulP7cr8k74INq1xswoGs9wIDAQABAoIBAHayc2NkF3YJXv+h\nqx7yUEfHBgKuAKiuBCqLfCnKuqPFx/So9h5/oPeeuzVlwL0SJePlIjuK4vZ128v9\n/vLeILtADmbJ6m2jvHh8hBmKkc3Ndplp50C5k/CWoufCYZhbk3oOlvZ3Rc4rb4VZ\nWqNDu3voMMv8z91KqeZo1LwUAA/l9mU++zLkRA6qOuWGBJFsM8YpshzxL5lzRUb3\n7y+YJDyUZztfzKwr6pqm1n9B2e6e+znCw1vMZXp2TbUrpvrrXSxlgdNuK68SkZX6\nTdZUD8y0viwaioRVf3vR+e/Bf7yZannGdvcmVGs0A7dq9QgHkakqNHiRkQgwviSq\nbjBo7dECgYEAzekeP5j/dAPkv9X4qnmZ4du/+ZgrQrJckDD/JuNIBmQT9m286l4P\nmb2TBcWkswVOZaS5Qy2bN/69rwIbcdvbaROGBCabn3ATK4fSzmUk31M2rRKYZqaU\nMi0W2g2YtSRg+bV6S7aFXa98j5+JlqJeDZQoRuvL68ooq5WzFWmfYnkCgYEAzQTi\n4USqz2z66BfU+v2rchzK8URxnv7EW/CG3XFRsG+1UXCyEIct2L7rzvC7r7+jjS4s\ngmV3Civ1sckGMwikL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\njjzpAoGAdUXFW1elfjXpfIYZf7vUV7MPquKL7qAcopd96XBszhOn7g+ibzem+wgt\n1UTSeOBESYANHeJk2MuWPSRXk/FlQETVIcPAEp0kxbwQE+7YEdrMVeDcIe5lPwGD\n+WuS3kg0MPgUrXZXn74gcwWmSIOyHfqXULqOxWE25uU2icdV+2w=\n-----END RSA PRIVATE KEY-----\n"
|
||||
private_key = OpenSSL::PKey::RSA.new(private_key33)
|
||||
# puts private_key.to_json
|
||||
# private_pem = File.read("/Users/xxq/Documents/gitlink-webhook.2022-06-09.private-key.pem")
|
||||
private_pem = "-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEAy3rJwhzC9K5f4Rc6KwYQKvdsUsbzrKdENBCjGq0kZ8LJltw+
|
||||
TRuLVp0hwrWXS9msadjBnzatYneBrqnggj87pU0Mf/f6KkTmIsFH2gDKNMN6hRg/
|
||||
JW5XXveexGa9dZIQHPKOmp9dC+YpLHOPRO0NsYJM/JoQ4rWRhtMvq0zR/fJDuXyt
|
||||
xLehfH4N4ppVbdRGaK+FIKNCjHTmL/3jZ0b2J9D4Al9R5QWlEmRPa4ZFCOZNUMXK
|
||||
nplNu2FE/ZjyKjE+f0MAn8hcSVR25XiQZ6StnxdyPvhXYNNU7yVJGTfCK/oTchTr
|
||||
Tfk4bKIkct38datffjlhKM45VabhUfIStNr5uwIDAQABAoIBADSMgGBmBx8jjVVX
|
||||
J0mHJlPCVDJIeROkmuOLTGQORPGbB26zcE9/houWxuo+9VS8YV9wgAh7GWntjQsr
|
||||
ifR5GhFFha3iv7N82aYuHj05qP7ZYOHQcjZbearn7hOwqMsdLpYbOiLKd0Akb4uw
|
||||
SFa3laq7CODPdP7nfy6/iXcGvtCC84E8XwDuUcFbzX8lLq0UI6HvdnySYOvglO3P
|
||||
txqr76dc61nLEIu945uVKndzu65sWRfC397JG+hgYFUwikbiFPAVVH4jsiCzMAW0
|
||||
oaTp6zQiE+h7HTGGHhnxFmnynmuq01E+wfxNvf8NHteBIMJA8g/gGHdpp+8E85V7
|
||||
bcF8+fECgYEA5cs8nZHfrTdjqZB6vgY1sCVsuuHtmEACu3zbJu9dr21ps6bomnDW
|
||||
Lw9Dx4tYSHPcL3zlu913qvXCnXsUGtjKeIVTHCdnwCnDTEam6GsDZab9zcmJ8Gkn
|
||||
wqsjr/Cy7pjwxqT3nFRUGaJmrFUUfPQuNmSYWQbRiRIQirGY2JlZLvMCgYEA4q9Q
|
||||
j8cwq5i1blWuyam8bx3efHBHMiMpJL/clc03//ddpsiae8GXZgRySJx9YPAYS+X/
|
||||
ApVfnB/en+xidCIg8P2rRjRW/GgW3Y6rjLUMIFMD/0ObezX/dp2AVHUdOdlZ7z+k
|
||||
4Ba8TZ8u5sfUO7USTxFl+fextLdBDSetOw/GDBkCgYAsYSjuwYpyWJ0t1VJvOqHJ
|
||||
yCCMoy+Q1OPyM7XbeiUcyUO9x4FquloTMp6DfjzpmT6wCS4RLz96TAZvBaMnYDES
|
||||
P6WCbXXTHf2y0H5RqsE4M50WzlKOlLByHz1AMHtOK0ltA9UyYvLvFHdB1xii3UHD
|
||||
jYACyZdUIqIBNzVut4cK0wKBgBNbHOnp/EHqvDM7pb0afTiPuFuvyqSBVBYLO+6e
|
||||
o1V77cc8AdTnZuITJx8EHcCVP73bWbcCwjM2lW/aY12/PEjXoDRSa8sJqEoq0IMn
|
||||
Qm3QKNs3DqOqrLGYKUkM5v31jTRcnttzlYibOwoBriGbCIEv3yFFASuJKkjRRn1w
|
||||
j1yhAoGBALqwZzRAle7t2jEWOyLaJeHUoSiZJv5dHOMRog7k5H24uTEKf3JCovQO
|
||||
wZd4cIA4oXD/3b5cK3H2e5YjhBunsMRhRBLgz8FD4y69cKxbcgPvtjhkwYRB0/cy
|
||||
21dHe2o7HfuZgUuh0kOlT0e326gQPIIlwuCBEAq6LzWrg8nd9Loz
|
||||
-----END RSA PRIVATE KEY-----"
|
||||
private_key = OpenSSL::PKey::RSA.new(private_pem)
|
||||
|
||||
# Generate the JWT
|
||||
payload = {
|
||||
|
@ -16,27 +39,15 @@ payload = {
|
|||
# JWT expiration time (10 minute maximum)
|
||||
exp: Time.now.to_i + (10 * 60),
|
||||
# GitHub App's identifier
|
||||
iss: "782"
|
||||
iss: "803"
|
||||
}
|
||||
|
||||
jwt = JWT.encode(payload, private_key, "RS256")
|
||||
puts jwt
|
||||
# puts OpenSSL::PKey::RSA.new(private_key33).public_key.to_s
|
||||
#
|
||||
rsa_private = OpenSSL::PKey::RSA.new(private_key33)
|
||||
rsa_public = rsa_private.public_key
|
||||
|
||||
# decoded_token = JWT.decode jwt, nil, false
|
||||
begin
|
||||
decoded_token = JWT.decode jwt, rsa_private, true, { algorithm: 'RS256' }
|
||||
rescue JWT::DecodeError
|
||||
puts "jwt is not mmmmmm"
|
||||
end
|
||||
|
||||
#
|
||||
puts decoded_token[0]
|
||||
puts decoded_token[0]["iss"]
|
||||
|
||||
# serialized_private_key = OpenSSL::PKey::RSA::generate(2048).to_s
|
||||
|
||||
|
||||
decoded_token = JWT.decode "eyJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE2ODA1OTkzNDAsImV4cCI6MTY4MDYwMDAwMCwiaXNzIjoiODAzIn0.wOCCMVbrulTVCIKDvmLtxCkTLtWJMGmY2mIZgfdJcKcixqZek1y_9YD7wF07wqP6qTjQaNiSDjdJSDGzO_Qi3qQT_2BaR6EWBUIcbaNz5GTHKLcOW4SFWj13OFJwjom6egz489b6qA3MPXmliWYR6F5zlLu1jlXjaWVvUZAy0AuAdmWiSocdjurt_giEIDefiRcPu_NbccWG-mAwa9wV9ja2PoZUJyHlzXR6rioLIO1rtw5bIX3E4YNPde9EkEK1eYLmedmhKfwlgX2CgdGodSHPg5Vro09XWiGaJkBwoi1T41BLVsb5hxqQc3DLrz1ZFFY1vXEkxIw4BIXitpk3kg", nil, false
|
||||
puts decoded_token
|
||||
puts Time.now.to_i - 60 - decoded_token[0]["exp"].to_i > 0
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue