jay_doubleu_tee 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +49 -4
- data/lib/jay_doubleu_tee/version.rb +1 -1
- data/lib/jay_doubleu_tee.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 466bf244fedd2cc739d50c571486552fd5ba396b4dabef84f67cd048ae6b6907
|
4
|
+
data.tar.gz: 9ff43ce6564a8aa048c30309b0a9c36bf1b41a9635046ae72a21ae668161fe47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58971ff4a53581205acdfcb211131e3ff2daf9a09ddb4fa5da1bcfe828eb3a34baffcc9fdeee23cffe403e8ec0b9de8db074b33f6999f1943531c39bef1b7ea1
|
7
|
+
data.tar.gz: 3ca090115afdb48737b4e6352d377b6b268be6fa3b0f86f95a70540b046b3acedf83fc66417b8716b2808d3e24155a1c52b90150c94883ed12eb9b61e8f5dfc0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -24,6 +24,22 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
+
`jay_double_uti` uses RS256 algorithm by default, so youl'll need a private/public key pair and the access token for testing it out.
|
28
|
+
|
29
|
+
In your console run
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'jwt'
|
33
|
+
payload = {
|
34
|
+
data: { user_id: "de804507-5d03-4493-a038-d62f499b8a96" }, scopes: ""
|
35
|
+
}
|
36
|
+
private_key = OpenSSL::PKey::RSA.generate 2048
|
37
|
+
secret = private_key.public_key.to_s
|
38
|
+
token = JWT.encode payload, private_key, 'RS256'
|
39
|
+
```
|
40
|
+
|
41
|
+
Then save the `ENV` variable `JAY_DOUBLEU_TEE_PUBLIC_KEY` by setting the as a value your secret.
|
42
|
+
|
27
43
|
### Plain ruby Rack application
|
28
44
|
|
29
45
|
```ruby
|
@@ -35,7 +51,7 @@ class App
|
|
35
51
|
def call(env)
|
36
52
|
status, body =
|
37
53
|
if auth.success?
|
38
|
-
[200, ["Hello, World
|
54
|
+
[200, [{ message: "Hello, World!", auth: auth.value! }]]
|
39
55
|
else
|
40
56
|
[401, [{ error: auth.failure }.to_json]]
|
41
57
|
end
|
@@ -55,6 +71,27 @@ use JayDoubleuTee::Authentication
|
|
55
71
|
run App.new
|
56
72
|
```
|
57
73
|
|
74
|
+
```shell
|
75
|
+
curl --location --request GET 'http://localhost:9292' \
|
76
|
+
--header 'Authorization: Bearer <<YOUR_TOKEN>>'
|
77
|
+
|
78
|
+
# => 200:
|
79
|
+
# {
|
80
|
+
# message: 'Hello, World!,
|
81
|
+
# auth: {
|
82
|
+
# data: { user_id: "de804507-5d03-4493-a038-d62f499b8a96" },
|
83
|
+
# scopes: ""
|
84
|
+
# }
|
85
|
+
# }
|
86
|
+
```
|
87
|
+
|
88
|
+
```shell
|
89
|
+
curl --location --request GET 'http://localhost:9292' \
|
90
|
+
--header 'Authorization: Bearer invalid'
|
91
|
+
|
92
|
+
# => 401: { error: Unauthorized. Token invalid }
|
93
|
+
```
|
94
|
+
|
58
95
|
### Hanami 2.0
|
59
96
|
|
60
97
|
```ruby
|
@@ -75,7 +112,7 @@ use JayDoubleuTee::Authentication
|
|
75
112
|
|
76
113
|
#### Supported algorithms
|
77
114
|
|
78
|
-
JayDoubleuTee
|
115
|
+
JayDoubleuTee users RS256 encryption algoritym by default, but you can completely disable the token signature validation by setting up algorithm to 'none'. Check out the Configuration section.
|
79
116
|
|
80
117
|
Below are listed all supported algoritms at the moment.
|
81
118
|
|
@@ -87,7 +124,7 @@ For more info about each of them refer to [jwt documentation](https://github.com
|
|
87
124
|
|
88
125
|
### Configuration
|
89
126
|
|
90
|
-
To set encryption algorithm, you can configure
|
127
|
+
To set encryption algorithm, you can configure several fields
|
91
128
|
|
92
129
|
```ruby
|
93
130
|
JayDoubleuTee.configure do |config|
|
@@ -104,11 +141,19 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
104
141
|
|
105
142
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
106
143
|
|
144
|
+
### Resources
|
145
|
+
|
146
|
+
It's built on top of several gems to ensure the best user experience.
|
147
|
+
|
148
|
+
- [JWT](https://github.com/jwt/ruby-jwt#algorithms-and-usage)
|
149
|
+
- [dry-effects](https://dry-rb.org/gems/dry-effects). Here is the [video tutorial for dry-effects](https://hanamimastery.com/episodes/11-effective-ruby-programming-with-dry-effects)
|
150
|
+
- [dry-monads](https://dry-rb.org/gems/dry-monads). Here is a [video tutorial for dry-monads](https://hanamimastery.com/episodes/7-untangle-your-app-with-dry-monads)
|
151
|
+
- [dry-configurable](https://dry-rb.org/gems/dry-configurable). Here is the [video tutorial for dry-configurable](https://hanamimastery.com/episodes/5-configure-anything-with-dry-configurable)
|
152
|
+
|
107
153
|
## Contributing
|
108
154
|
|
109
155
|
Bug reports and pull requests are welcome on GitHub at https://github.com/hanamimastery/jay_doubleu_tee. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hanamimastery/jay_doubleu_tee/blob/master/CODE_OF_CONDUCT.md).
|
110
156
|
|
111
|
-
|
112
157
|
## License
|
113
158
|
|
114
159
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/jay_doubleu_tee.rb
CHANGED
@@ -14,10 +14,10 @@ module JayDoubleuTee
|
|
14
14
|
|
15
15
|
extend Dry::Configurable
|
16
16
|
|
17
|
-
setting :algorithm, default: '
|
17
|
+
setting :algorithm, default: 'RS256' do |value|
|
18
18
|
raise ConfigurationError, "Unsupported algorithm." unless ALGORITHMS.include?(value)
|
19
19
|
value
|
20
20
|
end
|
21
21
|
|
22
|
-
setting :secret, default:
|
22
|
+
setting :secret, default: ENV['JAY_DOUBLEU_TEE_PUBLIC_KEY']
|
23
23
|
end
|