matic-jwt 0.0.0 → 0.2.3
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 +5 -5
- data/Gemfile.lock +15 -30
- data/README.md +4 -42
- data/lib/matic-jwt/authenticator.rb +13 -14
- data/lib/matic-jwt/generator.rb +3 -13
- data/lib/matic-jwt/version.rb +1 -1
- data/lib/matic-jwt.rb +1 -9
- data/matic-jwt.gemspec +1 -1
- metadata +9 -13
- data/.github/workflows/check.yml +0 -126
- data/.github/workflows/release.yml +0 -48
- data/lib/matic-jwt/grape/helper.rb +0 -9
- data/lib/matic-jwt/grape/middleware/auth.rb +0 -53
- data/lib/matic-jwt/grape/middleware/request.rb +0 -32
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: '0955fc9d431b0fbe6d6f537dbd3c04426bc077ab'
|
|
4
|
+
data.tar.gz: 33cb5c5c5646a9873f097ae81940e9eecab7ccfd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4470400ba831c24979bb12cbbd4c3ba06dcf84298042b16e8b5b50b263e880a23b92dc4cbfbec2e05ad269dc6823c03f58978f3e886c78a576662f6550e9e271
|
|
7
|
+
data.tar.gz: c4e46a45d284b9c35cac86bdbf5c3a5e375096d2e430c26a816f04d04050c7df180e466afb12e6f05f8dc98b6da7cb29419cbbe72e25c7fe3d9804c1dfe5f411
|
data/Gemfile.lock
CHANGED
|
@@ -1,40 +1,25 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
matic-jwt (0.
|
|
4
|
+
matic-jwt (0.2.3)
|
|
5
5
|
activesupport
|
|
6
6
|
jwt
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
activesupport (
|
|
12
|
-
base64
|
|
13
|
-
benchmark (>= 0.3)
|
|
14
|
-
bigdecimal
|
|
11
|
+
activesupport (5.1.4)
|
|
15
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
minitest (>= 5.1)
|
|
21
|
-
mutex_m
|
|
22
|
-
securerandom (>= 0.3)
|
|
23
|
-
tzinfo (~> 2.0)
|
|
24
|
-
base64 (0.3.0)
|
|
25
|
-
benchmark (0.4.1)
|
|
26
|
-
bigdecimal (3.2.0)
|
|
27
|
-
concurrent-ruby (1.3.5)
|
|
28
|
-
connection_pool (2.5.3)
|
|
13
|
+
i18n (~> 0.7)
|
|
14
|
+
minitest (~> 5.1)
|
|
15
|
+
tzinfo (~> 1.1)
|
|
16
|
+
concurrent-ruby (1.0.5)
|
|
29
17
|
diff-lcs (1.3)
|
|
30
|
-
|
|
31
|
-
i18n (1.14.7)
|
|
18
|
+
i18n (0.9.1)
|
|
32
19
|
concurrent-ruby (~> 1.0)
|
|
33
|
-
jwt (2.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
mutex_m (0.3.0)
|
|
37
|
-
rake (13.0.1)
|
|
20
|
+
jwt (2.1.0)
|
|
21
|
+
minitest (5.10.3)
|
|
22
|
+
rake (10.5.0)
|
|
38
23
|
rspec (3.7.0)
|
|
39
24
|
rspec-core (~> 3.7.0)
|
|
40
25
|
rspec-expectations (~> 3.7.0)
|
|
@@ -48,9 +33,9 @@ GEM
|
|
|
48
33
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
49
34
|
rspec-support (~> 3.7.0)
|
|
50
35
|
rspec-support (3.7.0)
|
|
51
|
-
|
|
52
|
-
tzinfo (2.
|
|
53
|
-
|
|
36
|
+
thread_safe (0.3.6)
|
|
37
|
+
tzinfo (1.2.4)
|
|
38
|
+
thread_safe (~> 0.1)
|
|
54
39
|
|
|
55
40
|
PLATFORMS
|
|
56
41
|
ruby
|
|
@@ -58,8 +43,8 @@ PLATFORMS
|
|
|
58
43
|
DEPENDENCIES
|
|
59
44
|
bundler (~> 1.16)
|
|
60
45
|
matic-jwt!
|
|
61
|
-
rake (~>
|
|
46
|
+
rake (~> 10.0)
|
|
62
47
|
rspec (~> 3.0)
|
|
63
48
|
|
|
64
49
|
BUNDLED WITH
|
|
65
|
-
|
|
50
|
+
1.16.0
|
data/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Matic::Jwt
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/matic/jwt`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
@@ -20,47 +22,7 @@ Or install it yourself as:
|
|
|
20
22
|
|
|
21
23
|
## Usage
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Use `MaticJWT::Generator` to create JWT tokens or headers:
|
|
26
|
-
```ruby
|
|
27
|
-
generator = MaticJWT::Generator.new
|
|
28
|
-
token = generator.token_for('my_client', 'my_super_secret', additional_payload: 'test')
|
|
29
|
-
header = generator.authentication_header_for('my_client', 'my_super_secret', user_id: 'test@localhost.com')
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### With Grape
|
|
33
|
-
Register `jwt_auth` strategy
|
|
34
|
-
```ruby
|
|
35
|
-
Grape::Middleware::Auth::Strategies.add(
|
|
36
|
-
:jwt_auth,
|
|
37
|
-
MaticJWT::Grape::Middleware::Auth,
|
|
38
|
-
->(options) { [options] }
|
|
39
|
-
)
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Use ```:jwt_auth``` strategy and define lambda to obtain secret for by client name.
|
|
43
|
-
```ruby
|
|
44
|
-
auth :jwt_auth,
|
|
45
|
-
secret: -> (client_name) { ::ApiClient.find_by!(name: client_name).secret }
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
If you need to get any data from authentication payload use ::MaticJWT::Grape::Helper.
|
|
49
|
-
```ruby
|
|
50
|
-
module ApiHelper
|
|
51
|
-
include ::MaticJWT::Grape::Helper
|
|
52
|
-
|
|
53
|
-
def current_client
|
|
54
|
-
@current_client ||= ::ApiClient.find_by!(name: client_name)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
private
|
|
58
|
-
|
|
59
|
-
def client_name
|
|
60
|
-
auth_payload['client_name']
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
```
|
|
25
|
+
TODO: Write usage instructions here
|
|
64
26
|
|
|
65
27
|
## Development
|
|
66
28
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
module MaticJWT
|
|
2
2
|
class Authenticator
|
|
3
|
-
def initialize(
|
|
4
|
-
@
|
|
5
|
-
@token = extract_token(header)
|
|
3
|
+
def initialize(request)
|
|
4
|
+
@token = extract_token(request)
|
|
6
5
|
end
|
|
7
6
|
|
|
8
7
|
def client_name
|
|
@@ -10,23 +9,23 @@ module MaticJWT
|
|
|
10
9
|
end
|
|
11
10
|
|
|
12
11
|
def authenticate_with_secret!(secret)
|
|
13
|
-
JWT.decode
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def payload
|
|
17
|
-
JWT.decode(@token, nil, false)
|
|
12
|
+
JWT.decode @token, secret, true, algorithm: ALGORITHM
|
|
18
13
|
end
|
|
19
14
|
|
|
20
15
|
private
|
|
21
16
|
|
|
22
|
-
def extract_token(
|
|
23
|
-
|
|
24
|
-
validate_header_presence!(
|
|
25
|
-
|
|
17
|
+
def extract_token(request)
|
|
18
|
+
header = request.headers['Authorization']
|
|
19
|
+
validate_header_presence!(header)
|
|
20
|
+
header.slice(8..-1)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def payload
|
|
24
|
+
JWT.decode(@token, nil, false)
|
|
26
25
|
end
|
|
27
26
|
|
|
28
|
-
def validate_header_presence!(
|
|
29
|
-
raise(JWT::DecodeError, 'Authorization
|
|
27
|
+
def validate_header_presence!(header)
|
|
28
|
+
raise(JWT::DecodeError, 'Authorization header is missing') if header.nil?
|
|
30
29
|
end
|
|
31
30
|
end
|
|
32
31
|
end
|
data/lib/matic-jwt/generator.rb
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
module MaticJWT
|
|
2
2
|
class Generator
|
|
3
|
-
def
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def token_for(client_name, secret, payload = {})
|
|
9
|
-
jwt_payload = payload.merge(client_name: client_name, exp: @expiration.since.to_i)
|
|
10
|
-
JWT.encode(jwt_payload, secret, ALGORITHM)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def authentication_header_for(client_name, secret, payload = {})
|
|
14
|
-
token = token_for(client_name, secret, payload)
|
|
15
|
-
"#{@scheme} #{token}"
|
|
3
|
+
def token_for(client_name, secret)
|
|
4
|
+
payload = {client_name: client_name, exp: EXPIRATION.since.to_i}
|
|
5
|
+
JWT.encode(payload, secret, ALGORITHM)
|
|
16
6
|
end
|
|
17
7
|
end
|
|
18
8
|
end
|
data/lib/matic-jwt/version.rb
CHANGED
data/lib/matic-jwt.rb
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
require 'active_support'
|
|
2
|
-
require 'active_support/core_ext'
|
|
1
|
+
require 'active_support/time'
|
|
3
2
|
require 'jwt'
|
|
4
3
|
|
|
5
4
|
require 'matic-jwt/authenticator'
|
|
6
5
|
require 'matic-jwt/generator'
|
|
7
6
|
require 'matic-jwt/version'
|
|
8
7
|
|
|
9
|
-
if Gem.loaded_specs.has_key?('grape')
|
|
10
|
-
require 'matic-jwt/grape/helper'
|
|
11
|
-
require 'matic-jwt/grape/middleware/request'
|
|
12
|
-
require 'matic-jwt/grape/middleware/auth'
|
|
13
|
-
end
|
|
14
|
-
|
|
15
8
|
module MaticJWT
|
|
16
9
|
ALGORITHM = 'HS256'.freeze
|
|
17
10
|
EXPIRATION = 1.minute
|
|
18
|
-
SCHEME = 'Bearer'.freeze
|
|
19
11
|
end
|
data/matic-jwt.gemspec
CHANGED
|
@@ -32,6 +32,6 @@ Gem::Specification.new do |spec|
|
|
|
32
32
|
spec.add_dependency 'activesupport'
|
|
33
33
|
|
|
34
34
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
|
35
|
-
spec.add_development_dependency 'rake', '~>
|
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
36
36
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
37
37
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: matic-jwt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yurii Danyliak
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-11-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jwt
|
|
@@ -58,14 +58,14 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
61
|
+
version: '10.0'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
68
|
+
version: '10.0'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: rspec
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -88,8 +88,6 @@ executables: []
|
|
|
88
88
|
extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
|
90
90
|
files:
|
|
91
|
-
- ".github/workflows/check.yml"
|
|
92
|
-
- ".github/workflows/release.yml"
|
|
93
91
|
- ".gitignore"
|
|
94
92
|
- Gemfile
|
|
95
93
|
- Gemfile.lock
|
|
@@ -101,16 +99,13 @@ files:
|
|
|
101
99
|
- lib/matic-jwt.rb
|
|
102
100
|
- lib/matic-jwt/authenticator.rb
|
|
103
101
|
- lib/matic-jwt/generator.rb
|
|
104
|
-
- lib/matic-jwt/grape/helper.rb
|
|
105
|
-
- lib/matic-jwt/grape/middleware/auth.rb
|
|
106
|
-
- lib/matic-jwt/grape/middleware/request.rb
|
|
107
102
|
- lib/matic-jwt/version.rb
|
|
108
103
|
- matic-jwt.gemspec
|
|
109
104
|
homepage: https://github.com/matic-insurance/matic-jwt-wrapper
|
|
110
105
|
licenses: []
|
|
111
106
|
metadata:
|
|
112
107
|
allowed_push_host: https://rubygems.org
|
|
113
|
-
post_install_message:
|
|
108
|
+
post_install_message:
|
|
114
109
|
rdoc_options: []
|
|
115
110
|
require_paths:
|
|
116
111
|
- lib
|
|
@@ -125,8 +120,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
125
120
|
- !ruby/object:Gem::Version
|
|
126
121
|
version: '0'
|
|
127
122
|
requirements: []
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
rubyforge_project:
|
|
124
|
+
rubygems_version: 2.5.2
|
|
125
|
+
signing_key:
|
|
130
126
|
specification_version: 4
|
|
131
127
|
summary: Matic's JWT implementation
|
|
132
128
|
test_files: []
|
data/.github/workflows/check.yml
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
name: Check
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches: [ "master" ]
|
|
5
|
-
pull_request:
|
|
6
|
-
branches: [ "master" ]
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
check:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
strategy:
|
|
12
|
-
matrix:
|
|
13
|
-
ruby: [ '3.1', '3.4' ]
|
|
14
|
-
steps:
|
|
15
|
-
- name: Checkout
|
|
16
|
-
uses: actions/checkout@v4
|
|
17
|
-
|
|
18
|
-
- name: Set up Ruby
|
|
19
|
-
uses: ruby/setup-ruby@v1
|
|
20
|
-
with:
|
|
21
|
-
ruby-version: ${{ matrix.ruby }}
|
|
22
|
-
bundler-cache: true
|
|
23
|
-
|
|
24
|
-
- name: Run specs
|
|
25
|
-
env:
|
|
26
|
-
COVERAGE: true
|
|
27
|
-
run: bundle exec rspec
|
|
28
|
-
|
|
29
|
-
# release:
|
|
30
|
-
# runs-on: ubuntu-latest
|
|
31
|
-
# steps:
|
|
32
|
-
# - name: Checkout
|
|
33
|
-
# uses: actions/checkout@v4
|
|
34
|
-
# - name: Set up Ruby
|
|
35
|
-
# uses: ruby/setup-ruby@v1
|
|
36
|
-
# with:
|
|
37
|
-
# ruby-version: 3.1
|
|
38
|
-
# bundler-cache: true
|
|
39
|
-
# # - name: Set up credentials
|
|
40
|
-
# # run: |
|
|
41
|
-
# # mkdir -p $HOME/.gem
|
|
42
|
-
# # touch $HOME/.gem/credentials
|
|
43
|
-
# # chmod 0600 $HOME/.gem/credentials
|
|
44
|
-
# # printf -- "---\n:rubygems_api_key: ${{secrets.RUBYGEMS_AUTH_TOKEN}}\n" > $HOME/.gem/credentials
|
|
45
|
-
|
|
46
|
-
# - name: Get version
|
|
47
|
-
# run: echo "${GITHUB_REF/refs\/tags\//}" > release.tag
|
|
48
|
-
# - name: Set version
|
|
49
|
-
# run: sed -i "s/0.0.0/$(<release.tag)/g" $(find . -name "version.rb")
|
|
50
|
-
|
|
51
|
-
# - name: Build gem
|
|
52
|
-
# run: gem build *.gemspec
|
|
53
|
-
# # - name: Push gem
|
|
54
|
-
# # run: gem push *.gem
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
# # version: 2.1
|
|
58
|
-
|
|
59
|
-
# # orbs:
|
|
60
|
-
# # ci: matic/orb-common@0.3
|
|
61
|
-
# # ruby: circleci/ruby@2.5.3
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
# # release:
|
|
65
|
-
# # parameters:
|
|
66
|
-
# # tag:
|
|
67
|
-
# # type: string
|
|
68
|
-
# # default: "default-tag"
|
|
69
|
-
# # docker:
|
|
70
|
-
# # - image: cimg/ruby:3.1.4
|
|
71
|
-
# # environment:
|
|
72
|
-
# # RELEASE_TAG: << parameters.tag >>
|
|
73
|
-
# # steps:
|
|
74
|
-
# # - run:
|
|
75
|
-
# # name: Checkout code via HTTPS
|
|
76
|
-
# # command: |
|
|
77
|
-
# # git clone https://${GITHUB_TOKEN}@github.com/matic-insurance/matic-jwt-wrapper.git .
|
|
78
|
-
# # git checkout ${RELEASE_TAG}
|
|
79
|
-
# # - ruby/install-deps
|
|
80
|
-
# # - run:
|
|
81
|
-
# # name: Set up credentials
|
|
82
|
-
# # command: |
|
|
83
|
-
# # mkdir -p $HOME/.gem
|
|
84
|
-
# # echo ":rubygems_api_key: ${RUBYGEMS_API_KEY}" >> ~/.gem/credentials
|
|
85
|
-
# # chmod 0600 $HOME/.gem/credentials
|
|
86
|
-
# # - run:
|
|
87
|
-
# # name: Debug credentials
|
|
88
|
-
# # command: |
|
|
89
|
-
# # echo "API key length: ${#RUBYGEMS_API_KEY}"
|
|
90
|
-
# # echo "Credentials file exists: $(ls -la $HOME/.gem/credentials || echo 'NOT FOUND')"
|
|
91
|
-
# # echo "Testing API key with current gem..."
|
|
92
|
-
# # curl -f -H "Authorization: $RUBYGEMS_API_KEY" https://rubygems.org/api/v1/gems/matic-jwt-wrapper.json && echo "API key can access gem" || echo "API key cannot access gem"
|
|
93
|
-
# # - run:
|
|
94
|
-
# # name: Set version
|
|
95
|
-
# # command: sed -i "s/[[:digit:]].[[:digit:]].[[:digit:]]/${RELEASE_TAG}/g" $(find . -name "version.rb")
|
|
96
|
-
# # - run:
|
|
97
|
-
# # name: Build gem
|
|
98
|
-
# # command: gem build *.gemspec
|
|
99
|
-
# # - run:
|
|
100
|
-
# # name: Push gem
|
|
101
|
-
# # command: gem push *.gem
|
|
102
|
-
|
|
103
|
-
# # workflows:
|
|
104
|
-
|
|
105
|
-
# # matic-jwt-wrapper.build-pull-request:
|
|
106
|
-
# # when:
|
|
107
|
-
# # not:
|
|
108
|
-
# # equal: [ master, << pipeline.git.branch >> ]
|
|
109
|
-
# # jobs:
|
|
110
|
-
|
|
111
|
-
# # - release:
|
|
112
|
-
# # tag: "1.3.0"
|
|
113
|
-
# # context: gem-publishing
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
# # matic-jwt-wrapper.release:
|
|
117
|
-
# # jobs:
|
|
118
|
-
|
|
119
|
-
# # - release:
|
|
120
|
-
# # tag: << pipeline.git.tag >>
|
|
121
|
-
# # context: gem-publishing
|
|
122
|
-
# # filters:
|
|
123
|
-
# # branches:
|
|
124
|
-
# # ignore: /.*/
|
|
125
|
-
# # tags:
|
|
126
|
-
# # only: /\d\.\d\.\d/ # It should be [digin dot digit dot digit] format
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
name: Release
|
|
2
|
-
on:
|
|
3
|
-
|
|
4
|
-
# push:
|
|
5
|
-
# tags:
|
|
6
|
-
# - '*.*.*'
|
|
7
|
-
push:
|
|
8
|
-
branches: [ "master" ]
|
|
9
|
-
pull_request:
|
|
10
|
-
branches: [ "master" ]
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
release:
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
permissions:
|
|
16
|
-
id-token: write
|
|
17
|
-
contents: read
|
|
18
|
-
steps:
|
|
19
|
-
- name: Checkout
|
|
20
|
-
uses: actions/checkout@v4
|
|
21
|
-
- name: Set up Ruby
|
|
22
|
-
uses: ruby/setup-ruby@v1
|
|
23
|
-
with:
|
|
24
|
-
ruby-version: 3.1
|
|
25
|
-
bundler-cache: true
|
|
26
|
-
- name: Set version
|
|
27
|
-
run: |
|
|
28
|
-
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
29
|
-
VERSION=${GITHUB_REF#refs/tags/}
|
|
30
|
-
echo "Setting version to: $VERSION"
|
|
31
|
-
find . -name "version.rb" -exec sed -i "s|VERSION = ['\"]0\.0\.0['\"]|VERSION = \"$VERSION\"|g" {} \;
|
|
32
|
-
else
|
|
33
|
-
echo "❌ ERROR: This workflow should only run on tag pushes, though GITHUB_REF is $GITHUB_REF"
|
|
34
|
-
VERSION="1.3.0"
|
|
35
|
-
# exit 1
|
|
36
|
-
fi
|
|
37
|
-
- name: Configure RubyGems Credentials
|
|
38
|
-
uses: rubygems/configure-rubygems-credentials@main
|
|
39
|
-
# - name: Set up credentials
|
|
40
|
-
# run: |
|
|
41
|
-
# mkdir -p $HOME/.gem
|
|
42
|
-
# touch $HOME/.gem/credentials
|
|
43
|
-
# chmod 0600 $HOME/.gem/credentials
|
|
44
|
-
# printf -- "---\n:rubygems_api_key: ${{secrets.RUBYGEMS_AUTH_TOKEN}}\n" > $HOME/.gem/credentials
|
|
45
|
-
- name: Build gem
|
|
46
|
-
run: gem build *.gemspec
|
|
47
|
-
- name: Push gem
|
|
48
|
-
run: gem push *.gem
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
module MaticJWT
|
|
2
|
-
module Grape
|
|
3
|
-
module Middleware
|
|
4
|
-
class Auth
|
|
5
|
-
def initialize(app, options)
|
|
6
|
-
@app = app
|
|
7
|
-
@secret_reader = options[:secret]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def call(env)
|
|
11
|
-
@env = env
|
|
12
|
-
|
|
13
|
-
validate_request
|
|
14
|
-
decode_payload
|
|
15
|
-
authenticate!
|
|
16
|
-
continue!
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
def validate_request
|
|
22
|
-
raise JWT::VerificationError, 'Authorization token is invalid' unless request.valid?
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def decode_payload
|
|
26
|
-
@env['auth_payload'] = jwt_authenticator.payload&.first
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def authenticate!
|
|
30
|
-
jwt_authenticator.authenticate_with_secret!(secret)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def continue!
|
|
34
|
-
@app.call(@env)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def jwt_authenticator
|
|
38
|
-
::MaticJWT::Authenticator.new(request.auth_token)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def secret
|
|
42
|
-
@secret_reader.call(jwt_authenticator.client_name)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def request
|
|
46
|
-
@request ||= ::MaticJWT::Grape::Middleware::Request.new(@env)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
Grape::Middleware::Auth::Strategies.add(:jwt_auth, ::MaticJWT::Grape::Middleware::Auth, ->(options) { [options] })
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
module MaticJWT
|
|
2
|
-
module Grape
|
|
3
|
-
module Middleware
|
|
4
|
-
class Request
|
|
5
|
-
AUTHORIZATION_KEYS = %w[
|
|
6
|
-
Authorization
|
|
7
|
-
HTTP_AUTHORIZATION
|
|
8
|
-
X-HTTP_AUTHORIZATION
|
|
9
|
-
X_HTTP_AUTHORIZATION
|
|
10
|
-
].freeze
|
|
11
|
-
|
|
12
|
-
def initialize(env)
|
|
13
|
-
@env = env
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def valid?
|
|
17
|
-
!@env[auth_key].nil?
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def auth_token
|
|
21
|
-
@env[auth_key]
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
def auth_key
|
|
27
|
-
@authorization_key ||= AUTHORIZATION_KEYS.detect { |key| @env.key?(key) }
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|