Created
February 13, 2020 06:10
-
-
Save ysv/2c018de1a7ff40fe93472ded204131b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "pry-byebug" | |
require "openssl" | |
require "jwt" | |
require "securerandom" | |
priv_key = File.open(ENV.fetch("IDENT_PRIV_KEY")) do |f| | |
OpenSSL::PKey.read(f.read) | |
end | |
profile = { | |
email: "[email protected]", | |
phone: { | |
code: "38044", | |
number: "1234567", | |
}, | |
registrationDate: (Time.now.to_i - 100).to_s, | |
registeredSystem: "dev.yellow.openware.work" | |
}.yield_self { |h| Base64.urlsafe_encode64(JSON.dump(h)) } | |
# binding.pry | |
payload = { | |
uid: "UID123456", | |
profile: profile | |
} | |
claims = { | |
algorithm: "RS256", | |
iss: "sandbox", | |
jti: "TEST", | |
iat: Time.now.to_i, | |
exp: (Time.now + 60 * 60 * 24 *7).to_i, | |
} | |
jwt = JWT.encode(payload.merge(claims), priv_key, claims[:algorithm]) | |
pp jwt | |
# const payload = { | |
# uid: 'up12345', // userId | |
# profile: { | |
# email: '[email protected]', | |
# phone: { | |
# code: '38044', | |
# number: '1234567', | |
# }, | |
# }, | |
# }; | |
# const options = { | |
# algorithm: 'RS256', | |
# issuer: 'cex', // merchantId | |
# expiresIn: '1d', | |
# }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment