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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a653bd311fdb43e3c4f202e8761582c459ffa1c4e85a1e7309e337e8dd6e1f0
4
- data.tar.gz: 846d43693d28a97cdd4a9fca88e0ee51c6a6289ac389122e078ccc9a8193a40f
3
+ metadata.gz: 4124184b5f99cb6976a978a75da83643bb40984c4e59bef1992fee722e046e4d
4
+ data.tar.gz: a525c3d884017cc30b371412d7268d746628cece3a1e27f8530399f960a92dc7
5
5
  SHA512:
6
- metadata.gz: 6b9185d2dc8a350988c52bfd56c3417840969d89167ee7824132ddc505630b99a4bbc757edd1ea8b644e67da856a3ca78fe88a927334d0ecd7cc16c606de423a
7
- data.tar.gz: 343cab74ac29ded2ff832c19c141fd0d14dc6fdb7d0da3fb0ba7e32006ba29a0550445a1d42c204d15e569c2797c142a02769e8360cfa9ac8e72c375b2a0f9ad
6
+ metadata.gz: dec363f76f004cee9a2d9275c5967c556dece83f91e427029e0e99a640fbf5ae164876d66d742cef4c4bdb0e64627cd7b3776019567f9ea475d913e981d81d6e
7
+ data.tar.gz: fbab3ccd2a07a9268bef3a20242dac63405b586a1d37a394bc25b5ee5bed6a0a243853c5eee2aeb9feb99b594005cd432981d889f98b6d216f6fd63feaf414d3
data/lib/keycard.rb CHANGED
@@ -18,3 +18,4 @@ require "keycard/db"
18
18
  require "keycard/railtie" if defined?(Rails)
19
19
  require "keycard/institution_finder"
20
20
  require "keycard/request"
21
+ require "keycard/token"
@@ -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
- user_pid: user_pid,
15
- user_eid: user_eid,
16
- client_ip: client_ip,
17
- persistentNameID: persistent_id,
18
- eduPersonPrincipalName: principal_name,
19
- eduPersonScopedAffiliation: affiliation,
20
- displayName: display_name,
21
- mail: email,
22
- authnContextClassRef: authn_context,
23
- authenticationMethod: authn_method,
24
- identity_provider: identity_provider
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Keycard
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
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.0
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-06 00:00:00.000000000 Z
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