keycard 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/keycard.rb +1 -0
- data/lib/keycard/request/attributes.rb +12 -1
- data/lib/keycard/request/cosign_attributes.rb +0 -8
- data/lib/keycard/request/direct_attributes.rb +0 -8
- data/lib/keycard/request/proxied_attributes.rb +0 -8
- data/lib/keycard/request/shibboleth_attributes.rb +12 -13
- data/lib/keycard/token.rb +35 -0
- data/lib/keycard/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: 4124184b5f99cb6976a978a75da83643bb40984c4e59bef1992fee722e046e4d
|
4
|
+
data.tar.gz: a525c3d884017cc30b371412d7268d746628cece3a1e27f8530399f960a92dc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dec363f76f004cee9a2d9275c5967c556dece83f91e427029e0e99a640fbf5ae164876d66d742cef4c4bdb0e64627cd7b3776019567f9ea475d913e981d81d6e
|
7
|
+
data.tar.gz: fbab3ccd2a07a9268bef3a20242dac63405b586a1d37a394bc25b5ee5bed6a0a243853c5eee2aeb9feb99b594005cd432981d889f98b6d216f6fd63feaf414d3
|
data/lib/keycard.rb
CHANGED
@@ -52,12 +52,23 @@ module Keycard::Request
|
|
52
52
|
nil
|
53
53
|
end
|
54
54
|
|
55
|
+
# The token supplied by the user via auth_param according to RFC 7235. Typically,
|
56
|
+
# this is the API token.
|
57
|
+
def auth_token
|
58
|
+
Keycard::Token.rfc7235(safe('HTTP_AUTHORIZATION'))
|
59
|
+
end
|
60
|
+
|
55
61
|
# The set of base attributes for this request.
|
56
62
|
#
|
57
63
|
# Subclasses should implement user_pid, user_eid, and client_ip
|
58
64
|
# and include them in the hash under those keys.
|
59
65
|
def base
|
60
|
-
{
|
66
|
+
{
|
67
|
+
user_pid: user_pid,
|
68
|
+
user_eid: user_eid,
|
69
|
+
client_ip: client_ip,
|
70
|
+
auth_token: auth_token
|
71
|
+
}
|
61
72
|
end
|
62
73
|
|
63
74
|
def [](attr)
|
@@ -6,14 +6,6 @@ module Keycard::Request
|
|
6
6
|
# the pid/eid are the same and there are currently no additional
|
7
7
|
# attributes extracted.
|
8
8
|
class CosignAttributes < Attributes
|
9
|
-
def base
|
10
|
-
{
|
11
|
-
user_pid: user_pid,
|
12
|
-
user_eid: user_eid,
|
13
|
-
client_ip: client_ip
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
9
|
def user_pid
|
18
10
|
get 'HTTP_X_REMOTE_USER'
|
19
11
|
end
|
@@ -5,14 +5,6 @@ module Keycard::Request
|
|
5
5
|
# serve HTTP requests directly or through a proxy that passes trusted
|
6
6
|
# values into the application environment to be accessed as usual.
|
7
7
|
class DirectAttributes < Attributes
|
8
|
-
def base
|
9
|
-
{
|
10
|
-
user_pid: user_pid,
|
11
|
-
user_eid: user_eid,
|
12
|
-
client_ip: client_ip
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
8
|
def user_pid
|
17
9
|
get 'REMOTE_USER'
|
18
10
|
end
|
@@ -9,14 +9,6 @@ module Keycard::Request
|
|
9
9
|
# which, somewhat confusingly, are transposed into HTTP_X_REMOTE_USER and
|
10
10
|
# HTTP_X_FORWARDED_FOR once the Rack request is assembled.
|
11
11
|
class ProxiedAttributes < Attributes
|
12
|
-
def base
|
13
|
-
{
|
14
|
-
user_pid: user_pid,
|
15
|
-
user_eid: user_eid,
|
16
|
-
client_ip: client_ip
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
12
|
def user_pid
|
21
13
|
get 'HTTP_X_REMOTE_USER'
|
22
14
|
end
|
@@ -10,19 +10,18 @@ module Keycard::Request
|
|
10
10
|
# requests, and the user_pid, for requests from authenticated users.
|
11
11
|
class ShibbolethAttributes < Attributes
|
12
12
|
def base # rubocop:disable Metrics/MethodLength
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
}
|
13
|
+
super.merge(
|
14
|
+
{
|
15
|
+
persistentNameID: persistent_id,
|
16
|
+
eduPersonPrincipalName: principal_name,
|
17
|
+
eduPersonScopedAffiliation: affiliation,
|
18
|
+
displayName: display_name,
|
19
|
+
mail: email,
|
20
|
+
authnContextClassRef: authn_context,
|
21
|
+
authenticationMethod: authn_method,
|
22
|
+
identity_provider: identity_provider
|
23
|
+
}
|
24
|
+
)
|
26
25
|
end
|
27
26
|
|
28
27
|
def user_pid
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Holds utility methods for parsing tokens from header values
|
4
|
+
class Keycard::Token
|
5
|
+
TOKEN_DELIMS = /\s*[:,;\t]\s*/.freeze
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def rfc7235(string)
|
9
|
+
string
|
10
|
+
.sub(/^(Bearer|Token):?/, '')
|
11
|
+
.split(TOKEN_DELIMS)
|
12
|
+
.map { |assignment| split_assignment(assignment) }
|
13
|
+
.to_h["token"]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
# @param string_assignment [String] of the form 'key="value"'
|
19
|
+
# @return An array of pairs of key:value, both strings
|
20
|
+
def split_assignment(string_assignment)
|
21
|
+
clean_assignment(string_assignment)
|
22
|
+
.split('=')
|
23
|
+
.push('')
|
24
|
+
.slice(0, 2)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param string_assignment [String] of the form 'key="value"'
|
28
|
+
# @return [String] With the quotes and extraneous whitespace removed.
|
29
|
+
def clean_assignment(string_assignment)
|
30
|
+
string_assignment
|
31
|
+
.delete('"')
|
32
|
+
.strip
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/keycard/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keycard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Botimer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-03-
|
12
|
+
date: 2019-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sequel
|
@@ -207,6 +207,7 @@ files:
|
|
207
207
|
- lib/keycard/request/direct_attributes.rb
|
208
208
|
- lib/keycard/request/proxied_attributes.rb
|
209
209
|
- lib/keycard/request/shibboleth_attributes.rb
|
210
|
+
- lib/keycard/token.rb
|
210
211
|
- lib/keycard/version.rb
|
211
212
|
- lib/tasks/migrate.rake
|
212
213
|
homepage: https://github.com/mlibrary/keycard
|