fb-jwt-auth 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 809db265860e3142598f429c53482e4b642543717c83cab5c6fbe46fd4834ee5
4
- data.tar.gz: a26191f1f776d29b42f3095f4ae9c9dca20d032ab31f8add3efd7dbca99239a9
3
+ metadata.gz: 45ebbebff675bd2afe201e48c9d3d711ae255619511e00318f6cd39aef8094c0
4
+ data.tar.gz: e1d51f15d8b8a4a55be59228edce5aa3723b74bd312d0b87f868e81ecd3bcdb3
5
5
  SHA512:
6
- metadata.gz: 9c86735004359b8c7b0261808d0bf90ed5b7ebd56cca83f83dcbb950c1894825df06051c8fc85f23ceef3c6cc79c16a05fd1cd293676d80832dd3e2c3843e1f6
7
- data.tar.gz: 318864900ac94c5f51c1e781ba5aa9b990604acb85084db810144963cb93941465b7428931dafd71d0918343d4cb925778b16b3a5c8bc48899373923332d6317
6
+ metadata.gz: 56e7552bcdede5d4ce45200ab5160a790128e80ee0a6f276d0e4d7f9f4515de14db7a9efab79554df31593ee801e9a983d1af413327427b1c88e184a80e88042
7
+ data.tar.gz: 395d1d6f094db54c9411bc20d6804c94ea56f7a52e60a64e4496f6ed75d2bb5bd52817ada3fbc7058a404fa47db4b48b850df16ccb9a4ae96236b4591a13d2c6
@@ -1,3 +1,9 @@
1
+ # 0.3.0
2
+ * Request non cached version of public key if first validition fails
3
+
4
+ # v0.2.2
5
+ * Add token not present exception when token is empty
6
+
1
7
  # v0.2.1
2
8
  * Add better error messages
3
9
 
data/README.md CHANGED
@@ -25,6 +25,16 @@ Fb::Jwt::Auth.configure do |config|
25
25
  config.service_token_cache_root_url = ENV['SERVICE_TOKEN_CACHE_ROOT_URL']
26
26
  end
27
27
  ```
28
+ In order to generate the service access token we need to use `Fb::Jwt::Auth::ServiceAccessToken.new.generate` or if you require a subject, `Fb::Jwt::Auth::ServiceAccessToken.new(subject: subject).generate`
29
+
30
+ In the case you need to configure the service access token as a client
31
+ ```ruby
32
+ Fb::Jwt::Auth.configure do |config|
33
+ config.issuer = 'fb-editor'
34
+ config.namespace = 'formbuilder-saas-test'
35
+ config.encoded_private_key = 'base64 encoded private key'
36
+ end
37
+ ```
28
38
 
29
39
  ### Using other endpoint versions
30
40
 
@@ -1,18 +1,23 @@
1
1
  require 'fb/jwt/auth/version'
2
2
  require 'openssl'
3
3
  require 'jwt'
4
- require 'active_support/core_ext'
4
+ require 'active_support/all'
5
5
 
6
6
  module Fb
7
7
  module Jwt
8
8
  class Auth
9
- cattr_accessor :service_token_cache_root_url, :service_token_cache_api_version
9
+ cattr_accessor :service_token_cache_root_url,
10
+ :service_token_cache_api_version,
11
+ :encoded_private_key,
12
+ :issuer,
13
+ :namespace
10
14
 
11
15
  def self.configure(&block)
12
16
  yield self
13
17
  end
14
18
 
15
19
  autoload :ServiceTokenClient, 'fb/jwt/auth/service_token_client'
20
+ autoload :ServiceAccessToken, 'fb/jwt/auth/service_access_token'
16
21
 
17
22
  class TokenNotPresentError < StandardError
18
23
  end
@@ -0,0 +1,45 @@
1
+ module Fb
2
+ module Jwt
3
+ class Auth
4
+ class ServiceAccessToken
5
+ attr_reader :encoded_private_key,
6
+ :issuer,
7
+ :subject,
8
+ :namespace
9
+
10
+ def initialize(subject: nil)
11
+ @subject = subject
12
+ @encoded_private_key = Fb::Jwt::Auth.encoded_private_key
13
+ @namespace = Fb::Jwt::Auth.namespace
14
+ @issuer = Fb::Jwt::Auth.issuer
15
+ end
16
+
17
+ def generate
18
+ return '' if encoded_private_key.blank?
19
+
20
+ private_key = OpenSSL::PKey::RSA.new(
21
+ Base64.strict_decode64(encoded_private_key.chomp)
22
+ )
23
+
24
+ JWT.encode(
25
+ token,
26
+ private_key,
27
+ 'RS256'
28
+ )
29
+ end
30
+
31
+ private
32
+
33
+ def token
34
+ payload = {
35
+ iss: issuer,
36
+ iat: Time.current.to_i
37
+ }
38
+ payload[:sub] = subject if subject.present?
39
+ payload[:namespace] = namespace if namespace.present?
40
+ payload
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,7 +1,7 @@
1
1
  module Fb
2
2
  module Jwt
3
3
  class Auth
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb-jwt-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Form builder developers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-04 00:00:00.000000000 Z
11
+ date: 2021-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -73,6 +73,7 @@ files:
73
73
  - bin/setup
74
74
  - fb-jwt-auth.gemspec
75
75
  - lib/fb/jwt/auth.rb
76
+ - lib/fb/jwt/auth/service_access_token.rb
76
77
  - lib/fb/jwt/auth/service_token_client.rb
77
78
  - lib/fb/jwt/auth/version.rb
78
79
  homepage: https://github.com/ministryofjustice/fb-jwt-auth