User API keys specification에서의 토론을 이어갑니다:
로컬에서 User API 키를 테스트하기 위해 작은 유틸리티 스크립트를 작성했습니다.
먼저 종속성을 설치합니다:
gem install addressable openssl base64 json
다음은 스크립트입니다:
require 'addressable'
require 'openssl'
require 'base64'
require 'json'
PRIVATE_KEY = OpenSSL::PKey::RSA.new(2048)
PUBLIC_KEY = PRIVATE_KEY.public_key
puts 'What is the target site?'
site = STDIN.gets.chomp
template = Addressable::Template.new("#{site}/user-api-key/new{?query*}")
url = template.expand({
query: {
application_name: 'ruby',
client_id: `hostname`,
scopes: 'read',
public_key: PUBLIC_KEY,
nonce: 1
}
})
puts "navigate to #{url}."
puts
puts "copy the generated key in here"
puts
puts "press ENTER type end and press ENTER again"
puts
$/ = "end"
encoded_key = STDIN.gets.chomp
user_api_key = JSON.parse(PRIVATE_KEY.private_decrypt(Base64.decode64(encoded_key)))
puts "Your User API Key is #{user_api_key['key']}"