keratin-authn 0.3.1 → 0.3.2

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
  SHA1:
3
- metadata.gz: 4f56c448de089a50cd7d4ee112f5238cab39146e
4
- data.tar.gz: 4e4b9953cb86e8a1ea827d5ea9e861578260effd
3
+ metadata.gz: 806ffe0f80a2c6e59bd9873478554375bc5f45a4
4
+ data.tar.gz: 0b02c5bdd99206aaf381c9919a3ea885ab91804d
5
5
  SHA512:
6
- metadata.gz: cf79c26b1b0dd270c93fcbb708cbc7edf8931355555e69c069f6987ae577968844655ab221450198ccef76e71bb57a3c94233450da592327deb7f9d7c76b4f2d
7
- data.tar.gz: c6c7f30a6799367f31a67c3b17eee21e50a04e9b5bb6bb38aec03482e0aca3da9ceb67c64ec0e29643e45a4e8e01c29b1295f603a1b6cfc54aa0f10161a31ab3
6
+ metadata.gz: 8c71e68e2419fd280c82525cd1966520da11c2d51024bcb15d548224e6d46ccd439b87b9edb80d420870c594e7b4d231461666001304516dc792ffdaf1f3ce5b
7
+ data.tar.gz: 11b7124b866aae6727a473a717ba465f94c5d8dba90a10463d18028cfa4a4e1172b7614fb6624c4aadaa93514cb12fe86aa6f2bf40d1a05230aa19f19d232bc9
data/.rubocop.yml ADDED
@@ -0,0 +1,43 @@
1
+ AllCops:
2
+ Exclude:
3
+ - keratin-authn.gemspec
4
+
5
+ Style/Lambda:
6
+ EnforcedStyle: literal
7
+ Style/IndentArray:
8
+ EnforcedStyle: consistent
9
+ Style/IndentHash:
10
+ EnforcedStyle: consistent
11
+ Style/AlignParameters:
12
+ EnforcedStyle: with_fixed_indentation
13
+ Style/MultilineMethodCallIndentation:
14
+ EnforcedStyle: indented
15
+ Style/FrozenStringLiteralComment:
16
+ EnforcedStyle: never
17
+ Style/ClassAndModuleChildren:
18
+ EnforcedStyle: compact
19
+ Style/SpaceInsideHashLiteralBraces:
20
+ EnforcedStyle: no_space
21
+ Style/SpaceBeforeBlockBraces:
22
+ EnforcedStyle: no_space
23
+ Style/SpaceInsideBlockBraces:
24
+ SpaceBeforeBlockParameters: false
25
+
26
+ Metrics/LineLength:
27
+ Enabled: false
28
+ Metrics/MethodLength:
29
+ Enabled: false
30
+ Metrics/BlockLength:
31
+ Enabled: false
32
+ Metrics/AbcSize:
33
+ Enabled: false
34
+ Metrics/CyclomaticComplexity:
35
+ Enabled: false
36
+ Metrics/ClassLength:
37
+ Enabled: false
38
+ Style/NumericLiterals:
39
+ Enabled: false
40
+ Style/Documentation:
41
+ Enabled: false
42
+ Style/MutableConstant:
43
+ Enabled: false
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
7
  t.test_files = FileList['test/**/*_test.rb']
8
8
  t.warning = false
9
9
  end
10
10
 
11
- task :default => :test
11
+ task default: :test
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "keratin/authn"
3
+ require 'bundler/setup'
4
+ require 'keratin/authn'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
10
+ # require 'pry'
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -4,38 +4,38 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'keratin/authn/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "keratin-authn"
7
+ spec.name = 'keratin-authn'
8
8
  spec.version = Keratin::AuthN::VERSION
9
- spec.authors = ["Lance Ivy"]
10
- spec.email = ["lance@cainlevy.net"]
11
- spec.license = "LGPL-3.0"
9
+ spec.authors = ['Lance Ivy']
10
+ spec.email = ['lance@cainlevy.net']
11
+ spec.license = 'LGPL-3.0'
12
12
 
13
- spec.summary = %q{Client gem for keratin/authn service.}
14
- # spec.description = %q{}
15
- # spec.homepage = ""
13
+ spec.summary = 'Client gem for keratin/authn service.'
14
+ # spec.description = ''
15
+ # spec.homepage = ''
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
19
  if spec.respond_to?(:metadata)
20
20
  # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
21
  else
22
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
23
  end
24
24
 
25
25
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
26
  f.match(%r{^(test|spec|features)/})
27
27
  end
28
- spec.bindir = "exe"
28
+ spec.bindir = 'exe'
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
30
+ spec.require_paths = ['lib']
31
31
 
32
- spec.add_dependency "json-jwt"
33
- spec.add_dependency "lru_redux"
32
+ spec.add_dependency 'json-jwt'
33
+ spec.add_dependency 'lru_redux'
34
34
 
35
- spec.add_development_dependency "bundler", "~> 1.13"
36
- spec.add_development_dependency "rake", "~> 10.0"
37
- spec.add_development_dependency "minitest", "~> 5.0"
38
- spec.add_development_dependency "timecop"
39
- spec.add_development_dependency "byebug"
40
- spec.add_development_dependency "webmock"
35
+ spec.add_development_dependency 'bundler', '~> 1.13'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'minitest', '~> 5.0'
38
+ spec.add_development_dependency 'timecop'
39
+ spec.add_development_dependency 'byebug'
40
+ spec.add_development_dependency 'webmock'
41
41
  end
@@ -12,12 +12,27 @@ module Keratin::AuthN
12
12
  jwt['sub']
13
13
  end
14
14
 
15
+ EXPECTATIONS = [
16
+ :token_exists?,
17
+ :token_from_us?,
18
+ :token_for_us?,
19
+ :token_fresh?,
20
+ :token_intact?
21
+ ]
22
+
15
23
  def verified?
16
- jwt.present? &&
17
- token_from_us? &&
18
- token_for_us? &&
19
- !token_expired? &&
20
- token_intact?
24
+ EXPECTATIONS.all? do |expectation|
25
+ if send(expectation)
26
+ true
27
+ else
28
+ Keratin::AuthN.debug{ "JWT failure: #{expectation}" }
29
+ false
30
+ end
31
+ end
32
+ end
33
+
34
+ def token_exists?
35
+ !jwt.nil? && !jwt.blank?
21
36
  end
22
37
 
23
38
  def token_from_us?
@@ -30,8 +45,8 @@ module Keratin::AuthN
30
45
  jwt[:aud] == Keratin::AuthN.config.audience
31
46
  end
32
47
 
33
- def token_expired?
34
- jwt[:exp] < @time
48
+ def token_fresh?
49
+ jwt[:exp] > @time
35
50
  end
36
51
 
37
52
  def token_intact?
@@ -4,27 +4,27 @@ require 'net/http'
4
4
  module Keratin::AuthN
5
5
  class Issuer < Keratin::Client
6
6
  def lock(account_id)
7
- patch(path: "/accounts/:account_id/lock").result
7
+ patch(path: "/accounts/#{account_id}/lock").result
8
8
  end
9
9
 
10
10
  def unlock(account_id)
11
- patch(path: "/accounts/:account_id/unlock").result
11
+ patch(path: "/accounts/#{account_id}/unlock").result
12
12
  end
13
13
 
14
14
  def archive(account_id)
15
- delete(path: "/accounts/:account_id").result
15
+ delete(path: "/accounts/#{account_id}").result
16
16
  end
17
17
 
18
18
  def signing_key(kid)
19
19
  keys.find{|k| k['use'] == 'sig' && (kid.blank? || kid == k['kid']) }
20
20
  end
21
21
 
22
- def configuration
22
+ private def configuration
23
23
  @configuration ||= get(path: '/configuration').data
24
24
  end
25
25
 
26
- def keys
27
- @keys ||= JSON::JWK::Set.new(
26
+ private def keys
27
+ JSON::JWK::Set.new(
28
28
  get(path: URI.parse(configuration['jwks_uri']).path).data
29
29
  )
30
30
  end
@@ -1,6 +1,6 @@
1
1
  module Keratin::AuthN
2
2
  class MockSignatureVerifier
3
- def verify(jwt)
3
+ def verify(_)
4
4
  true
5
5
  end
6
6
  end
@@ -1,25 +1,23 @@
1
- module Keratin::AuthN
2
- module Test
3
- module Helpers
4
- JWS_ALGORITHM = 'RS256'
1
+ module Keratin::AuthN::Test
2
+ module Helpers
3
+ JWS_ALGORITHM = 'RS256'
5
4
 
6
- # a factory for JWT id_tokens
7
- private def id_token_for(subject)
8
- JSON::JWT.new(
9
- iss: Keratin::AuthN.config.issuer,
10
- aud: Keratin::AuthN.config.audience,
11
- sub: subject,
12
- iat: 10.seconds.ago,
13
- exp: 1.hour.from_now
14
- ).sign(jws_keypair.to_jwk, JWS_ALGORITHM).to_s
15
- end
5
+ # a factory for JWT id_tokens
6
+ private def id_token_for(subject)
7
+ JSON::JWT.new(
8
+ iss: Keratin::AuthN.config.issuer,
9
+ aud: Keratin::AuthN.config.audience,
10
+ sub: subject,
11
+ iat: 10.seconds.ago,
12
+ exp: 1.hour.from_now
13
+ ).sign(jws_keypair.to_jwk, JWS_ALGORITHM).to_s
14
+ end
16
15
 
17
- # a temporary RSA key for the test suite.
18
- #
19
- # generates the smallest (fastest) key possible for RS256
20
- private def jws_keypair
21
- @keypair ||= OpenSSL::PKey::RSA.new(512)
22
- end
16
+ # a temporary RSA key for the test suite.
17
+ #
18
+ # generates the smallest (fastest) key possible for RS256
19
+ private def jws_keypair
20
+ @keypair ||= OpenSSL::PKey::RSA.new(512)
23
21
  end
24
22
  end
25
23
  end
@@ -1,5 +1,5 @@
1
- module Keratin
1
+ module Keratin # rubocop:disable Style/ClassAndModuleChildren
2
2
  module AuthN
3
- VERSION = "0.3.1"
3
+ VERSION = '0.3.2'
4
4
  end
5
5
  end
data/lib/keratin/authn.rb CHANGED
@@ -10,7 +10,8 @@ require 'json/jwt'
10
10
 
11
11
  module Keratin
12
12
  def self.authn
13
- @authn ||= AuthN::Issuer.new(AuthN.config.issuer,
13
+ @authn ||= AuthN::Issuer.new(
14
+ AuthN.config.issuer,
14
15
  username: AuthN.config.username,
15
16
  password: AuthN.config.password
16
17
  )
@@ -35,6 +36,9 @@ module Keratin
35
36
 
36
37
  # the http basic auth password for accessing private endpoints of the authn issuer.
37
38
  attr_accessor :password
39
+
40
+ # optional logger for debug messages
41
+ attr_accessor :logger
38
42
  end
39
43
 
40
44
  def self.config
@@ -43,6 +47,10 @@ module Keratin
43
47
  end
44
48
  end
45
49
 
50
+ def self.debug
51
+ config.logger.debug{ yield } if config.logger
52
+ end
53
+
46
54
  # The default strategy for signature verification will find the JWT's issuer, fetch the JWKs
47
55
  # from that server, choose the correct key by id, and finally verify the JWT. The keys are
48
56
  # then cached in memory to reduce network traffic.
@@ -55,11 +63,11 @@ module Keratin
55
63
  # If the default strategy is not desired (as in host application tests), different strategies
56
64
  # may be specified here. The strategy must define a `verify(jwt)` method.
57
65
  def self.signature_verifier=(val)
58
- if val.respond_to?(:verify) && val.method(:verify).arity == 1
59
- @verifier = val
60
- else
61
- raise ArgumentError.new("Please ensure that your signature verifier has been instantiated and implements `def verify(jwt)`.")
66
+ unless val.respond_to?(:verify) && val.method(:verify).arity == 1
67
+ raise ArgumentError, 'Please ensure that your signature verifier has been instantiated and implements `def verify(jwt)`.'
62
68
  end
69
+
70
+ @verifier = val
63
71
  end
64
72
 
65
73
  class << self
@@ -73,7 +81,7 @@ module Keratin
73
81
  def logout_url(return_to: nil)
74
82
  query = {redirect_uri: return_to}.to_param if return_to
75
83
 
76
- "#{config.issuer}/sessions/logout#{?? if query}#{query}"
84
+ "#{config.issuer}/sessions/logout#{'?' if query}#{query}"
77
85
  end
78
86
  end
79
87
  end
@@ -28,7 +28,6 @@ module Keratin
28
28
  end
29
29
 
30
30
  class Client
31
-
32
31
  attr_reader :base
33
32
 
34
33
  def initialize(base_url, username: nil, password: nil)
@@ -66,13 +65,13 @@ module Keratin
66
65
  'location' => response['Location']
67
66
  })
68
67
  when Net::HTTPClientError
69
- raise ClientError.new(JSON.parse(response.body)['errors'])
68
+ raise ClientError, JSON.parse(response.body)['errors']
70
69
  when Net::HTTPServerError
71
- raise ServiceError.new(response.body)
70
+ raise ServiceError, response.body
72
71
  end
73
72
  end
74
73
  rescue Net::OpenTimeout, Net::ReadTimeout => e
75
- raise ServiceError.new(e.message)
74
+ raise ServiceError, e.message
76
75
  end
77
76
  end
78
77
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keratin-authn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lance Ivy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-23 00:00:00.000000000 Z
11
+ date: 2017-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-jwt
@@ -130,6 +130,7 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - ".gitignore"
133
+ - ".rubocop.yml"
133
134
  - ".travis.yml"
134
135
  - CODE_OF_CONDUCT.md
135
136
  - Gemfile