minato-rails-auth 0.1.0 → 0.2.0
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 +4 -4
- data/.devcontainer/devcontainer.json +37 -0
- data/.devcontainer/docker-compose.yml +8 -0
- data/README.md +1 -1
- data/lib/minato/rails/auth/jwt/configuration.rb +1 -1
- data/lib/minato/rails/auth/jwt.rb +3 -1
- data/lib/minato/rails/auth/user.rb +49 -0
- data/lib/minato/rails/auth/version.rb +1 -1
- data/lib/object_hash.rb +10 -8
- metadata +5 -3
- data/lib/minato/rails/auth/jwt/user.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8604698708e566c6bafcdfb266913b0e2aacbdabb44451212cfab2af34f2583
|
4
|
+
data.tar.gz: 5a08d876eee74aa03c58dea4893e2dab2d15abe9c4392440a3a6f9ccb2a4ff2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37c6f45719975a70f7fc2ba11b2605d6764d080126281d6cf88d212c575d05f041ed8e41c29ab93045ca9b992711f4c22084795f6ddadabb4b25e4fc21b39f60
|
7
|
+
data.tar.gz: e36d6abdc74a8e3ec50aace97f9840fbf5210080ed97fffc0dde44f6cf7cc1c397ad89cee7b30dbd19117683eb4739cfe8038f360b4249aca437c8345b078dad
|
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"name": "${localWorkspaceFolderBasename}",
|
3
|
+
"dockerComposeFile": [
|
4
|
+
"../compose.yml",
|
5
|
+
"docker-compose.yml"
|
6
|
+
],
|
7
|
+
"service": "minato-rails-auth",
|
8
|
+
"workspaceFolder": "/usr/src/api",
|
9
|
+
"features": {
|
10
|
+
"ghcr.io/devcontainers/features/common-utils:2": {},
|
11
|
+
"ghcr.io/devcontainers-contrib/features/zsh-plugins:0": {
|
12
|
+
"plugins": "zsh-autosuggestions zsh-syntax-highlighting",
|
13
|
+
"omzPlugins": "https://github.com/zsh-users/zsh-autosuggestions https://github.com/zsh-users/zsh-syntax-highlighting"
|
14
|
+
},
|
15
|
+
"ghcr.io/guiyomh/features/vim:0": {},
|
16
|
+
"ghcr.io/devcontainers/features/git:1.1.0": {}
|
17
|
+
},
|
18
|
+
"customizations": {
|
19
|
+
"vscode": {
|
20
|
+
"extensions": [
|
21
|
+
"eamodio.gitlens",
|
22
|
+
"redhat.vscode-yaml",
|
23
|
+
"EditorConfig.EditorConfig",
|
24
|
+
"GitLab.gitlab-workflow",
|
25
|
+
"MS-vsliveshare.vsliveshare"
|
26
|
+
],
|
27
|
+
"settings": {
|
28
|
+
"terminal.integrated.defaultProfile.linux": "zsh",
|
29
|
+
"terminal.integrated.defaultProfile.windows": "zsh",
|
30
|
+
"terminal.integrated.defaultProfile.osx": "zsh"
|
31
|
+
}
|
32
|
+
}
|
33
|
+
},
|
34
|
+
"postCreateCommand": "bundle config --local GITLAB__COM gitlab-ci-token:$GITLAB_AUTH_TOKEN",
|
35
|
+
"postStartCommand": "bundle install",
|
36
|
+
"remoteUser": "ruby"
|
37
|
+
}
|
data/README.md
CHANGED
@@ -104,7 +104,7 @@ To add the JWT authentication system in your Rails application, just follow the
|
|
104
104
|
- This works like the `.machine?` method, but tells you if the client is human.
|
105
105
|
|
106
106
|
- `.session`
|
107
|
-
- This returns a
|
107
|
+
- This returns a object containing the JWT payload, if the client is human.
|
108
108
|
|
109
109
|
- `.machine`
|
110
110
|
- This returns a string with the machine name, when the client is a machine.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative 'user'
|
4
4
|
require_relative 'configuration'
|
5
5
|
require_relative 'jwt/decode'
|
6
6
|
require 'active_support'
|
@@ -14,6 +14,8 @@ module Minato
|
|
14
14
|
module JWT
|
15
15
|
extend ActiveSupport::Concern
|
16
16
|
|
17
|
+
attr_reader :current_user
|
18
|
+
|
17
19
|
private
|
18
20
|
|
19
21
|
def authenticate_request!
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'object_hash'
|
4
|
+
|
5
|
+
module Minato
|
6
|
+
module Rails
|
7
|
+
module Auth
|
8
|
+
class User
|
9
|
+
attr_reader :token_payload
|
10
|
+
|
11
|
+
def initialize(token_payload)
|
12
|
+
@token_payload = ObjectHash.new(token_payload)
|
13
|
+
end
|
14
|
+
|
15
|
+
def human?
|
16
|
+
@human ||= @token_payload.respond_to?(:session)
|
17
|
+
end
|
18
|
+
|
19
|
+
def machine?
|
20
|
+
@machine ||= !human?
|
21
|
+
end
|
22
|
+
|
23
|
+
def identity_id
|
24
|
+
return session.identity.id unless impersonated?
|
25
|
+
|
26
|
+
session.identity.metadata_public.impersonated_identity_id
|
27
|
+
end
|
28
|
+
|
29
|
+
def impersonator_identity_id
|
30
|
+
session.identity.id
|
31
|
+
end
|
32
|
+
|
33
|
+
def subject
|
34
|
+
@token_payload.sub
|
35
|
+
end
|
36
|
+
|
37
|
+
def impersonated?
|
38
|
+
!session.identity.metadata_public&.impersonated_identity_id.nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def session
|
44
|
+
@token_payload.session
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/object_hash.rb
CHANGED
@@ -6,12 +6,14 @@ class ObjectHash
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def method_missing(name)
|
9
|
-
find_hash_value(name)
|
9
|
+
value = find_hash_value(name)
|
10
|
+
define_singleton_method(name) { value }
|
11
|
+
value
|
10
12
|
end
|
11
13
|
|
12
|
-
def respond_to_missing?(name,
|
13
|
-
return true if @hash.
|
14
|
-
return true if @hash.
|
14
|
+
def respond_to_missing?(name, _include_private = false)
|
15
|
+
return true if @hash.key?(name.to_sym)
|
16
|
+
return true if @hash.key?(name.to_s)
|
15
17
|
|
16
18
|
super
|
17
19
|
end
|
@@ -19,12 +21,12 @@ class ObjectHash
|
|
19
21
|
private
|
20
22
|
|
21
23
|
def find_hash_value(name)
|
22
|
-
value = @hash
|
23
|
-
return ObjectHash.new(value) if value.
|
24
|
+
value = @hash.fetch(name.to_sym, nil) || @hash.fetch(name.to_s, nil)
|
25
|
+
return ObjectHash.new(value) if value.is_a?(Hash)
|
24
26
|
|
25
|
-
if value.
|
27
|
+
if value.is_a?(Array)
|
26
28
|
return value.map do |item|
|
27
|
-
next ObjectHash.new(item) if item.
|
29
|
+
next ObjectHash.new(item) if item.is_a?(Hash)
|
28
30
|
|
29
31
|
item
|
30
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minato-rails-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ferreri
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -45,6 +45,8 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- ".devcontainer/devcontainer.json"
|
49
|
+
- ".devcontainer/docker-compose.yml"
|
48
50
|
- ".rspec"
|
49
51
|
- ".rubocop.yml"
|
50
52
|
- README.md
|
@@ -56,8 +58,8 @@ files:
|
|
56
58
|
- lib/minato/rails/auth/jwt/configuration.rb
|
57
59
|
- lib/minato/rails/auth/jwt/decode.rb
|
58
60
|
- lib/minato/rails/auth/jwt/spec/contexts.rb
|
59
|
-
- lib/minato/rails/auth/jwt/user.rb
|
60
61
|
- lib/minato/rails/auth/spec.rb
|
62
|
+
- lib/minato/rails/auth/user.rb
|
61
63
|
- lib/minato/rails/auth/version.rb
|
62
64
|
- lib/object_hash.rb
|
63
65
|
- minato-rails-auth.gemspec
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'object_hash'
|
4
|
-
|
5
|
-
module Minato
|
6
|
-
module Rails
|
7
|
-
module Auth
|
8
|
-
module JWT
|
9
|
-
class User
|
10
|
-
attr_reader :token_payload
|
11
|
-
|
12
|
-
def initialize(token_payload)
|
13
|
-
@token_payload = ObjectHash.new(token_payload)
|
14
|
-
end
|
15
|
-
|
16
|
-
def human?
|
17
|
-
@human ||= @token_payload.respond_to?(:session)
|
18
|
-
end
|
19
|
-
|
20
|
-
def machine?
|
21
|
-
@machine ||= !human?
|
22
|
-
end
|
23
|
-
|
24
|
-
def session
|
25
|
-
@token_payload.session
|
26
|
-
end
|
27
|
-
|
28
|
-
def subject
|
29
|
-
@token_payload.sub
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|