gr1d99_auth 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -1
- data/gr1d99_auth-0.1.0.gem +0 -0
- data/lib/gr1d99_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: 8f6da760779a1c0c0805df4f978ceed97504dd0c3c48924be8f4979843fba109
|
4
|
+
data.tar.gz: 6bf45d76781f8e2c6abea48f6cf0c00254057ca2dda91dda2c1b31d182021b9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 261b67b6bd0a56190c35f4c2cc1843b17d0c03871ba26ef10b3e67154a6f1606153a8e77ff57d9b1c0a23d10edaf129831e2475dfcbeeda1244cb75fe6081c73
|
7
|
+
data.tar.gz: 2ed232416cfe8a598cab8df8ef2318f9677cfe3c000ff8ffc0b48ae63a1f0d3ee2f339e673ba2bb7e19a4609325e180e3d6689f8846459edd640dd87fe32a13f
|
data/README.md
CHANGED
@@ -22,7 +22,46 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
### Rails
|
26
|
+
1. Add `gem 'gr1d99_auth'` to your gemfile
|
27
|
+
2. Create a file named `gr1d99_auth.rb` in **config/initializers** directory and add required configurations.
|
28
|
+
|
29
|
+
It is worth noting that `gr1d99_auth` gem offers minimal configurations to enable the gem to work correctly.
|
30
|
+
|
31
|
+
These configurations are:
|
32
|
+
1. **jwt_key** - this is just a random string that will be used to encode/decode jwt
|
33
|
+
2. **jwt_verify** - value can either be **true** or **false**, this specifies whether the jwt should be verified during decoding.
|
34
|
+
3. **jwt_algorithm** - specify the algorithm that should be used, currently the tested algorithms and verified that they work correctly is `HS512` and `HS256`, you are highly recommended to use any of them.
|
35
|
+
4. **jwt_exp** - specify the time in seconds that the token should be valid
|
36
|
+
5. **time_zone** - this ensures that the `jwt_exp` is set appropriately.
|
37
|
+
|
38
|
+
example:
|
39
|
+
in **config/initializers/gr1d99_auth.rb** you would typically have this setup.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Gr1d99Auth.configure do |config|
|
43
|
+
config.jwt_key = "my-jwt-key"
|
44
|
+
config.jwt_verify = true
|
45
|
+
config.jwt_algorithm = 'HS512'
|
46
|
+
config.jwt_exp = 3600
|
47
|
+
config.time_zone = "Africa/Nairobi"
|
48
|
+
end
|
49
|
+
```
|
50
|
+
3. In your controller, typically `authentication_controller.rb`, you would encode your payload by
|
51
|
+
```ruby
|
52
|
+
payload = { id: user.id, email: user.email, roles: user.roles.pluck(:name) }
|
53
|
+
Gr1d99Auth::JWT.encode(payload)
|
54
|
+
```
|
55
|
+
4. To decode token
|
56
|
+
```ruby
|
57
|
+
token = response.headers["HTTP_X_ACCESS_TOKEN"]
|
58
|
+
Gr1d99Auth::JWT.decode(token)
|
59
|
+
```
|
60
|
+
|
61
|
+
5. You should also handle errors raised during decoding, these errors are.
|
62
|
+
1. `JWT::DecodeError`
|
63
|
+
2. `JWT::VerificationError`
|
64
|
+
3. `JWT::IncorrectAlgorithm`
|
26
65
|
|
27
66
|
## Development
|
28
67
|
|
Binary file
|
data/lib/gr1d99_auth/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gr1d99_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gideon Kimutai
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- Rakefile
|
99
99
|
- bin/console
|
100
100
|
- bin/setup
|
101
|
+
- gr1d99_auth-0.1.0.gem
|
101
102
|
- gr1d99_auth.gemspec
|
102
103
|
- lib/gr1d99_auth.rb
|
103
104
|
- lib/gr1d99_auth/configuration.rb
|