cognito_token_verifier 0.1.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +116 -0
- data/LICENSE.txt +21 -0
- data/README.md +73 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cognito_token_verifier.gemspec +42 -0
- data/gemfiles/rails42.gemfile +11 -0
- data/gemfiles/rails51.gemfile +11 -0
- data/gemfiles/rails52.gemfile +11 -0
- data/lib/cognito_token_verifier.rb +23 -0
- data/lib/cognito_token_verifier/config.rb +38 -0
- data/lib/cognito_token_verifier/controller_macros.rb +34 -0
- data/lib/cognito_token_verifier/errors.rb +46 -0
- data/lib/cognito_token_verifier/token.rb +26 -0
- data/lib/cognito_token_verifier/version.rb +3 -0
- metadata +198 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b62edbc24a15d7e43934a4ffcb641370e503084caffbac662da565528b3621f4
|
4
|
+
data.tar.gz: 4d562bee7ee8130d082c3f24530a1e62f235c03e176733bdd7b17d7cf7deca09
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 000d7d04865954163674f2970163cd411fae1a8bbd83cf7f2dd5feeac00f5674367fd07621e135a44c59a2687115092405834ae42a9d5cad5bbbf7353a62a5bf
|
7
|
+
data.tar.gz: e1c17ca0365937f4bad00d395283f9d8f74fc58342cda151a23597c34925d1f058ed2f23ecad157b26a028854225275b4dd5b3b7d4646facf5184a7f280ca972
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
sudo: false
|
3
|
+
language: ruby
|
4
|
+
cache: bundler
|
5
|
+
rvm:
|
6
|
+
- 2.3.8
|
7
|
+
- 2.4.5
|
8
|
+
- 2.5.3
|
9
|
+
- 2.6.1
|
10
|
+
before_install: gem install bundler -v 2.0.1
|
11
|
+
gemfile:
|
12
|
+
- Gemfile
|
13
|
+
- gemfiles/rails42.gemfile
|
14
|
+
- gemfiles/rails51.gemfile
|
15
|
+
- gemfiles/rails52.gemfile
|
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cognito_token_verifier (0.1.0)
|
5
|
+
activesupport (>= 4.2, < 6.0)
|
6
|
+
json-jwt (~> 1.1)
|
7
|
+
rest-client (~> 2.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actionpack (5.2.2)
|
13
|
+
actionview (= 5.2.2)
|
14
|
+
activesupport (= 5.2.2)
|
15
|
+
rack (~> 2.0)
|
16
|
+
rack-test (>= 0.6.3)
|
17
|
+
rails-dom-testing (~> 2.0)
|
18
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
19
|
+
actionview (5.2.2)
|
20
|
+
activesupport (= 5.2.2)
|
21
|
+
builder (~> 3.1)
|
22
|
+
erubi (~> 1.4)
|
23
|
+
rails-dom-testing (~> 2.0)
|
24
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
25
|
+
activesupport (5.2.2)
|
26
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
27
|
+
i18n (>= 0.7, < 2)
|
28
|
+
minitest (~> 5.1)
|
29
|
+
tzinfo (~> 1.1)
|
30
|
+
aes_key_wrap (1.0.1)
|
31
|
+
bindata (2.4.4)
|
32
|
+
builder (3.2.3)
|
33
|
+
byebug (11.0.0)
|
34
|
+
concurrent-ruby (1.1.4)
|
35
|
+
crass (1.0.4)
|
36
|
+
diff-lcs (1.3)
|
37
|
+
domain_name (0.5.20180417)
|
38
|
+
unf (>= 0.0.5, < 1.0.0)
|
39
|
+
erubi (1.8.0)
|
40
|
+
http-cookie (1.0.3)
|
41
|
+
domain_name (~> 0.5)
|
42
|
+
i18n (1.5.3)
|
43
|
+
concurrent-ruby (~> 1.0)
|
44
|
+
json-jwt (1.10.0)
|
45
|
+
activesupport (>= 4.2)
|
46
|
+
aes_key_wrap
|
47
|
+
bindata
|
48
|
+
loofah (2.2.3)
|
49
|
+
crass (~> 1.0.2)
|
50
|
+
nokogiri (>= 1.5.9)
|
51
|
+
method_source (0.9.2)
|
52
|
+
mime-types (3.2.2)
|
53
|
+
mime-types-data (~> 3.2015)
|
54
|
+
mime-types-data (3.2018.0812)
|
55
|
+
mini_portile2 (2.4.0)
|
56
|
+
minitest (5.11.3)
|
57
|
+
netrc (0.11.0)
|
58
|
+
nokogiri (1.10.1)
|
59
|
+
mini_portile2 (~> 2.4.0)
|
60
|
+
rack (2.0.6)
|
61
|
+
rack-test (1.1.0)
|
62
|
+
rack (>= 1.0, < 3)
|
63
|
+
rails-dom-testing (2.0.3)
|
64
|
+
activesupport (>= 4.2.0)
|
65
|
+
nokogiri (>= 1.6)
|
66
|
+
rails-html-sanitizer (1.0.4)
|
67
|
+
loofah (~> 2.2, >= 2.2.2)
|
68
|
+
railties (5.2.2)
|
69
|
+
actionpack (= 5.2.2)
|
70
|
+
activesupport (= 5.2.2)
|
71
|
+
method_source
|
72
|
+
rake (>= 0.8.7)
|
73
|
+
thor (>= 0.19.0, < 2.0)
|
74
|
+
rake (12.3.2)
|
75
|
+
rest-client (2.0.2)
|
76
|
+
http-cookie (>= 1.0.2, < 2.0)
|
77
|
+
mime-types (>= 1.16, < 4.0)
|
78
|
+
netrc (~> 0.8)
|
79
|
+
rspec-core (3.8.0)
|
80
|
+
rspec-support (~> 3.8.0)
|
81
|
+
rspec-expectations (3.8.2)
|
82
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
83
|
+
rspec-support (~> 3.8.0)
|
84
|
+
rspec-mocks (3.8.0)
|
85
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
86
|
+
rspec-support (~> 3.8.0)
|
87
|
+
rspec-rails (3.8.2)
|
88
|
+
actionpack (>= 3.0)
|
89
|
+
activesupport (>= 3.0)
|
90
|
+
railties (>= 3.0)
|
91
|
+
rspec-core (~> 3.8.0)
|
92
|
+
rspec-expectations (~> 3.8.0)
|
93
|
+
rspec-mocks (~> 3.8.0)
|
94
|
+
rspec-support (~> 3.8.0)
|
95
|
+
rspec-support (3.8.0)
|
96
|
+
thor (0.20.3)
|
97
|
+
thread_safe (0.3.6)
|
98
|
+
tzinfo (1.2.5)
|
99
|
+
thread_safe (~> 0.1)
|
100
|
+
unf (0.1.4)
|
101
|
+
unf_ext
|
102
|
+
unf_ext (0.0.7.5)
|
103
|
+
|
104
|
+
PLATFORMS
|
105
|
+
ruby
|
106
|
+
|
107
|
+
DEPENDENCIES
|
108
|
+
actionpack (>= 4.2, < 6.0)
|
109
|
+
bundler (~> 2.0)
|
110
|
+
byebug
|
111
|
+
cognito_token_verifier!
|
112
|
+
rake (>= 10.0, < 13.0)
|
113
|
+
rspec-rails (~> 3.0)
|
114
|
+
|
115
|
+
BUNDLED WITH
|
116
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Matt Tanous
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# CognitoTokenVerifier [](https://travis-ci.org/CodingAnarchy/cognito_token_verifier)
|
2
|
+
|
3
|
+
Verify and decode AWS Cognito tokens for use in your Ruby application.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'cognito_token_verifier'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install cognito_token_verifier
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
This gem provides a `Token` class that will verify and decode a token, as well as controller macros to run verification on tokens automatically. To use, first configure the gem with the appropriate AWS configuration, as below:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
CognitoTokenVerifier.configure do |config|
|
27
|
+
config.aws_region = 'us-west-2'
|
28
|
+
config.user_pool_id = 'your_user_pool_id'
|
29
|
+
config.token_use = 'id' # acceptable options are 'id' and 'access'; can be an array for both options - defaults to allowing either cognito token type
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
You can then include the controller macros in your controller and override the methods to handle expired and invalid tokens (or you can skip this step and allow errors to be raised).
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
class ExampleController < ActionController::Base
|
37
|
+
include CognitoTokenVerifier::ControllerMacros
|
38
|
+
|
39
|
+
...
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def handle_expired_token(exception)
|
44
|
+
# Do what you want here
|
45
|
+
end
|
46
|
+
|
47
|
+
def handle_invalid_token(exception)
|
48
|
+
# Do what you want here
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
You can also access the Cognito token in the controller yourself for additional verification (such as custom attributes). For example:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
def handle_custom_attribute
|
57
|
+
cognito_token.decoded_token['custom:attr'] == <some_value>
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
## Development
|
62
|
+
|
63
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
64
|
+
|
65
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/CodingAnarchy/cognito_token_verifier.
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cognito_token_verifier"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "cognito_token_verifier/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cognito_token_verifier"
|
8
|
+
spec.version = CognitoTokenVerifier::VERSION
|
9
|
+
spec.authors = ["Matt Tanous"]
|
10
|
+
spec.email = ["mtanous22@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Verify and parse AWS Cognito JWTs to authenticate endpoints}
|
13
|
+
spec.homepage = "https://github.com/CodingAnarchy/cognito_token_verifier"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/CodingAnarchy/cognito_token_verifier/blob/master/CHANGELOG.md"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Specify which files should be added to the gem when it is released.
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_runtime_dependency "activesupport", [">= 4.2", "< 6.0"]
|
34
|
+
spec.add_runtime_dependency "json-jwt", "~> 1.1"
|
35
|
+
spec.add_runtime_dependency "rest-client", "~> 2.0"
|
36
|
+
|
37
|
+
spec.add_development_dependency "byebug", "~> 11.0"
|
38
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
39
|
+
spec.add_development_dependency "rake", [">= 10.0", "< 13.0"]
|
40
|
+
spec.add_development_dependency "rspec-rails", "~> 3.0"
|
41
|
+
spec.add_development_dependency "actionpack", [">= 4.2", "< 6.0"]
|
42
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "cognito_token_verifier/version"
|
2
|
+
require "cognito_token_verifier/errors"
|
3
|
+
require "cognito_token_verifier/config"
|
4
|
+
require "cognito_token_verifier/token"
|
5
|
+
require "cognito_token_verifier/controller_macros"
|
6
|
+
|
7
|
+
module CognitoTokenVerifier
|
8
|
+
class << self
|
9
|
+
attr_accessor :config
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.config
|
13
|
+
@config ||= Config.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.reset
|
17
|
+
@config = Config.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configure
|
21
|
+
yield(config)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module CognitoTokenVerifier
|
4
|
+
class Config
|
5
|
+
attr_accessor :aws_region, :user_pool_id, :token_use, :allow_expired_tokens
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@aws_region = nil
|
9
|
+
@user_pool_id = nil
|
10
|
+
@token_use = 'all'
|
11
|
+
@allow_expired_tokens = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def any_token_use?
|
15
|
+
['all', 'any', ['id', 'access']].any?{|usage| usage == token_use }
|
16
|
+
end
|
17
|
+
|
18
|
+
def allow_expired_tokens?
|
19
|
+
allow_expired_tokens
|
20
|
+
end
|
21
|
+
|
22
|
+
def jwks
|
23
|
+
raise ConfigSetupError.new(self) unless aws_region.present? and user_pool_id.present?
|
24
|
+
@jwks ||= JSON.parse(RestClient.get(jwk_url))
|
25
|
+
# TODO: rescue RestClient and JSON errors here to present a more user-friendly error
|
26
|
+
end
|
27
|
+
|
28
|
+
def iss
|
29
|
+
"https://cognito-idp.#{aws_region}.amazonaws.com/#{user_pool_id}"
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def jwk_url
|
35
|
+
"#{iss}/.well-known/jwks.json"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require "cognito_token_verifier/token"
|
3
|
+
|
4
|
+
module CognitoTokenVerifier
|
5
|
+
module ControllerMacros
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
before_action :verify_cognito_token
|
10
|
+
rescue_from CognitoTokenVerifier::TokenExpired, with: :handle_expired_token
|
11
|
+
rescue_from CognitoTokenVerifier::Error, with: :handle_invalid_token
|
12
|
+
end
|
13
|
+
|
14
|
+
def cognito_token
|
15
|
+
return @cognito_token if @cognito_token.present? # Caching here, so gem user can access token themselves for additional checks
|
16
|
+
raise TokenMissing unless request.headers['authorization'].present?
|
17
|
+
@cognito_token = CognitoTokenVerifier::Token.new(request.headers['authorization'])
|
18
|
+
end
|
19
|
+
|
20
|
+
def verify_cognito_token
|
21
|
+
raise TokenExpired if cognito_token.expired?
|
22
|
+
raise IncorrectTokenType.new(cognito_token) unless cognito_token.valid_token_use?
|
23
|
+
raise InvalidIss.new(cognito_token) unless cognito_token.valid_iss?
|
24
|
+
end
|
25
|
+
|
26
|
+
def handle_expired_token(exception)
|
27
|
+
raise exception # Just re-raise the exception: this is for the user to overwrite
|
28
|
+
end
|
29
|
+
|
30
|
+
def handle_invalid_token(exception)
|
31
|
+
raise exception # Just re-raise the exception: this is for the user to overwrite
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module CognitoTokenVerifier
|
2
|
+
class Error < StandardError; end
|
3
|
+
|
4
|
+
class ConfigSetupError < StandardError
|
5
|
+
def initialize(config)
|
6
|
+
@aws_region = config.aws_region
|
7
|
+
@user_pool_id = config.user_pool_id
|
8
|
+
end
|
9
|
+
|
10
|
+
def message
|
11
|
+
"Configuration of CognitoTokenVerifier is incomplete: please verify aws_region (#{@aws_region}) and Cognito user_pool_id (#{@user_pool_id})."
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class TokenMissing < CognitoTokenVerifier::Error
|
16
|
+
def message
|
17
|
+
"Cognito token not provided. Please retransmit request with Cognito token in authorization header."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class TokenExpired < StandardError
|
22
|
+
def message
|
23
|
+
"Cognito token has expired. Please reauthorize and try again."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class IncorrectTokenType < CognitoTokenVerifier::Error
|
28
|
+
def initialize(token)
|
29
|
+
@token_use = token.decoded_token['token_use']
|
30
|
+
end
|
31
|
+
|
32
|
+
def message
|
33
|
+
"Incorrect token type. Received #{@token_use} while expecting one of #{[CognitoTokenVerifier.config.token_use].flatten}."
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class InvalidIss < CognitoTokenVerifier::Error
|
38
|
+
def initialize(token)
|
39
|
+
@iss = token.decoded_token['iss']
|
40
|
+
end
|
41
|
+
|
42
|
+
def message
|
43
|
+
"Invalid token ISS reference. Received #{@iss} while expecting #{CognitoTokenVerifier.config.iss}."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'json/jwt'
|
2
|
+
|
3
|
+
module CognitoTokenVerifier
|
4
|
+
class Token
|
5
|
+
attr_reader :header, :decoded_token
|
6
|
+
|
7
|
+
def initialize(jwt)
|
8
|
+
@header= JSON.parse(Base64.decode64(jwt.split('.')[0]))
|
9
|
+
@jwk = JSON::JWK.new(CognitoTokenVerifier.config.jwks["keys"].detect{|jwk| jwk['kid'] == header['kid']})
|
10
|
+
@decoded_token = JSON::JWT.decode(jwt, @jwk)
|
11
|
+
# TODO: rescue errors for JSON/JWK/JWT parsing/decoding to present user-friendly "token could not be decoded" error
|
12
|
+
end
|
13
|
+
|
14
|
+
def expired?
|
15
|
+
decoded_token['exp'] < Time.now.to_i and not CognitoTokenVerifier.config.allow_expired_tokens?
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid_token_use?
|
19
|
+
CognitoTokenVerifier.config.any_token_use? || [CognitoTokenVerifier.config.token_use].flatten.include?(decoded_token['token_use'])
|
20
|
+
end
|
21
|
+
|
22
|
+
def valid_iss?
|
23
|
+
decoded_token['iss'] == CognitoTokenVerifier.config.iss
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cognito_token_verifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Tanous
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.2'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: json-jwt
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.1'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.1'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rest-client
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: byebug
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '11.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '11.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: bundler
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rake
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '10.0'
|
96
|
+
- - "<"
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '13.0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '10.0'
|
106
|
+
- - "<"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '13.0'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: rspec-rails
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '3.0'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '3.0'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: actionpack
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '4.2'
|
130
|
+
- - "<"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '6.0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '4.2'
|
140
|
+
- - "<"
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '6.0'
|
143
|
+
description:
|
144
|
+
email:
|
145
|
+
- mtanous22@gmail.com
|
146
|
+
executables: []
|
147
|
+
extensions: []
|
148
|
+
extra_rdoc_files: []
|
149
|
+
files:
|
150
|
+
- ".gitignore"
|
151
|
+
- ".rspec"
|
152
|
+
- ".travis.yml"
|
153
|
+
- CHANGELOG.md
|
154
|
+
- Gemfile
|
155
|
+
- Gemfile.lock
|
156
|
+
- LICENSE.txt
|
157
|
+
- README.md
|
158
|
+
- Rakefile
|
159
|
+
- bin/console
|
160
|
+
- bin/setup
|
161
|
+
- cognito_token_verifier.gemspec
|
162
|
+
- gemfiles/rails42.gemfile
|
163
|
+
- gemfiles/rails51.gemfile
|
164
|
+
- gemfiles/rails52.gemfile
|
165
|
+
- lib/cognito_token_verifier.rb
|
166
|
+
- lib/cognito_token_verifier/config.rb
|
167
|
+
- lib/cognito_token_verifier/controller_macros.rb
|
168
|
+
- lib/cognito_token_verifier/errors.rb
|
169
|
+
- lib/cognito_token_verifier/token.rb
|
170
|
+
- lib/cognito_token_verifier/version.rb
|
171
|
+
homepage: https://github.com/CodingAnarchy/cognito_token_verifier
|
172
|
+
licenses:
|
173
|
+
- MIT
|
174
|
+
metadata:
|
175
|
+
homepage_uri: https://github.com/CodingAnarchy/cognito_token_verifier
|
176
|
+
source_code_uri: https://github.com/CodingAnarchy/cognito_token_verifier
|
177
|
+
changelog_uri: https://github.com/CodingAnarchy/cognito_token_verifier/blob/master/CHANGELOG.md
|
178
|
+
post_install_message:
|
179
|
+
rdoc_options: []
|
180
|
+
require_paths:
|
181
|
+
- lib
|
182
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
requirements: []
|
193
|
+
rubyforge_project:
|
194
|
+
rubygems_version: 2.7.8
|
195
|
+
signing_key:
|
196
|
+
specification_version: 4
|
197
|
+
summary: Verify and parse AWS Cognito JWTs to authenticate endpoints
|
198
|
+
test_files: []
|