JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and JSON Web Key) in Ruby
|
%!s(int64=9) %!d(string=hai) anos | |
---|---|---|
lib | %!s(int64=9) %!d(string=hai) anos | |
spec | %!s(int64=9) %!d(string=hai) anos | |
.gitignore | %!s(int64=12) %!d(string=hai) anos | |
.gitmodules | %!s(int64=12) %!d(string=hai) anos | |
.rspec | %!s(int64=14) %!d(string=hai) anos | |
.travis.yml | %!s(int64=9) %!d(string=hai) anos | |
Gemfile | %!s(int64=12) %!d(string=hai) anos | |
LICENSE | %!s(int64=14) %!d(string=hai) anos | |
README.md | %!s(int64=9) %!d(string=hai) anos | |
Rakefile | %!s(int64=11) %!d(string=hai) anos | |
VERSION | %!s(int64=9) %!d(string=hai) anos | |
json-jwt.gemspec | %!s(int64=11) %!d(string=hai) anos |
JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and JSON Web Key) in Ruby
gem install json-jwt
require 'json/jwt'
private_key = OpenSSL::PKey::RSA.new <<-PEM
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAyBKIFSH8dP6bDkGBziB6RXTTfZVTaaNSWNtIzDmgRFi6FbLo
:
-----END RSA PRIVATE KEY-----
PEM
public_key = OpenSSL::PKey::RSA.new <<-PEM
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyBKIFSH8dP6bDkGBziB6
:
-----END PUBLIC KEY-----
PEM
# Sign & Encode
claim = {
iss: 'nov',
exp: 1.week.from_now,
nbf: Time.now
}
jws = JSON::JWT.new(claim).sign(private_key, :RS256)
jws.to_s
# Decode & Verify
input = "jwt_header.jwt_claims.jwt_signature"
JSON::JWT.decode(input, public_key)
For more details, read Documentation Wiki.
Copyright (c) 2011 nov matake. See LICENSE for details.