建木认证code加密生成
This commit is contained in:
parent
8a187df5f4
commit
29342e11fb
|
@ -63,6 +63,7 @@ module ProjectsHelper
|
|||
project_category_id: project.project_category_id,
|
||||
project_language_id: project.project_language_id,
|
||||
license_id: project.license_id,
|
||||
jianmu_devops: jianmu_devops_code(project, user),
|
||||
ignore_id: project.ignore_id
|
||||
}).compact
|
||||
|
||||
|
@ -98,4 +99,35 @@ module ProjectsHelper
|
|||
def render_educoder_avatar_url(project_educoder)
|
||||
[Rails.application.config_for(:configuration)['educoder']['cdn_url'], project_educoder&.image_url].join('/')
|
||||
end
|
||||
|
||||
# 静默登录方式:
|
||||
#
|
||||
# 数据格式为JSON:
|
||||
# {
|
||||
# "userId": "xxx", // 用户唯一标识
|
||||
# "ref": "xxx", // 仓库唯一标识
|
||||
# "owner": "xxx", // 用户登录名或组织账号
|
||||
# "timestamp": xxx // 当前时间戳,单位:毫秒
|
||||
# }
|
||||
# 加密方式:把数据序列化成JSON字符串,用Client Secret对称加密(模式:AES/ECB/PKCS5Padding)
|
||||
#
|
||||
# API:
|
||||
# GET:https://ci-v3.test.jianmuhub.com/oauth2/authorize?code=${encode(密文)}
|
||||
def jianmu_devops_code(project, user)
|
||||
data = { userId: user.id, ref: project.identifier, owner: project.owner.login, timestamp: Time.now.to_i * 1000 }
|
||||
aes_encrypt(data)
|
||||
end
|
||||
|
||||
def aes_encrypt(des_text)
|
||||
# des_text='{"access_key_id":"STS.NTuC9RVmWfJqj3JkcMzPnDf7X","access_key_secret":"E8NxRZWGNxxMfwgt5nFLnBFgg6AzgXCZkSNCyqygLuHM","end_point":"oss-accelerate.aliyuncs.com","security_token":"CAIS8gF1q6Ft5B2yfSjIr5fACIPmu7J20YiaaBX7j2MYdt9Cq6Ocujz2IHhMenVhA+8Wv/02n2hR7PcYlq9IS55VWEqc/VXLaywQo22beIPkl5Gfz95t0e+IewW6Dxr8w7WhAYHQR8/cffGAck3NkjQJr5LxaTSlWS7OU/TL8+kFCO4aRQ6ldzFLKc5LLw950q8gOGDWKOymP2yB4AOSLjIx6lAt2T8vs/7hmZPFukSFtjCglL9J/baWC4O/csxhMK14V9qIx+FsfsLDqnUIs0YWpf0p3P0doGyf54vMWUM05A6dduPS7txkLAJwerjVl1/ADxc0/hqAASXhPeiktbmDjwvnSn4iKcSGQ+xoQB468eHXNdvf13dUlbbE1+JhRi0pZIB2UCtN9oTsLHcwIHt+EJaoMd3+hGwPVmvHSXzECDFHylZ8l/pzTwlE/aCtZyVmI5cZEvmWu2xBa3GRbULo7lLvyeX1cHTVmVWf4Nk6D09PzTU8qlAj","bucket":"edu-bigfiles1","region":"oss-cn-hangzhou","callback_url":"https://data.educoder.net/api/buckets/callback.json","bucket_host":"data.educoder.net"}'
|
||||
# des = OpenSSL::Cipher::Cipher.new('aes-256-ctr')
|
||||
des = OpenSSL::Cipher.new('AES-256-CBC')
|
||||
des.encrypt
|
||||
# des.padding =
|
||||
des.key = 'bf3c199c2470cb477d907b1e0917c17b'
|
||||
des.iv = "5183666c72eec9e4"
|
||||
result = des.update(des_text)
|
||||
result << des.final
|
||||
Base64.strict_encode64 result
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue