auth0-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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bb8f942000982639197c60d8e94a4197ac96b2f1e1dfdaa072db9ca3fc734dc9
4
+ data.tar.gz: c7d229c9e6b646527de507d03fa8bc3a22a0177af5c1aa0a2bde109fee7b3696
5
+ SHA512:
6
+ metadata.gz: 3c1f7a2dadc29d891c1cf2ab6e26deb7a4aa9e02ce3fcfbffd566d11c175e3f2927360e9d22f38b80d19d55ab03edcdcec402d57802f2ca1bbb50b1cbeb328e5
7
+ data.tar.gz: 807f500cf6ec6a295c716284df847371445977ee922d570b74924f7d30c819f1ca85c798b7155a87cf0dbab2ad74487a9e428dc576fbd46a952a97afaad8b50b
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,27 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.3
5
+ Exclude:
6
+ - 'bin/rubocop'
7
+ - 'bin/rspec'
8
+
9
+ Layout/AlignParameters:
10
+ Enabled: true
11
+ EnforcedStyle: with_fixed_indentation
12
+
13
+ Layout/MultilineMethodCallIndentation:
14
+ Enabled: true
15
+ EnforcedStyle: indented
16
+
17
+ Layout/CaseIndentation:
18
+ Enabled: true
19
+ EnforcedStyle: end
20
+
21
+ Metrics/BlockLength:
22
+ Exclude:
23
+ - 'spec/**/*_spec.rb'
24
+ - '*.gemspec'
25
+
26
+ Style/Documentation:
27
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at jpalumickas@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ group :development do
6
+ gem 'rubocop', '~> 0.62'
7
+ gem 'rubocop-rspec'
8
+ end
9
+
10
+ group :development, :test do
11
+ gem 'pry'
12
+ end
13
+
14
+ group :test do
15
+ gem 'rake' # For Travis CI
16
+ gem 'rspec', '~> 3.8'
17
+ gem 'simplecov', '~> 0.16', require: false
18
+ gem 'webmock', '~> 3.5'
19
+ end
20
+
21
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ auth0-verifier (0.1.0)
5
+ jwt (>= 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ ast (2.4.0)
13
+ coderay (1.1.2)
14
+ crack (0.4.3)
15
+ safe_yaml (~> 1.0.0)
16
+ diff-lcs (1.3)
17
+ docile (1.3.1)
18
+ hashdiff (0.3.8)
19
+ jaro_winkler (1.5.2)
20
+ json (2.1.0)
21
+ jwt (2.1.0)
22
+ method_source (0.9.2)
23
+ parallel (1.12.1)
24
+ parser (2.5.3.0)
25
+ ast (~> 2.4.0)
26
+ powerpack (0.1.2)
27
+ pry (0.12.2)
28
+ coderay (~> 1.1.0)
29
+ method_source (~> 0.9.0)
30
+ public_suffix (3.0.3)
31
+ rainbow (3.0.0)
32
+ rake (12.3.2)
33
+ rspec (3.8.0)
34
+ rspec-core (~> 3.8.0)
35
+ rspec-expectations (~> 3.8.0)
36
+ rspec-mocks (~> 3.8.0)
37
+ rspec-core (3.8.0)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-expectations (3.8.2)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.8.0)
42
+ rspec-mocks (3.8.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.8.0)
45
+ rspec-support (3.8.0)
46
+ rubocop (0.62.0)
47
+ jaro_winkler (~> 1.5.1)
48
+ parallel (~> 1.10)
49
+ parser (>= 2.5, != 2.5.1.1)
50
+ powerpack (~> 0.1)
51
+ rainbow (>= 2.2.2, < 4.0)
52
+ ruby-progressbar (~> 1.7)
53
+ unicode-display_width (~> 1.4.0)
54
+ rubocop-rspec (1.31.0)
55
+ rubocop (>= 0.60.0)
56
+ ruby-progressbar (1.10.0)
57
+ safe_yaml (1.0.4)
58
+ simplecov (0.16.1)
59
+ docile (~> 1.1)
60
+ json (>= 1.8, < 3)
61
+ simplecov-html (~> 0.10.0)
62
+ simplecov-html (0.10.2)
63
+ unicode-display_width (1.4.1)
64
+ webmock (3.5.1)
65
+ addressable (>= 2.3.6)
66
+ crack (>= 0.3.2)
67
+ hashdiff
68
+
69
+ PLATFORMS
70
+ ruby
71
+
72
+ DEPENDENCIES
73
+ auth0-verifier!
74
+ bundler (~> 2.0)
75
+ pry
76
+ rake
77
+ rspec (~> 3.8)
78
+ rubocop (~> 0.62)
79
+ rubocop-rspec
80
+ simplecov (~> 0.16)
81
+ webmock (~> 3.5)
82
+
83
+ BUNDLED WITH
84
+ 2.0.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Justas Palumickas
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,68 @@
1
+ # Auth0 Verifier
2
+
3
+ Verify [Auth0](auth0) JWT token using RS256 with JWKS method.
4
+
5
+ [![Gem Version](https://img.shields.io/gem/v/auth0-verifier.svg?style=flat-square)][rubygems]
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'auth0-verifier'
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### In Rails using initializer
18
+
19
+ Create file `config/initializers/auth0.rb` and add:
20
+
21
+ ```rb
22
+ Auth0::Verifier.configure do |config|
23
+ config.domain = 'test.auth0.com' # Defaults to ENV variable AUTH0_DOMAIN
24
+ config.audience = 'https://example.com' # Defaults to ENV variable AUTH0_AUDIENCE
25
+
26
+ # Optional:
27
+ #
28
+ # config.type = :RS256 # Default RS256 using JWKS
29
+ # config.jwks_url = 'https://test.auth0.com/.well-known/jwks.json' # Defaults to domain
30
+ end
31
+
32
+ ```
33
+
34
+
35
+ Verify token:
36
+
37
+ ```rb
38
+ Auth0::Verifier.verify('my token')
39
+
40
+ ```
41
+
42
+ ## Supported Ruby Versions
43
+
44
+ This library aims to support and is [tested against][travis] the following Ruby
45
+ implementations:
46
+
47
+ * Ruby 2.3.0
48
+ * Ruby 2.4.0
49
+ * Ruby 2.5.0
50
+ * Ruby 2.6.0
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jpalumickas/auth0-verifier. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
55
+
56
+
57
+ ## Code of Conduct
58
+
59
+ Everyone interacting in the Auth0 Verifier project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jpalumickas/auth0-verifier/blob/master/CODE_OF_CONDUCT.md).
60
+
61
+ ## Copyright
62
+ Copyright (c) 2019 Justas Palumickas. See [LICENSE][license] for details.
63
+
64
+ [rubygems]: https://rubygems.org/gems/auth0-verifier
65
+ [travis]: https://travis-ci.org/jpalumickas/auth0-verifier
66
+
67
+ [license]: https://raw.githubusercontent.com/jpalumickas/auth0-verifie/master/LICENSE
68
+ [auth0]: https://auth0.com
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'auth0/verifier/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'auth0-verifier'
9
+ spec.version = Auth0::Verifier::VERSION
10
+ spec.authors = ['Justas Palumickas']
11
+ spec.email = ['jpalumickas@gmail.com']
12
+
13
+ spec.summary = 'Auth0 token verifier'
14
+ spec.description = 'Auth0 verifier for Auth0 JWT tokens for RS256'
15
+ spec.homepage = 'https://github.com/jpalumickas/auth0-verifier'
16
+ spec.license = 'MIT'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = spec.homepage
20
+ spec.metadata['changelog_uri'] = 'https://github.com/jpalumickas/auth0-verifier/releases'
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added
24
+ # into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ spec.required_ruby_version = '>= 2.3.0'
35
+
36
+ spec.add_dependency 'jwt', '>= 2.0'
37
+ spec.add_development_dependency 'bundler', '~> 2.0'
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ end
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'auth0/verifier'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require 'pry'
11
+ Pry.start
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/rubocop ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+
29
+ load Gem.bin_path('rubocop', 'rubocop')
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'verifier/version'
4
+ require_relative 'verifier/error'
5
+ require_relative 'verifier/configuration'
6
+ require_relative 'verifier/jwks'
7
+ require_relative 'verifier/handler'
8
+
9
+ module Auth0
10
+ # Main module for gem
11
+ module Verifier
12
+ class << self
13
+ def handler
14
+ @handler ||= Auth0::Verifier::Handler.new
15
+ end
16
+
17
+ def verify!(options = {})
18
+ handler = Auth0::Verifier::Handler.new(options.except(:token))
19
+ handler.verify(options[:token])
20
+ end
21
+
22
+ private
23
+
24
+ def method_missing(method_name, *args, &block)
25
+ return super unless handler.respond_to?(method_name)
26
+
27
+ handler.send(method_name, *args, &block)
28
+ end
29
+
30
+ def respond_to_missing?(method_name, include_private = false)
31
+ handler.respond_to?(method_name, include_private)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+
5
+ module Auth0
6
+ module Verifier
7
+ # Configuration file
8
+ class Configuration
9
+ attr_writer :domain, :audience, :jwks_url, :type, :use_ssl
10
+
11
+ def url
12
+ protocol = use_ssl ? 'https' : 'http'
13
+ "#{protocol}://#{domain}"
14
+ end
15
+
16
+ def domain
17
+ @domain || URI(ENV['AUTH0_DOMAIN']).host
18
+ end
19
+
20
+ def type
21
+ @type || :RS256
22
+ end
23
+
24
+ def audience
25
+ @audience || ENV['AUTH0_AUDIENCE']
26
+ end
27
+
28
+ def use_ssl
29
+ return @use_ssl unless @use_ssl.nil?
30
+
31
+ true
32
+ end
33
+
34
+ def jwks_url
35
+ return @jwks_url if @jwks_url
36
+ return unless domain
37
+
38
+ "#{url}/.well-known/jwks.json"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auth0
4
+ module Verifier
5
+ class Error < StandardError; end
6
+ end
7
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'handlers/base'
4
+ require_relative 'handlers/rs256'
5
+
6
+ module Auth0
7
+ module Verifier
8
+ class Handler
9
+ def initialize(options = {})
10
+ options.each do |key, value|
11
+ config.public_send("#{key}=", value) if config.respond_to?("#{key}=")
12
+ end
13
+ end
14
+
15
+ def verify(token)
16
+ handler.new(token: token, config: config).verify
17
+ end
18
+
19
+ def config
20
+ @config ||= Configuration.new
21
+ end
22
+ alias configuration config
23
+
24
+ def configure
25
+ yield(config) if block_given?
26
+ true
27
+ end
28
+
29
+ private
30
+
31
+ def handler
32
+ case config.type.to_s.downcase
33
+ when 'rs256'
34
+ Auth0::Verifier::Handlers::Rs256
35
+ else
36
+ raise NotImplementedError
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auth0
4
+ module Verifier
5
+ module Handlers
6
+ class Base
7
+ attr_reader :token, :config
8
+
9
+ def initialize(token:, config:)
10
+ @token = token
11
+ @config = config
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jwt'
4
+
5
+ module Auth0
6
+ module Verifier
7
+ module Handlers
8
+ class Rs256 < Base
9
+ def verify
10
+ decode_jwt do |header|
11
+ jwks.keys[header['kid']]
12
+ end
13
+ rescue JWT::DecodeError, JWT::VerificationError
14
+ raise Auth0::Verifier::Error, 'Cannot verify token'
15
+ end
16
+
17
+ private
18
+
19
+ def decode_jwt(&block)
20
+ JWT.decode(
21
+ token,
22
+ nil,
23
+ true, # Verify the signature of this token
24
+ jwt_options,
25
+ &block
26
+ )
27
+ end
28
+
29
+ def jwt_options
30
+ {
31
+ algorithm: 'RS256',
32
+ iss: "#{config.url}/",
33
+ verify_iss: true,
34
+ aud: config.audience,
35
+ verify_aud: true
36
+ }
37
+ end
38
+
39
+ def jwks
40
+ @jwks ||= Auth0::Verifier::Jwks.new(config.jwks_url)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+ require 'base64'
7
+ require 'openssl'
8
+
9
+ module Auth0
10
+ module Verifier
11
+ class Jwks
12
+ attr_reader :url
13
+
14
+ def initialize(url)
15
+ @url = url
16
+ end
17
+
18
+ def keys
19
+ return unless data
20
+
21
+ jwks_keys = Array(data['keys'])
22
+ jwks_keys.each_with_object({}) do |key, object|
23
+ next unless key['alg'] == 'RS256'
24
+
25
+ object[key['kid']] = key_certificate(key)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def key_certificate(key)
32
+ decoded = Base64.decode64(key['x5c'][0])
33
+ OpenSSL::X509::Certificate.new(decoded).public_key
34
+ end
35
+
36
+ def data
37
+ @data ||= begin
38
+ result = Net::HTTP.get(URI(url))
39
+ JSON.parse(result)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auth0
4
+ module Verifier
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auth0-verifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justas Palumickas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Auth0 verifier for Auth0 JWT tokens for RS256
56
+ email:
57
+ - jpalumickas@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - auth0-verifier.gemspec
73
+ - bin/console
74
+ - bin/rspec
75
+ - bin/rubocop
76
+ - bin/setup
77
+ - lib/auth0/verifier.rb
78
+ - lib/auth0/verifier/configuration.rb
79
+ - lib/auth0/verifier/error.rb
80
+ - lib/auth0/verifier/handler.rb
81
+ - lib/auth0/verifier/handlers/base.rb
82
+ - lib/auth0/verifier/handlers/rs256.rb
83
+ - lib/auth0/verifier/jwks.rb
84
+ - lib/auth0/verifier/version.rb
85
+ homepage: https://github.com/jpalumickas/auth0-verifier
86
+ licenses:
87
+ - MIT
88
+ metadata:
89
+ homepage_uri: https://github.com/jpalumickas/auth0-verifier
90
+ source_code_uri: https://github.com/jpalumickas/auth0-verifier
91
+ changelog_uri: https://github.com/jpalumickas/auth0-verifier/releases
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 2.3.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.0.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Auth0 token verifier
111
+ test_files: []