Skip to content

Commit

Permalink
Merge 755abc2 into 298d587
Browse files Browse the repository at this point in the history
  • Loading branch information
jpickwell committed Oct 18, 2018
2 parents 298d587 + 755abc2 commit 71d1a09
Show file tree
Hide file tree
Showing 18 changed files with 381 additions and 307 deletions.
18 changes: 12 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
*.gem
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
*.gem

/.yardoc/
/_yardoc/
/doc/

/.bundle/

Gemfile.lock

.idea/
*.iml
56 changes: 50 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,57 @@
---
require: rubocop-rspec

AllCops:
DefaultFormatter: progress
DisplayCopNames: true
DisplayStyleGuide: false
ExtraDetails: true
TargetRubyVersion: 2.5

################################### Bundler ####################################

################################### Gemspec ####################################

#################################### Layout ####################################

##################################### Lint #####################################

################################### Metrics ####################################

Metrics/BlockLength:
Exclude:
- spec/**/*
Enabled: false

Metrics/MethodLength:
Enabled: false

#################################### Naming ####################################

LineLength:
Naming/FileName:
Exclude:
- spec/**/*
- lib/doorkeeper-jwt.rb

StringLiterals:
Enabled: false
################################# Performance ##################################

#################################### Rails #####################################

################################### Security ###################################

#################################### Style #####################################

Style/Documentation:
Enabled: false

Style/StringLiterals:
EnforcedStyle: double_quotes

################################### Capybara ###################################

################################## FactoryBot ##################################

#################################### RSpec #####################################

RSpec/ExampleLength:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false
15 changes: 11 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
project adheres to [Semantic Versioning](http://semver.org/).

## [0.4.0] - 2018-10-18

### Changed

- Restructured library files to follow naming conventions. (https://guides.rubygems.org/name-your-gem/).

## [0.3.0] - 2018-10-01

### Added

- Bump JWT gem version. Via [#27](https://github.com/doorkeeper-gem/doorkeeper-jwt/pull/27) by [@pacop](https://github.com/pacop/)
- Bump JWT gem version. Via [#27](https://github.com/doorkeeper-gem/doorkeeper-jwt/pull/27) by [@pacop](https://github.com/pacop/).

## [0.2.1] - 2017-06-07

Expand All @@ -20,4 +26,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- Added support for ["kid" (Key ID) Header Parameter](https://tools.ietf.org/html/rfc7515#section-4.1.4) @travisofthenorth. Allows custom token headers.
- Added support for ["kid" (Key ID) Header Parameter](https://tools.ietf.org/html/rfc7515#section-4.1.4)
@travisofthenorth. Allows custom token headers.
8 changes: 6 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
source 'https://rubygems.org'
# frozen_string_literal: true

source "https://rubygems.org"

# Specify your gem's dependencies in doorkeeper-jwt.gemspec
gemspec

gem 'coveralls', require: false
gem "coveralls", require: false
gem "rubocop", "~> 0.59.2", require: false
gem "rubocop-rspec", "~> 1.30", require: false
48 changes: 23 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ Then add a `Doorkeeper::JWT.configure` block below the `Doorkeeper.configure` bl
```ruby
Doorkeeper::JWT.configure do
# Set the payload for the JWT token. This should contain unique information
# about the user.
# Defaults to a randomly generated token in a hash
# { token: "RANDOM-TOKEN" }
# about the user. Defaults to a randomly generated token in a hash:
# { token: "RANDOM-TOKEN" }
token_payload do |opts|
user = User.find(opts[:resource_owner_id])

{
iss: 'My App',
iat: Time.current.utc.to_i,
jti: SecureRandom.uuid, # @see JWT reserved claims - https://tools.ietf.org/html/draft-jones-json-web-token-07#page-7

# @see JWT reserved claims - https://tools.ietf.org/html/draft-jones-json-web-token-07#page-7
jti: SecureRandom.uuid,

user: {
id: user.id,
Expand All @@ -59,47 +60,44 @@ Doorkeeper::JWT.configure do
}
end

# Optionally set additional headers for the JWT. See https://tools.ietf.org/html/rfc7515#section-4.1
# Optionally set additional headers for the JWT. See
# https://tools.ietf.org/html/rfc7515#section-4.1
token_headers do |opts|
{
kid: opts[:application][:uid]
}
{ kid: opts[:application][:uid] }
end

# Use the application secret specified in the Access Grant token
# Defaults to false
# If you specify `use_application_secret true`, both secret_key and secret_key_path will be ignored
# Use the application secret specified in the access grant token. Defaults to
# `false`. If you specify `use_application_secret true`, both `secret_key` and
# `secret_key_path` will be ignored.
use_application_secret false

# Set the encryption secret. This would be shared with any other applications
# that should be able to read the payload of the token.
# Defaults to "secret"
# that should be able to read the payload of the token. Defaults to "secret".
secret_key ENV['JWT_SECRET']

# If you want to use RS* encoding specify the path to the RSA key
# to use for signing.
# If you specify a secret_key_path it will be used instead of secret_key
# If you want to use RS* encoding specify the path to the RSA key to use for
# signing. If you specify a `secret_key_path` it will be used instead of
# `secret_key`.
secret_key_path File.join('path', 'to', 'file.pem')

# Specify encryption type. Supports any algorithm in
# https://github.com/progrium/ruby-jwt
# defaults to nil
# Specify encryption type (https://github.com/progrium/ruby-jwt). Defaults to
# `nil`.
encryption_method :hs512
end
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive
prompt that will allow you to experiment.
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt
that will allow you to experiment.

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` to create a git tag for the
version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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` to create a git tag for the version, push git
commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

1. Fork it ( https://github.com/[my-github-username]/doorkeeper-jwt/fork )
1. Fork it (https://github.com/[my-github-username]/doorkeeper-jwt/fork)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"

Expand Down
5 changes: 4 additions & 1 deletion bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "doorkeeper-jwt"
Expand All @@ -7,8 +8,10 @@ require "doorkeeper-jwt"
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# require 'pry'
#
# Pry.start

require "irb"

IRB.start
5 changes: 3 additions & 2 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash
#!/usr/bin/env bash

set -euo pipefail
IFS=$'\n\t'

bundle install

# Do any other automated setup that you need to do here
# Do any other automated setup that you need to do here.
34 changes: 19 additions & 15 deletions doorkeeper-jwt.gemspec
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
lib = File.expand_path('lib', __dir__)
# frozen_string_literal: true

lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'doorkeeper-jwt/version'

require "doorkeeper/jwt/version"

Gem::Specification.new do |spec|
spec.name = "doorkeeper-jwt"
spec.version = Doorkeeper::JWT.gem_version
spec.authors = ["Chris Warren"]
spec.email = ["chris@expectless.com"]
spec.name = "doorkeeper-jwt"
spec.version = Doorkeeper::JWT::VERSION
spec.authors = ["Chris Warren"]
spec.email = ["chris@expectless.com"]

spec.summary = 'JWT token generator for Doorkeeper'
spec.description = 'JWT token generator extension for Doorkeeper'
spec.homepage = "https://github.com/chriswarren/doorkeeper-jwt"
spec.license = "MIT"
spec.summary = "JWT token generator for Doorkeeper"
spec.description = "JWT token generator extension for Doorkeeper"
spec.homepage = "https://github.com/chriswarren/doorkeeper-jwt"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency "jwt", "~> 2.1.0", ">= 2.1.0"
spec.add_dependency "jwt", "~> 2.1"

spec.add_development_dependency "bundler", "~> 1.8", ">= 1.8"
spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "pry", "~> 0"
spec.add_development_dependency "rake", "~> 10.0", ">= 10.0"
spec.add_development_dependency "rspec", "~> 3.2.0", ">= 3.2"
spec.add_development_dependency "rake", "~> 12.3"
spec.add_development_dependency "rspec", "~> 3.8"
end
3 changes: 0 additions & 3 deletions lib/doorkeeper-jwt/doorkeeper-jwt.rb

This file was deleted.

20 changes: 0 additions & 20 deletions lib/doorkeeper-jwt/version.rb

This file was deleted.

25 changes: 15 additions & 10 deletions lib/doorkeeper-jwt.rb → lib/doorkeeper/jwt.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require "doorkeeper-jwt/version"
require "doorkeeper-jwt/config"
require 'jwt'
require "doorkeeper/jwt/version"
require "doorkeeper/jwt/config"
require "jwt"

module Doorkeeper
module JWT
Expand All @@ -19,11 +19,11 @@ def generate(opts = {})
private

def token_payload(opts = {})
Doorkeeper::JWT.configuration.token_payload.call opts
Doorkeeper::JWT.configuration.token_payload.call(opts)
end

def token_headers(opts = {})
Doorkeeper::JWT.configuration.token_headers.call opts
Doorkeeper::JWT.configuration.token_headers.call(opts)
end

def secret_key(opts)
Expand All @@ -33,6 +33,7 @@ def secret_key(opts)
return secret_key_file unless secret_key_file.nil?
return rsa_key if rsa_encryption?
return ecdsa_key if ecdsa_encryption?

Doorkeeper::JWT.configuration.secret_key
end

Expand All @@ -44,6 +45,7 @@ def secret_key_file

def encryption_method
return "none" unless Doorkeeper::JWT.configuration.encryption_method

Doorkeeper::JWT.configuration.encryption_method.to_s.upcase
end

Expand All @@ -53,14 +55,17 @@ def use_application_secret?

def application_secret(opts)
if opts[:application].nil?
raise "JWT `use_application_secret` is enabled but application is " \
"nil. This can happen if `client_id` was absent in the request " \
"params."
raise(
"JWT `use_application_secret` is enabled, but application is nil." \
" This can happen if `client_id` was absent in the request params."
)
end

if opts[:application][:secret].nil?
raise "JWT `use_application_secret` is enabled but the application " \
"secret is nil."
raise(
"JWT `use_application_secret` is enabled, but the application" \
" secret is nil."
)
end

opts[:application][:secret]
Expand Down

0 comments on commit 71d1a09

Please sign in to comment.