ruby_jwk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23921b96849d38f01a575f59134abbe026c6848c1cbc4c460c27d92bcf77a809
4
- data.tar.gz: b787be04a11e0ffbf0fe9f3c1418747589f60563a7067e8910a741b6b56a6335
3
+ metadata.gz: 65d30dcf7895ee00236d272c7dbce4572e60cf45a4907ada1cf286e9184516bd
4
+ data.tar.gz: aaa39468e2fdd1ed1e9299e49d2f4953f149f02100382d6fbfe3bbddc0e5ee2d
5
5
  SHA512:
6
- metadata.gz: 1dab2c10dcb374bd786b21e244105bd1ef391416838f5736d6fc168a8dcf57a5ac19e3aaabeb37968f230a6bf8fd26b6e49cbb0e9027b79342443bdeaa06d400
7
- data.tar.gz: d06b10422d2f8b94def06b55fe6653c818535bed789c83f5cafaf06ed74ca3807bded3fa14d2161f4294aea985cde3c653abb856e9764a3e40dfb18a0fc955b2
6
+ metadata.gz: 97c756981851f833cd074eae8d2760da354aa77ae5d24f343a8b67e23049265d9f2e3dd83da699194693fe1537c6a8d21cb4da3ca46fe34c6256e09b26f1623d
7
+ data.tar.gz: ebc2f965cf933e7b17d876e1dc8d7f3d3e94ed0fe1075399bd179122461259c9b87210e76253cdf0340dbb0fe9ac5015a2ae10c778aedd12df11b929a3c8fc53
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # RubyJwk
2
- Authenticate JWKs via public JWT enspoint
2
+ Authenticate JWT with JWKs.
3
3
 
4
4
  ## Usage
5
5
  How to use my plugin.
@@ -20,6 +20,47 @@ Or install it yourself as:
20
20
  ```bash
21
21
  $ gem install ruby_jwk
22
22
  ```
23
+ ## Getting started
24
+
25
+ Authentication system exposes a JWKS endpoint for each tenant, which looks like `https://YOUR_DOMAIN/.well-known/jwks.json`. This endpoint will contain the JWK used to verify all Authentication JWTs for this tenant. This endpoint has to be configured like below in initializer file.
26
+
27
+ ```ruby
28
+ RubyJwk.jwk_url = 'https://YOUR_DOMAIN/.well-known/jwks.json'
29
+ RubyJwk.skip_issuers = [] # to skip authentication for certain issuers
30
+ ```
31
+
32
+ Suppose each tenant has different endpoint then configure it as below. Here `:tenant_name` gets replaced by `tenant` attribute in JWT payload.
33
+
34
+ ```ruby
35
+ RubyJwk.jwk_url = 'https://:tenant_name/.well-known/jwks.json'
36
+ ```
37
+
38
+ To set up a controller with tenant authentication, just add this before_action
39
+
40
+ ```ruby
41
+ class ApplicationController < ActionController::API
42
+ include RubyJwk::Authenticate
43
+ before_action :authenticate_tenant!
44
+ end
45
+ ```
46
+ To get the JWT payload, use the following helper:
47
+ ```ruby
48
+ jwt_payload
49
+ ```
50
+
51
+ To get tenant name from JWT, use the following helper:
52
+ ```ruby
53
+ jwt_tenant_name
54
+ ```
55
+
56
+ ### Token verification
57
+ Currently, we support below verifications
58
+ * Signature
59
+ * Token expiry
60
+ * nbf
61
+
62
+ ## Reference
63
+ https://blog.unathichonco.com/verifying-jwts-with-jwks-in-ruby
23
64
 
24
65
  ## Contributing
25
66
  Contribution directions go here.
@@ -1,7 +1,7 @@
1
1
  module RubyJwk
2
2
  module Authenticate
3
3
  def authenticate_tenant!
4
- return if RubyJwk.skip_issuers.to_a.include?(payload[:iss])
4
+ return if RubyJwk.skip_issuers.to_a.include?(jwt_payload[:iss])
5
5
 
6
6
  JWT.decode(token, nil, true, { algorithm: 'RS256', jwks: jwk_loader})
7
7
  rescue JWT::DecodeError => e
@@ -14,6 +14,10 @@ module RubyJwk
14
14
  render status: 401, json: error_response_template("Authentication failed! - #{e.message}")
15
15
  end
16
16
 
17
+ def jwt_tenant_name
18
+ @jwt_payload.dig('tenant')
19
+ end
20
+
17
21
  private
18
22
 
19
23
  # invalidate becomes true when kid not found
@@ -30,10 +34,6 @@ module RubyJwk
30
34
  end
31
35
  end
32
36
 
33
- def tenant_name
34
- @payload.fetch('tenant')
35
- end
36
-
37
37
  def error_response_template(msg)
38
38
  {
39
39
  error: {
@@ -1,7 +1,4 @@
1
1
  module RubyJwk
2
2
  class ApplicationController < ::ApplicationController
3
- def authenticate_tenant!
4
- byebug
5
- end
6
3
  end
7
4
  end
@@ -1,3 +1,3 @@
1
1
  module RubyJwk
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_jwk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - santhanakarthikeyan