Skip to content
Permalink
Browse files

Restructure library files.

  • Loading branch information
jpickwell committed Oct 18, 2018
1 parent 298d587 commit 2668d521da8d401be2cb13ce3f02bc951f7d8bd7
@@ -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
@@ -0,0 +1,2 @@
rubocop:
config_file: .rubocop.yml
@@ -1,13 +1,54 @@
---
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

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

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

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

RSpec/ExampleLength:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false
@@ -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

@@ -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.
@@ -1,6 +1,10 @@
# frozen_string_literal: true

source 'https://rubygems.org'

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

gem 'coveralls', require: false
gem 'rubocop', '~> 0.59.2', require: false
gem 'rubocop-rspec', '~> 1.30', require: false
@@ -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,
@@ -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`)
@@ -1,5 +1,7 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new

@@ -1,14 +1,17 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "doorkeeper-jwt"
require 'bundler/setup'
require 'doorkeeper-jwt'

# 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.

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

require "irb"
require 'irb'

IRB.start
@@ -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.
@@ -1,27 +1,31 @@
# 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.bindir = 'exe'
spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
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 "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 'bundler', '~> 1.16'
spec.add_development_dependency 'pry', '~> 0'
spec.add_development_dependency 'rake', '~> 12.3'
spec.add_development_dependency 'rspec', '~> 3.8'
end

This file was deleted.

This file was deleted.

@@ -1,7 +1,7 @@
# frozen_string_literal: true

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

module Doorkeeper
@@ -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)
@@ -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

@@ -43,7 +44,8 @@ def secret_key_file
end

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

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

@@ -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]

0 comments on commit 2668d52

Please sign in to comment.
You can’t perform that action at this time.