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 +4 -4
- data/Changelog.md +6 -0
- data/README.md +10 -0
- data/lib/fb/jwt/auth.rb +7 -2
- data/lib/fb/jwt/auth/service_access_token.rb +45 -0
- data/lib/fb/jwt/auth/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45ebbebff675bd2afe201e48c9d3d711ae255619511e00318f6cd39aef8094c0
|
4
|
+
data.tar.gz: e1d51f15d8b8a4a55be59228edce5aa3723b74bd312d0b87f868e81ecd3bcdb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56e7552bcdede5d4ce45200ab5160a790128e80ee0a6f276d0e4d7f9f4515de14db7a9efab79554df31593ee801e9a983d1af413327427b1c88e184a80e88042
|
7
|
+
data.tar.gz: 395d1d6f094db54c9411bc20d6804c94ea56f7a52e60a64e4496f6ed75d2bb5bd52817ada3fbc7058a404fa47db4b48b850df16ccb9a4ae96236b4591a13d2c6
|
data/Changelog.md
CHANGED
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
|
|
data/lib/fb/jwt/auth.rb
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
require 'fb/jwt/auth/version'
|
2
2
|
require 'openssl'
|
3
3
|
require 'jwt'
|
4
|
-
require 'active_support/
|
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,
|
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
|
data/lib/fb/jwt/auth/version.rb
CHANGED
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.
|
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:
|
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
|