ruby_magic_link 1.0.0 → 1.0.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 +3 -1
- data/lib/ruby_magic_link/ruby_magic_link.rb +1 -1
- data/lib/ruby_magic_link/tasks.rb +1 -1
- data/lib/ruby_magic_link/token.rb +4 -30
- data/lib/ruby_magic_link/token_object.rb +33 -0
- data/lib/ruby_magic_link/version.rb +1 -1
- data/lib/ruby_magic_link.rb +2 -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: 265ece5de19cf999679f6006cc8aa2ac2df56284c55e50acc44825d0ffa013fc
|
4
|
+
data.tar.gz: bf4848c3854c3fda2fa7858ddc79b7fdb39e36896548a580bc6fa51774d16160
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95c41caf541fa90039f2231b994723d4d48ddba1aab9eb26bb4b2f09e0502997cf710d3e777fe89d423f5f572b3c66809c93604a0c66acfdb9bce2b81f91d137
|
7
|
+
data.tar.gz: c4eaa959ba5d81dda9db387f53131924f7089c00c58e11b7e402f23d5860bb8c8ad41460552dd393192d3f459264ec16271fb45fd74cc033c1ae0275131ee9b4
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
![CI](https://github.com/igorkorepanov/ruby_magic_link/actions/workflows/main.yml/badge.svg)
|
2
|
+
|
1
3
|
# RubyMagicLink
|
2
4
|
|
3
5
|
RubyMagicLink: A gem crafted for the secure generation of tokens, ensuring the safe transmission of data within your Ruby application. Useful for creating magic links—single-use URLs empowering users to perform actions without a password.
|
@@ -25,7 +27,7 @@ gem install ruby_magic_link
|
|
25
27
|
## Usage
|
26
28
|
### Configuration
|
27
29
|
|
28
|
-
For Rails applications, create an initializer file in the `config/initializers directory
|
30
|
+
For Rails applications, create an initializer file in the `config/initializers` directory.
|
29
31
|
|
30
32
|
```ruby
|
31
33
|
# config/initializers/ruby_magic_link.rb
|
@@ -9,44 +9,18 @@ module RubyMagicLink
|
|
9
9
|
DELIMITER = '|'
|
10
10
|
ALGORITHM = 'AES-256-CBC'
|
11
11
|
|
12
|
-
class TokenObject
|
13
|
-
def initialize(data)
|
14
|
-
@data = data
|
15
|
-
end
|
16
|
-
|
17
|
-
def valid?
|
18
|
-
!expired?
|
19
|
-
end
|
20
|
-
|
21
|
-
def expired?
|
22
|
-
decoded_data['expires_in'] < Time.now.to_i
|
23
|
-
end
|
24
|
-
|
25
|
-
def payload
|
26
|
-
decoded_data['payload']
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def decoded_data
|
32
|
-
@decoded_data ||= RubyMagicLink::Token.decode_token(data)
|
33
|
-
end
|
34
|
-
|
35
|
-
attr_reader :data
|
36
|
-
end
|
37
|
-
|
38
12
|
module_function
|
39
13
|
|
40
14
|
def create(payload, expires_in: nil)
|
41
15
|
data = { payload: payload }
|
42
|
-
data[:expires_in] = expires_in if expires_in
|
16
|
+
data[:expires_in] = Time.now.to_i + expires_in if expires_in
|
43
17
|
iv = OpenSSL::Random.random_bytes(16)
|
44
|
-
|
45
|
-
Base64.urlsafe_encode64(Base64.urlsafe_encode64(iv) + DELIMITER +
|
18
|
+
encrypted_data = encrypt(JSON.generate(data), RubyMagicLink.config.secret_key, iv)
|
19
|
+
Base64.urlsafe_encode64(Base64.urlsafe_encode64(iv) + DELIMITER + encrypted_data)
|
46
20
|
end
|
47
21
|
|
48
22
|
def decode(data)
|
49
|
-
TokenObject.new(data)
|
23
|
+
RubyMagicLink::TokenObject.new(data)
|
50
24
|
end
|
51
25
|
|
52
26
|
def decode_token(data)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyMagicLink
|
4
|
+
class TokenObject
|
5
|
+
def initialize(data)
|
6
|
+
@data = data
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid?
|
10
|
+
!expired?
|
11
|
+
end
|
12
|
+
|
13
|
+
def expired?
|
14
|
+
if decoded_data['expires_in']
|
15
|
+
decoded_data['expires_in'] < Time.now.to_i
|
16
|
+
else
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def payload
|
22
|
+
decoded_data['payload']
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def decoded_data
|
28
|
+
@decoded_data ||= RubyMagicLink::Token.decode_token(data)
|
29
|
+
end
|
30
|
+
|
31
|
+
attr_reader :data
|
32
|
+
end
|
33
|
+
end
|
data/lib/ruby_magic_link.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_magic_link
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Korepanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Magic links for ruby web applications
|
14
14
|
email: noemail@example.com
|
@@ -22,6 +22,7 @@ files:
|
|
22
22
|
- lib/ruby_magic_link/ruby_magic_link.rb
|
23
23
|
- lib/ruby_magic_link/tasks.rb
|
24
24
|
- lib/ruby_magic_link/token.rb
|
25
|
+
- lib/ruby_magic_link/token_object.rb
|
25
26
|
- lib/ruby_magic_link/version.rb
|
26
27
|
homepage: https://github.com/igorkorepanov/ruby_magic_link
|
27
28
|
licenses:
|