diff --git a/.rspec b/.rspec index 83e16f8..4e1e0d2 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1 @@ --color ---require spec_helper diff --git a/.travis.yml b/.travis.yml index 630f8d4..7441ef0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: ruby rvm: - - 2.2.2 - - 2.1.6 - - 2.0.0 -# uncomment this line if your project needs to run something other than `rake`: -script: bundle exec rspec spec + - 2.0.0-p648 + - 2.1.10 + - 2.2.5 + - 2.3.1 +before_install: gem install bundler -v 1.13.2 diff --git a/Gemfile b/Gemfile index c5ca17a..c5f0536 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,4 @@ source 'https://rubygems.org' +# Specify your gem's dependencies in jwt_claims.gemspec gemspec - -gem 'pry-byebug', '~> 3.1', require: false -gem 'simplecov', '~> 0.10', require: false -gem 'yard', '~> 0.8', require: false diff --git a/README.md b/README.md index 375230f..d277ec2 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,14 @@ Please refer to the [JSON Web Token][json_web_token] gem for additional guidance Example ```ruby - -secure_jwt_example = 'eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt.cGxlLmNvbS9pc19yb290Ijp0cnVlfQ.dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk' - -# verify with default algorithm, HMAC SHA256 -{:ok, verified_claims} = JwtClaims.verify(secure_jwt_example, key: 'gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C') - +# An example using the 'Expires' `exp` claim (10 years for this example). +> jwt = JsonWebToken.sign({foo: 'bar', exp: Time.now.to_i + 315360000}, key: 'gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C') +#=> "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJleHAiOjE3OTEyMjc1MTl9.7cT7PzsT8Jv0VQIxokjk3sUqzJCxBR4h3W2uACQ-tW0" + +# Verify with default algorithm, HMAC SHA256 +# Returns a hash of `{:ok, verified_claims}` +> JwtClaims.verify(jwt, key: 'gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C') +#=> {:ok=>{:foo=>"bar", :exp=>1475870843}} ``` ### Supported registered claims diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..4bf5d40 --- /dev/null +++ b/Rakefile @@ -0,0 +1,10 @@ +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' +require 'yard' +require 'wwtd/tasks' + +RSpec::Core::RakeTask.new(:spec) + +YARD::Rake::YardocTask.new + +task default: :spec diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..41dcbb2 --- /dev/null +++ b/bin/console @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby + +require 'bundler/setup' +require 'jwt_claims' + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +require 'pry' +Pry.start diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/jwt_claims.gemspec b/jwt_claims.gemspec index e42e0ef..222a5e1 100644 --- a/jwt_claims.gemspec +++ b/jwt_claims.gemspec @@ -1,21 +1,36 @@ -# -*- encoding: utf-8 -*- -$:.push File.expand_path("../lib", __FILE__) +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'jwt_claims/version' Gem::Specification.new do |s| - s.author = 'Gary Fleshman' - s.email = 'gfleshman@newforge-tech.com' - s.files = `git ls-files`.split("\n") - s.homepage = 'https://github.com/garyf/jwt_claims' - s.name = 'jwt_claims' + s.name = 'jwt_claims' + s.version = JwtClaims::VERSION + s.authors = ['Gary Fleshman'] + s.email = ['gfleshman@newforge-tech.com'] + + s.summary = 'JSON Web Token (JWT) Claims for Ruby' + s.description = 'Modular implementation of JSON Web Token (JWT) Claims' + s.homepage = 'https://github.com/garyf/jwt_claims' + s.license = 'MIT' + + s.files = `git ls-files -z`.split("\x0").reject do |f| + f.match(%r{^(test|spec|features)/}) + end + + s.require_paths = ['lib'] + s.platform = Gem::Platform::RUBY - s.summary = 'JSON Web Token (JWT) Claims for Ruby' - s.version = JwtClaims::VERSION - # recommended - s.license = 'MIT' - # optional - s.add_runtime_dependency('json_web_token', '~> 0.3') - s.add_development_dependency('rspec', '~> 3.3') - s.description = 'Modular implementation of JSON Web Token (JWT) Claims' s.required_ruby_version = '>= 2.0.0' + + s.add_runtime_dependency('json_web_token', '~> 0.3') + + s.add_development_dependency 'bundler', '~> 1.13' + s.add_development_dependency 'rake', '~> 10.0' + s.add_development_dependency 'rspec', '~> 3.0' + s.add_development_dependency 'pry', '~> 0.10' + s.add_development_dependency 'pry-byebug', '~> 3.4' + s.add_development_dependency 'simplecov', '~> 0.12' + s.add_development_dependency 'yard', '~> 0.9' + s.add_development_dependency 'wwtd', '~> 1.3' end diff --git a/lib/jwt_claims/claim/exp.rb b/lib/jwt_claims/claim/exp.rb index f78cc9c..a46b0fc 100644 --- a/lib/jwt_claims/claim/exp.rb +++ b/lib/jwt_claims/claim/exp.rb @@ -1,3 +1,5 @@ +require 'jwt_claims/util' + module JwtClaims module Claim # Expiration time diff --git a/lib/jwt_claims/claim/nbf.rb b/lib/jwt_claims/claim/nbf.rb index 6c511e8..cebdab2 100644 --- a/lib/jwt_claims/claim/nbf.rb +++ b/lib/jwt_claims/claim/nbf.rb @@ -1,3 +1,5 @@ +require 'jwt_claims/util' + module JwtClaims module Claim # Not before diff --git a/lib/jwt_claims/validation.rb b/lib/jwt_claims/validation.rb index 0a9e224..c938f76 100644 --- a/lib/jwt_claims/validation.rb +++ b/lib/jwt_claims/validation.rb @@ -1,3 +1,11 @@ +require 'jwt_claims/claim/aud' +require 'jwt_claims/claim/exp' +require 'jwt_claims/claim/iat' +require 'jwt_claims/claim/iss' +require 'jwt_claims/claim/jti' +require 'jwt_claims/claim/nbf' +require 'jwt_claims/claim/sub' + module JwtClaims # Validate registered claims # @see http://tools.ietf.org/html/rfc7519#section-4.1 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3d06978..4534a89 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -49,7 +49,7 @@ # Allows RSpec to persist some state between runs in order to support the # `--only-failures` and `--next-failure` CLI options. We recommend you # configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" + config.example_status_persistence_file_path = 'spec/examples.txt' # Limits the available syntax to the non-monkey patched syntax that is # recommended. For more details, see: