gemstack-auth 0.3.6 → 0.4.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/CHANGELOG.md +4 -0
- data/README.md +3 -3
- data/lib/gemstack/auth.rb +14 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2efaac830d8c9ee2e7bee3b328c8ccfc770d50bc8e330b638f74021024b62c8f
|
|
4
|
+
data.tar.gz: b39738f3bbec6df951c91144032172360cddc91509f2487582a375d094298050
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 965368dfdd044bd3010c4dfdbd9c9d7a0023a9f6f5568d90a6943cf4af3b22bfb620f555f77113fd753b8a95ef56c80dc719b424d81154018f3e43f35d9d7779
|
|
7
|
+
data.tar.gz: 7361c0f0246ff1c7cd0f1e31d0dfc6974e5997a5e0deeb22d397dd6fb188713113057a76da8d087095d989bded073cd64799ddebbc116324564c1a42e5489e71
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
GemStack auth: Argon2id passwords, cookie sessions, API tokens, policies.
|
|
4
4
|
|
|
5
|
-
Part of [GemStack](https://github.com/gemstack-rb/gemstack), a modular Ruby
|
|
6
|
-
|
|
5
|
+
Part of [GemStack](https://github.com/gemstack-rb/gemstack), a modular Ruby web application framework with
|
|
6
|
+
a Next.js frontend, by [Adware Technologies](https://www.adwaretech.com). All GemStack gems are developed together in that repository and released with the same
|
|
7
7
|
version.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
@@ -11,7 +11,7 @@ version.
|
|
|
11
11
|
Optional module — `gemstack add auth`:
|
|
12
12
|
|
|
13
13
|
```ruby
|
|
14
|
-
gem "gemstack-auth", "~> 0.
|
|
14
|
+
gem "gemstack-auth", "~> 0.4.0"
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Documentation
|
data/lib/gemstack/auth.rb
CHANGED
|
@@ -55,6 +55,20 @@ module GemStack
|
|
|
55
55
|
|
|
56
56
|
def db = DB.connection
|
|
57
57
|
|
|
58
|
+
# The signed-in user of a Rack request — a Bearer API token or the session
|
|
59
|
+
# cookie, like controllers' current_user — or nil. For code outside
|
|
60
|
+
# controllers, e.g. config/channels.rb:
|
|
61
|
+
# identify { |request| GemStack::Auth.user_from(request)&.then { |u| { id: u.id } } }
|
|
62
|
+
def user_from(request)
|
|
63
|
+
if (token = request.get_header("HTTP_AUTHORIZATION").to_s[/\ABearer\s+(\S+)\z/i, 1])
|
|
64
|
+
row = Tokens.find(token, purpose: "api") or return nil
|
|
65
|
+
user_class[row[:user_id]]
|
|
66
|
+
elsif (cookie = request.cookies[config.cookie_name])
|
|
67
|
+
session = Sessions.find(cookie) or return nil
|
|
68
|
+
user_class[session[:user_id]]
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
58
72
|
# Deletes expired sessions and tokens; run it daily from a job.
|
|
59
73
|
def cleanup!
|
|
60
74
|
now = Time.now
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gemstack-auth
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Adware Technologies
|
|
@@ -30,14 +30,14 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - '='
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 0.
|
|
33
|
+
version: 0.4.0
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - '='
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 0.
|
|
40
|
+
version: 0.4.0
|
|
41
41
|
email:
|
|
42
42
|
- gemstack26@gmail.com
|
|
43
43
|
executables: []
|