• Stars
    star
    296
  • Rank 135,281 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and JSON Web Key) in Ruby

JSON::JWT

JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and JSON Web Key) in Ruby

Installation

gem install json-jwt

Resources

Examples

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)

If you need to get a JWK from jwks_uri of OpenID Connect IdP, you can use JSON::JWK::Set::Fetcher to fetch (& optionally cache) it.

# JWK Set Fetching & Caching
# NOTE: Optionally by setting cache instance, JWKs are cached by kid.
JSON::JWK::Set::Fetcher.cache = Rails.cache

JSON::JWK::Set::Fetcher.fetch(jwks_uri, kid: kid)
# => returns JSON::JWK instance or raise JSON::JWK::Set::KidNotFound

For more details, read Documentation Wiki.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2011 nov matake. See LICENSE for details.

More Repositories

1

fb_graph

This gem doesn't support FB Graph API v2.0+. Please use fb_graph2 gem instead.
Ruby
1,036
star
2

rack-oauth2

OAuth 2.0 Server & Client Library. Both Bearer and MAC token type are supported.
Ruby
691
star
3

openid_connect

OpenID Connect Server & Client Library
Ruby
405
star
4

paypal-express

Ruby Gem for PayPal Express Checkout API
Ruby
372
star
5

apple_id

Sign in with Apple backend library in Ruby
Ruby
198
star
6

jose-php

PHP JOSE Library (JWT, JWS, JWE, JWK, JWK Set, JWK Thumbprint are supported)
PHP
138
star
7

fb_graph2

Ruby
107
star
8

fb_graph_sample

An rails app using fb_graph. Learn how to authenticate facebook users using fb_graph and facebook's JavaScript SDK or OAuth2.
Ruby
105
star
9

itunes-receipt

Handle iTunes In App Purchase Receipt Verification
Ruby
94
star
10

paypal-express-sample

Learn how to use PayPal Express API in your Rails app.
Ruby
54
star
11

openid_connect_sample

Ruby
46
star
12

rack-oauth2-sample

Rack::OAuth2 Sample Server (Bearer)
Ruby
44
star
13

openid_connect_sample_rp

Ruby
25
star
14

activitystreams

RubyGem for ActivityStreams Publishers
Ruby
20
star
15

square

Square API Client
Ruby
19
star
16

web_authn

W3C Web Authentication API (a.k.a. WebAuthN / FIDO 2.0) RP library in Ruby
Ruby
19
star
17

signin-with-apple

Sample app for β€œapple_id” ruby gem.
Ruby
17
star
18

motion-oauth2

Ruby
16
star
19

webfinger

WebFinger Client in Ruby
Ruby
15
star
20

twitter_oauth2

Twitter OAuth 2.0 Client Library in Ruby
Ruby
13
star
21

oauth_sample

OAuth sample consumer & provider
Ruby
13
star
22

attr_required

Provide attr_required with presence validation
Ruby
9
star
23

fb_graph-mock

Ruby
9
star
24

openid_connect_sample2

Ruby
8
star
25

jsonbuilder

Json builder which has the same interface with Builder::XmlMarkup
Ruby
7
star
26

rack-oauth2-sample-mac

Rack::OAuth2 Sample Server (MAC)
Ruby
7
star
27

web_authn_sample

Ruby
5
star
28

iknow

moved to smartfm
4
star
29

rack-locale_memorable

Ruby
4
star
30

SWD

SWD (Simple Web Discovery) Client Library
Ruby
4
star
31

connect

Yet Another OpenID Connect Gem... might be
Ruby
3
star
32

connect-rp-certified

Ruby
3
star
33

apple_pay

Ruby
3
star
34

cose-key

COSE Key (RSA & EC) in Ruby
Ruby
3
star
35

rubymotion-crypto-sample

Ruby
3
star
36

FB-Connect

Objective-C
3
star
37

safie

Safie API Client in Ruby
Ruby
2
star
38

CookieFlash

Cookie-based Rails flash
JavaScript
2
star
39

nov.github.io

GitHub Pages Repository
HTML
2
star
40

CredentialsAPI

Java
2
star
41

gadgets

OpenSocial Gadgets
JavaScript
2
star
42

draft-ietf-oauth

OAuth 2.0
2
star
43

oauth.jp-karma

OAuth.jp Karma
Ruby
2
star
44

AccountManager

Java
2
star
45

alb-backed

Ruby
1
star
46

tower-sample

CoffeeScript
1
star
47

cocoa_teks

Ruby
1
star
48

oauth.jp

SCSS
1
star
49

faraday-jwt

Ruby
1
star
50

oauth-wmrm-sample

HTML
1
star
51

apple-pay-js

1
star
52

otp-sample

Rails Sample for Google Authenticator
Ruby
1
star
53

restclient_with_cert

RestClient with embedded cert
Ruby
1
star
54

persona

JavaScript
1
star
55

SecureRandom

SecureRandom in PHP
PHP
1
star
56

openid_sample

Sample OpenID Relying Party (with AX & UI Extension)
Ruby
1
star
57

iOS-Enterprise-SSO

iOS Enterprise SSO Test App
Swift
1
star
58

idcon

CSS
1
star
59

account-chooser

Account Chooser RP Sample
Ruby
1
star
60

try_git

1
star
61

crash-on-ios6

Ruby
1
star
62

backplane-sample

Ruby
1
star
63

connectable

Rails sample for connectable protocols
Ruby
1
star