doorkeeper-jwt 0.2.1 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/ci.yml +38 -0
- data/.gitignore +12 -5
- data/.hound.yml +3 -0
- data/.rubocop.yml +62 -0
- data/CHANGELOG.md +29 -3
- data/Gemfile +6 -3
- data/README.md +37 -30
- data/Rakefile +4 -2
- data/bin/console +4 -1
- data/bin/setup +3 -2
- data/doorkeeper-jwt.gemspec +21 -18
- data/lib/doorkeeper/jwt/config.rb +140 -0
- data/lib/doorkeeper/jwt/version.rb +20 -0
- data/lib/{doorkeeper-jwt.rb → doorkeeper/jwt.rb} +32 -13
- metadata +30 -46
- data/.travis.yml +0 -6
- data/lib/doorkeeper-jwt/config.rb +0 -137
- data/lib/doorkeeper-jwt/doorkeeper-jwt.rb +0 -1
- data/lib/doorkeeper-jwt/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e221c6342513368dcb299a24749a66fe45936fd1eef1ab3e93d1b34b7d0a89ca
|
4
|
+
data.tar.gz: 976256cc0a811b02e0ae9738842f99a8ccc57a054f8adea6fce9072db40cc390
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca803cc8cff761b4c2e7eddeeb2bf673ff3c4b32bdad377149904504c4d4dcc411dbe7bdfac7ac87f7deebe6e61a309ca983eb42c348e904265b3086311eccb3
|
7
|
+
data.tar.gz: e4c2690b4ddc8d0ace06d44659a7a91480f452394e8a6f7781c4dc4cd057101d38968559751ee15abcacf1ccdb49da05ad80a4ff0efd4c4c90527b013c35bffd
|
@@ -0,0 +1,38 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
name: >-
|
8
|
+
Ruby ${{ matrix.ruby }}
|
9
|
+
env:
|
10
|
+
CI: true
|
11
|
+
runs-on: ${{ matrix.os }}
|
12
|
+
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' || matrix.experimental }}
|
13
|
+
if: |
|
14
|
+
!( contains(github.event.pull_request.title, '[ci skip]')
|
15
|
+
|| contains(github.event.pull_request.title, '[skip ci]'))
|
16
|
+
strategy:
|
17
|
+
fail-fast: true
|
18
|
+
matrix:
|
19
|
+
experimental: [false]
|
20
|
+
os: [ ubuntu-latest ]
|
21
|
+
ruby:
|
22
|
+
- 2.6
|
23
|
+
- 2.7
|
24
|
+
- '3.0'
|
25
|
+
- '3.1'
|
26
|
+
steps:
|
27
|
+
- name: Repo checkout
|
28
|
+
uses: actions/checkout@v2
|
29
|
+
|
30
|
+
- name: Setup Ruby
|
31
|
+
uses: ruby/setup-ruby@v1
|
32
|
+
with:
|
33
|
+
ruby-version: ${{ matrix.ruby }}
|
34
|
+
bundler-cache: true
|
35
|
+
|
36
|
+
- name: Run tests
|
37
|
+
timeout-minutes: 10
|
38
|
+
run: bundle exec rake test
|
data/.gitignore
CHANGED
data/.hound.yml
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
---
|
2
|
+
require: rubocop-rspec
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
DefaultFormatter: progress
|
6
|
+
DisplayCopNames: true
|
7
|
+
DisplayStyleGuide: false
|
8
|
+
ExtraDetails: true
|
9
|
+
TargetRubyVersion: 2.5
|
10
|
+
|
11
|
+
Metrics/LineLength:
|
12
|
+
Exclude:
|
13
|
+
- spec/**/*
|
14
|
+
Max: 100
|
15
|
+
|
16
|
+
Metrics/BlockLength:
|
17
|
+
Exclude:
|
18
|
+
- spec/**/*
|
19
|
+
- doorkeeper-jwt.gemspec
|
20
|
+
|
21
|
+
Style/StringLiterals:
|
22
|
+
EnforcedStyle: double_quotes
|
23
|
+
Style/StringLiteralsInInterpolation:
|
24
|
+
EnforcedStyle: double_quotes
|
25
|
+
|
26
|
+
Style/FrozenStringLiteralComment:
|
27
|
+
Enabled: true
|
28
|
+
|
29
|
+
Style/TrailingCommaInHashLiteral:
|
30
|
+
EnforcedStyleForMultiline: consistent_comma
|
31
|
+
Style/TrailingCommaInArrayLiteral:
|
32
|
+
EnforcedStyleForMultiline: consistent_comma
|
33
|
+
|
34
|
+
Style/SymbolArray:
|
35
|
+
MinSize: 3
|
36
|
+
Style/WordArray:
|
37
|
+
MinSize: 3
|
38
|
+
|
39
|
+
Style/ClassAndModuleChildren:
|
40
|
+
Exclude:
|
41
|
+
- spec/**/*
|
42
|
+
Style/NumericPredicate:
|
43
|
+
Enabled: false
|
44
|
+
Style/DoubleNegation:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Layout/MultilineMethodCallIndentation:
|
48
|
+
EnforcedStyle: indented
|
49
|
+
Layout/TrailingBlankLines:
|
50
|
+
Enabled: true
|
51
|
+
Layout/DotPosition:
|
52
|
+
EnforcedStyle: leading
|
53
|
+
|
54
|
+
Naming/FileName:
|
55
|
+
Exclude:
|
56
|
+
- lib/doorkeeper-jwt.rb
|
57
|
+
|
58
|
+
RSpec/ExampleLength:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
RSpec/MultipleExpectations:
|
62
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,39 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
|
-
|
4
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
|
5
|
+
project adheres to [Semantic Versioning](http://semver.org/).
|
6
|
+
|
7
|
+
## master
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
|
11
|
+
## [0.4.1] - 2022-02-23
|
12
|
+
|
13
|
+
- JWT gem requirement relaxed to use any version >= 2.1
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
## [0.4.0] - 2019-10-02
|
18
|
+
|
19
|
+
- Restructured library files to follow naming conventions. (https://guides.rubygems.org/name-your-gem/).
|
20
|
+
- Add support of new doorkeeper with encryption [#30](https://github.com/doorkeeper-gem/doorkeeper-jwt/pull/30)
|
21
|
+
|
22
|
+
## [0.3.0] - 2018-10-01
|
23
|
+
|
24
|
+
### Added
|
25
|
+
|
26
|
+
- Bump JWT gem version. Via [#27](https://github.com/doorkeeper-gem/doorkeeper-jwt/pull/27) by [@pacop](https://github.com/pacop/).
|
6
27
|
|
7
28
|
## [0.2.1] - 2017-06-07
|
29
|
+
|
8
30
|
### Fixed
|
31
|
+
|
9
32
|
- The `token_headers` proc now passes `opts` like the other config methods. Fixed via #19 by @travisofthenorth.
|
10
33
|
|
11
34
|
## [0.2.0] - 2017-05-25
|
35
|
+
|
12
36
|
### Added
|
13
|
-
|
37
|
+
|
38
|
+
- Added support for ["kid" (Key ID) Header Parameter](https://tools.ietf.org/html/rfc7515#section-4.1.4)
|
39
|
+
@travisofthenorth. Allows custom token headers.
|
data/Gemfile
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in doorkeeper-jwt.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
|
-
gem
|
7
|
-
gem "
|
8
|
+
gem "coveralls", require: false
|
9
|
+
gem "rubocop", "~> 1.8", require: false
|
10
|
+
gem "rubocop-rspec", "~> 2.1", require: false
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
[![
|
2
|
-
[![
|
3
|
-
[![
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/doorkeeper-jwt.svg)](https://rubygems.org/gems/doorkeeper-jwt)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/github/doorkeeper-gem/doorkeeper-jwt/badge.svg?branch=master)](https://coveralls.io/github/doorkeeper-gem/doorkeeper-jwt?branch=master)
|
3
|
+
[![Build Status](https://travis-ci.org/doorkeeper-gem/doorkeeper-jwt.svg?branch=master)](https://travis-ci.org/doorkeeper-gem/doorkeeper-jwt)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/ca4d81b49acabda27e0c/maintainability)](https://codeclimate.com/github/doorkeeper-gem/doorkeeper-jwt/maintainability)
|
4
5
|
|
5
6
|
# Doorkeeper::JWT
|
6
7
|
|
7
|
-
Doorkeeper JWT adds JWT token support to the Doorkeeper OAuth library.
|
8
|
+
Doorkeeper JWT adds JWT token support to the Doorkeeper OAuth library. Confirmed to work with Doorkeeper 2.2.x - 4.x.
|
9
|
+
Untested with later versions of Doorkeeper.
|
8
10
|
|
9
11
|
```ruby
|
10
12
|
gem 'doorkeeper'
|
@@ -31,7 +33,7 @@ Or install it yourself as:
|
|
31
33
|
In your `doorkeeper.rb` initializer add the follow to the `Doorkeeper.configure` block:
|
32
34
|
|
33
35
|
```ruby
|
34
|
-
access_token_generator
|
36
|
+
access_token_generator '::Doorkeeper::JWT'
|
35
37
|
```
|
36
38
|
|
37
39
|
Then add a `Doorkeeper::JWT.configure` block below the `Doorkeeper.configure` block to set your JWT preferences.
|
@@ -39,13 +41,18 @@ Then add a `Doorkeeper::JWT.configure` block below the `Doorkeeper.configure` bl
|
|
39
41
|
```ruby
|
40
42
|
Doorkeeper::JWT.configure do
|
41
43
|
# Set the payload for the JWT token. This should contain unique information
|
42
|
-
# about the user.
|
43
|
-
#
|
44
|
-
# { token: "RANDOM-TOKEN" }
|
44
|
+
# about the user. Defaults to a randomly generated token in a hash:
|
45
|
+
# { token: "RANDOM-TOKEN" }
|
45
46
|
token_payload do |opts|
|
46
47
|
user = User.find(opts[:resource_owner_id])
|
47
48
|
|
48
49
|
{
|
50
|
+
iss: 'My App',
|
51
|
+
iat: Time.current.utc.to_i,
|
52
|
+
|
53
|
+
# @see JWT reserved claims - https://tools.ietf.org/html/draft-jones-json-web-token-07#page-7
|
54
|
+
jti: SecureRandom.uuid,
|
55
|
+
|
49
56
|
user: {
|
50
57
|
id: user.id,
|
51
58
|
email: user.email
|
@@ -53,44 +60,44 @@ Doorkeeper::JWT.configure do
|
|
53
60
|
}
|
54
61
|
end
|
55
62
|
|
56
|
-
# Optionally set additional headers for the JWT. See
|
63
|
+
# Optionally set additional headers for the JWT. See
|
64
|
+
# https://tools.ietf.org/html/rfc7515#section-4.1
|
57
65
|
token_headers do |opts|
|
58
|
-
{
|
59
|
-
kid: opts[:application][:uid]
|
60
|
-
}
|
66
|
+
{ kid: opts[:application][:uid] }
|
61
67
|
end
|
62
68
|
|
63
|
-
# Use the application secret specified in the
|
64
|
-
#
|
65
|
-
#
|
69
|
+
# Use the application secret specified in the access grant token. Defaults to
|
70
|
+
# `false`. If you specify `use_application_secret true`, both `secret_key` and
|
71
|
+
# `secret_key_path` will be ignored.
|
66
72
|
use_application_secret false
|
67
73
|
|
68
74
|
# Set the encryption secret. This would be shared with any other applications
|
69
|
-
# that should be able to read the payload of the token.
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
# If you
|
74
|
-
#
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
#
|
79
|
-
# https://github.com/progrium/ruby-jwt
|
80
|
-
# defaults to nil
|
75
|
+
# that should be able to read the payload of the token. Defaults to "secret".
|
76
|
+
secret_key ENV['JWT_SECRET']
|
77
|
+
|
78
|
+
# If you want to use RS* encoding specify the path to the RSA key to use for
|
79
|
+
# signing. If you specify a `secret_key_path` it will be used instead of
|
80
|
+
# `secret_key`.
|
81
|
+
secret_key_path File.join('path', 'to', 'file.pem')
|
82
|
+
|
83
|
+
# Specify encryption type (https://github.com/progrium/ruby-jwt). Defaults to
|
84
|
+
# `nil`.
|
81
85
|
encryption_method :hs512
|
82
86
|
end
|
83
87
|
```
|
84
88
|
|
85
89
|
## Development
|
86
90
|
|
87
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt
|
91
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt
|
92
|
+
that will allow you to experiment.
|
88
93
|
|
89
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
94
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
95
|
+
version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git
|
96
|
+
commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
90
97
|
|
91
98
|
## Contributing
|
92
99
|
|
93
|
-
1. Fork it (
|
100
|
+
1. Fork it (https://github.com/[my-github-username]/doorkeeper-jwt/fork)
|
94
101
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
95
102
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
96
103
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "bundler/setup"
|
4
5
|
require "doorkeeper-jwt"
|
@@ -7,8 +8,10 @@ require "doorkeeper-jwt"
|
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
8
9
|
|
9
10
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require
|
11
|
+
# require 'pry'
|
12
|
+
#
|
11
13
|
# Pry.start
|
12
14
|
|
13
15
|
require "irb"
|
16
|
+
|
14
17
|
IRB.start
|
data/bin/setup
CHANGED
data/doorkeeper-jwt.gemspec
CHANGED
@@ -1,28 +1,31 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
5
|
+
|
6
|
+
require "doorkeeper/jwt/version"
|
5
7
|
|
6
8
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
9
|
+
spec.name = "doorkeeper-jwt"
|
10
|
+
spec.version = Doorkeeper::JWT.gem_version
|
11
|
+
spec.authors = ["Chris Warren", "Nikita Bulai"]
|
12
|
+
spec.email = ["chris@expectless.com"]
|
11
13
|
|
12
|
-
spec.summary
|
13
|
-
spec.description
|
14
|
-
spec.homepage
|
15
|
-
spec.license
|
14
|
+
spec.summary = "JWT token generator for Doorkeeper"
|
15
|
+
spec.description = "JWT token generator extension for Doorkeeper"
|
16
|
+
spec.homepage = "https://github.com/chriswarren/doorkeeper-jwt"
|
17
|
+
spec.license = "MIT"
|
16
18
|
|
17
|
-
spec.
|
18
|
-
spec.
|
19
|
-
spec.executables
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
23
|
spec.require_paths = ["lib"]
|
21
24
|
|
22
|
-
spec.add_dependency "jwt", "
|
25
|
+
spec.add_dependency "jwt", ">= 2.1"
|
23
26
|
|
24
|
-
spec.add_development_dependency "bundler", "
|
25
|
-
spec.add_development_dependency "rake", "~> 10.0", ">= 10.0"
|
26
|
-
spec.add_development_dependency "rspec", "~> 3.2.0", ">= 3.2"
|
27
|
+
spec.add_development_dependency "bundler", ">= 1.16", "< 3"
|
27
28
|
spec.add_development_dependency "pry", "~> 0"
|
29
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
28
31
|
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Doorkeeper
|
4
|
+
module JWT
|
5
|
+
class MissingConfiguration < StandardError
|
6
|
+
def initialize
|
7
|
+
super("Configuration for doorkeeper-jwt missing.")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure(&block)
|
12
|
+
@config = Config::Builder.new(&block).build
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configuration
|
16
|
+
@config || raise(MissingConfiguration)
|
17
|
+
end
|
18
|
+
|
19
|
+
class Config
|
20
|
+
class Builder
|
21
|
+
def initialize(&block)
|
22
|
+
@config = Config.new
|
23
|
+
instance_eval(&block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def build
|
27
|
+
@config
|
28
|
+
end
|
29
|
+
|
30
|
+
def use_application_secret(value)
|
31
|
+
@config.instance_variable_set("@use_application_secret", value)
|
32
|
+
end
|
33
|
+
|
34
|
+
def secret_key(value)
|
35
|
+
@config.instance_variable_set("@secret_key", value)
|
36
|
+
end
|
37
|
+
|
38
|
+
def secret_key_path(value)
|
39
|
+
@config.instance_variable_set("@secret_key_path", value)
|
40
|
+
end
|
41
|
+
|
42
|
+
def encryption_method(value)
|
43
|
+
@config.instance_variable_set("@encryption_method", value)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module Option
|
48
|
+
# Defines configuration options.
|
49
|
+
#
|
50
|
+
# When you call option, it defines two methods. One method will take
|
51
|
+
# place in the +Config+ class and the other method will take place in
|
52
|
+
# the +Builder+ class.
|
53
|
+
#
|
54
|
+
# The +name+ parameter will set both builder method and config
|
55
|
+
# attribute. If the +:as+ option is defined, the builder method will be
|
56
|
+
# the specified option while the config attribute will be the +name+
|
57
|
+
# parameter.
|
58
|
+
#
|
59
|
+
# If you want to introduce another level of config DSL you can define
|
60
|
+
# +builder_class+ parameter. Builder should take a block as the
|
61
|
+
# initializer parameter and respond to function +build+ that returns the
|
62
|
+
# value of the config attribute.
|
63
|
+
#
|
64
|
+
# ==== Options
|
65
|
+
#
|
66
|
+
# * [+:as+] Set the builder method that goes inside +configure+ block.
|
67
|
+
# * [+:default+] The default value in case no option was set.
|
68
|
+
#
|
69
|
+
# ==== Examples
|
70
|
+
#
|
71
|
+
# option :name
|
72
|
+
# option :name, as: :set_name
|
73
|
+
# option :name, default: 'My Name'
|
74
|
+
# option :scopes, builder_class: ScopesBuilder
|
75
|
+
def option(name, options = {})
|
76
|
+
attribute = options[:as] || name
|
77
|
+
attribute_builder = options[:builder_class]
|
78
|
+
attribute_symbol = :"@#{attribute}"
|
79
|
+
|
80
|
+
Builder.instance_eval do
|
81
|
+
define_method name do |*args, &block|
|
82
|
+
# TODO: is builder_class option being used?
|
83
|
+
value =
|
84
|
+
if attribute_builder
|
85
|
+
attribute_builder.new(&block).build
|
86
|
+
else
|
87
|
+
block || args.first
|
88
|
+
end
|
89
|
+
|
90
|
+
@config.instance_variable_set(attribute_symbol, value)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
define_method attribute do |*|
|
95
|
+
if instance_variable_defined?(attribute_symbol)
|
96
|
+
instance_variable_get(attribute_symbol)
|
97
|
+
else
|
98
|
+
options[:default]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
public attribute
|
103
|
+
end
|
104
|
+
|
105
|
+
def extended(base)
|
106
|
+
base.send(:private, :option)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
extend Option
|
111
|
+
|
112
|
+
option(
|
113
|
+
:token_payload,
|
114
|
+
default: proc { { token: SecureRandom.method(:hex) } }
|
115
|
+
)
|
116
|
+
|
117
|
+
option :token_headers, default: proc { {} }
|
118
|
+
option :use_application_secret, default: false
|
119
|
+
option :secret_key, default: nil
|
120
|
+
option :secret_key_path, default: nil
|
121
|
+
option :encryption_method, default: nil
|
122
|
+
|
123
|
+
def use_application_secret
|
124
|
+
@use_application_secret ||= false
|
125
|
+
end
|
126
|
+
|
127
|
+
def secret_key
|
128
|
+
@secret_key ||= nil
|
129
|
+
end
|
130
|
+
|
131
|
+
def secret_key_path
|
132
|
+
@secret_key_path ||= nil
|
133
|
+
end
|
134
|
+
|
135
|
+
def encryption_method
|
136
|
+
@encryption_method ||= nil
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Doorkeeper
|
4
|
+
module JWT
|
5
|
+
def self.gem_version
|
6
|
+
Gem::Version.new VERSION::STRING
|
7
|
+
end
|
8
|
+
|
9
|
+
module VERSION
|
10
|
+
# Semantic versioning
|
11
|
+
MAJOR = 0
|
12
|
+
MINOR = 4
|
13
|
+
TINY = 1
|
14
|
+
PRE = nil
|
15
|
+
|
16
|
+
# Full version number
|
17
|
+
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "doorkeeper/jwt/version"
|
4
|
+
require "doorkeeper/jwt/config"
|
5
|
+
require "jwt"
|
4
6
|
|
5
7
|
module Doorkeeper
|
6
8
|
module JWT
|
@@ -17,11 +19,11 @@ module Doorkeeper
|
|
17
19
|
private
|
18
20
|
|
19
21
|
def token_payload(opts = {})
|
20
|
-
Doorkeeper::JWT.configuration.token_payload.call
|
22
|
+
Doorkeeper::JWT.configuration.token_payload.call(opts)
|
21
23
|
end
|
22
24
|
|
23
25
|
def token_headers(opts = {})
|
24
|
-
Doorkeeper::JWT.configuration.token_headers.call
|
26
|
+
Doorkeeper::JWT.configuration.token_headers.call(opts)
|
25
27
|
end
|
26
28
|
|
27
29
|
def secret_key(opts)
|
@@ -31,6 +33,7 @@ module Doorkeeper
|
|
31
33
|
return secret_key_file unless secret_key_file.nil?
|
32
34
|
return rsa_key if rsa_encryption?
|
33
35
|
return ecdsa_key if ecdsa_encryption?
|
36
|
+
|
34
37
|
Doorkeeper::JWT.configuration.secret_key
|
35
38
|
end
|
36
39
|
|
@@ -41,7 +44,8 @@ module Doorkeeper
|
|
41
44
|
end
|
42
45
|
|
43
46
|
def encryption_method
|
44
|
-
return
|
47
|
+
return "none" unless Doorkeeper::JWT.configuration.encryption_method
|
48
|
+
|
45
49
|
Doorkeeper::JWT.configuration.encryption_method.to_s.upcase
|
46
50
|
end
|
47
51
|
|
@@ -51,17 +55,32 @@ module Doorkeeper
|
|
51
55
|
|
52
56
|
def application_secret(opts)
|
53
57
|
if opts[:application].nil?
|
54
|
-
|
55
|
-
"
|
56
|
-
"params."
|
58
|
+
raise(
|
59
|
+
"JWT `use_application_secret` is enabled, but application is nil." \
|
60
|
+
" This can happen if `client_id` was absent in the request params."
|
61
|
+
)
|
57
62
|
end
|
58
63
|
|
59
|
-
if opts[:application]
|
60
|
-
|
61
|
-
|
64
|
+
secret = if opts[:application].respond_to?(:plaintext_secret)
|
65
|
+
unless opts[:application].secret_strategy.allows_restoring_secrets?
|
66
|
+
raise(
|
67
|
+
"JWT `use_application_secret` is enabled, but secret strategy " \
|
68
|
+
"doesn't allow plaintext secret restoring"
|
69
|
+
)
|
70
|
+
end
|
71
|
+
opts[:application].plaintext_secret
|
72
|
+
else
|
73
|
+
opts[:application][:secret]
|
74
|
+
end
|
75
|
+
|
76
|
+
if secret.nil?
|
77
|
+
raise(
|
78
|
+
"JWT `use_application_secret` is enabled, but the application" \
|
79
|
+
" secret is nil."
|
80
|
+
)
|
62
81
|
end
|
63
82
|
|
64
|
-
|
83
|
+
secret
|
65
84
|
end
|
66
85
|
|
67
86
|
def rsa_encryption?
|
metadata
CHANGED
@@ -1,109 +1,92 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doorkeeper-jwt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Warren
|
8
|
+
- Nikita Bulai
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2022-02-23 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: jwt
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.5.2
|
20
18
|
- - ">="
|
21
19
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1
|
20
|
+
version: '2.1'
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
24
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 1.5.2
|
30
25
|
- - ">="
|
31
26
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1
|
27
|
+
version: '2.1'
|
33
28
|
- !ruby/object:Gem::Dependency
|
34
29
|
name: bundler
|
35
30
|
requirement: !ruby/object:Gem::Requirement
|
36
31
|
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '1.8'
|
40
32
|
- - ">="
|
41
33
|
- !ruby/object:Gem::Version
|
42
|
-
version: '1.
|
34
|
+
version: '1.16'
|
35
|
+
- - "<"
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3'
|
43
38
|
type: :development
|
44
39
|
prerelease: false
|
45
40
|
version_requirements: !ruby/object:Gem::Requirement
|
46
41
|
requirements:
|
47
|
-
- - "~>"
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '1.8'
|
50
42
|
- - ">="
|
51
43
|
- !ruby/object:Gem::Version
|
52
|
-
version: '1.
|
44
|
+
version: '1.16'
|
45
|
+
- - "<"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3'
|
53
48
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
49
|
+
name: pry
|
55
50
|
requirement: !ruby/object:Gem::Requirement
|
56
51
|
requirements:
|
57
52
|
- - "~>"
|
58
53
|
- !ruby/object:Gem::Version
|
59
|
-
version: '
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '10.0'
|
54
|
+
version: '0'
|
63
55
|
type: :development
|
64
56
|
prerelease: false
|
65
57
|
version_requirements: !ruby/object:Gem::Requirement
|
66
58
|
requirements:
|
67
59
|
- - "~>"
|
68
60
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
70
|
-
- - ">="
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: '10.0'
|
61
|
+
version: '0'
|
73
62
|
- !ruby/object:Gem::Dependency
|
74
|
-
name:
|
63
|
+
name: rake
|
75
64
|
requirement: !ruby/object:Gem::Requirement
|
76
65
|
requirements:
|
77
66
|
- - "~>"
|
78
67
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '3.2'
|
68
|
+
version: '13.0'
|
83
69
|
type: :development
|
84
70
|
prerelease: false
|
85
71
|
version_requirements: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
90
|
-
- - ">="
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: '3.2'
|
75
|
+
version: '13.0'
|
93
76
|
- !ruby/object:Gem::Dependency
|
94
|
-
name:
|
77
|
+
name: rspec
|
95
78
|
requirement: !ruby/object:Gem::Requirement
|
96
79
|
requirements:
|
97
80
|
- - "~>"
|
98
81
|
- !ruby/object:Gem::Version
|
99
|
-
version: '
|
82
|
+
version: '3.8'
|
100
83
|
type: :development
|
101
84
|
prerelease: false
|
102
85
|
version_requirements: !ruby/object:Gem::Requirement
|
103
86
|
requirements:
|
104
87
|
- - "~>"
|
105
88
|
- !ruby/object:Gem::Version
|
106
|
-
version: '
|
89
|
+
version: '3.8'
|
107
90
|
description: JWT token generator extension for Doorkeeper
|
108
91
|
email:
|
109
92
|
- chris@expectless.com
|
@@ -111,9 +94,12 @@ executables: []
|
|
111
94
|
extensions: []
|
112
95
|
extra_rdoc_files: []
|
113
96
|
files:
|
97
|
+
- ".github/dependabot.yml"
|
98
|
+
- ".github/workflows/ci.yml"
|
114
99
|
- ".gitignore"
|
100
|
+
- ".hound.yml"
|
115
101
|
- ".rspec"
|
116
|
-
- ".
|
102
|
+
- ".rubocop.yml"
|
117
103
|
- CHANGELOG.md
|
118
104
|
- Gemfile
|
119
105
|
- LICENSE.txt
|
@@ -122,10 +108,9 @@ files:
|
|
122
108
|
- bin/console
|
123
109
|
- bin/setup
|
124
110
|
- doorkeeper-jwt.gemspec
|
125
|
-
- lib/doorkeeper
|
126
|
-
- lib/doorkeeper
|
127
|
-
- lib/doorkeeper
|
128
|
-
- lib/doorkeeper-jwt/version.rb
|
111
|
+
- lib/doorkeeper/jwt.rb
|
112
|
+
- lib/doorkeeper/jwt/config.rb
|
113
|
+
- lib/doorkeeper/jwt/version.rb
|
129
114
|
homepage: https://github.com/chriswarren/doorkeeper-jwt
|
130
115
|
licenses:
|
131
116
|
- MIT
|
@@ -145,8 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
130
|
- !ruby/object:Gem::Version
|
146
131
|
version: '0'
|
147
132
|
requirements: []
|
148
|
-
|
149
|
-
rubygems_version: 2.6.4
|
133
|
+
rubygems_version: 3.0.8
|
150
134
|
signing_key:
|
151
135
|
specification_version: 4
|
152
136
|
summary: JWT token generator for Doorkeeper
|
data/.travis.yml
DELETED
@@ -1,137 +0,0 @@
|
|
1
|
-
module Doorkeeper
|
2
|
-
module JWT
|
3
|
-
class MissingConfiguration < StandardError
|
4
|
-
def initialize
|
5
|
-
super('Configuration for doorkeeper-jwt missing.')
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.configure(&block)
|
10
|
-
@config = Config::Builder.new(&block).build
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.configuration
|
14
|
-
@config || (fail MissingConfiguration.new)
|
15
|
-
end
|
16
|
-
|
17
|
-
class Config
|
18
|
-
class Builder
|
19
|
-
def initialize(&block)
|
20
|
-
@config = Config.new
|
21
|
-
instance_eval(&block)
|
22
|
-
end
|
23
|
-
|
24
|
-
def build
|
25
|
-
@config
|
26
|
-
end
|
27
|
-
|
28
|
-
def use_application_secret(use_application_secret)
|
29
|
-
@config.instance_variable_set(
|
30
|
-
"@use_application_secret",
|
31
|
-
use_application_secret
|
32
|
-
)
|
33
|
-
end
|
34
|
-
|
35
|
-
def secret_key(secret_key)
|
36
|
-
@config.instance_variable_set('@secret_key', secret_key)
|
37
|
-
end
|
38
|
-
|
39
|
-
def secret_key_path(secret_key_path)
|
40
|
-
@config.instance_variable_set('@secret_key_path', secret_key_path)
|
41
|
-
end
|
42
|
-
|
43
|
-
def encryption_method(encryption_method)
|
44
|
-
@config.instance_variable_set(
|
45
|
-
'@encryption_method', encryption_method)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
module Option
|
50
|
-
# Defines configuration option
|
51
|
-
#
|
52
|
-
# When you call option, it defines two methods. One method will take place
|
53
|
-
# in the +Config+ class and the other method will take place in the
|
54
|
-
# +Builder+ class.
|
55
|
-
#
|
56
|
-
# The +name+ parameter will set both builder method and config attribute.
|
57
|
-
# If the +:as+ option is defined, the builder method will be the specified
|
58
|
-
# option while the config attribute will be the +name+ parameter.
|
59
|
-
#
|
60
|
-
# If you want to introduce another level of config DSL you can
|
61
|
-
# define +builder_class+ parameter.
|
62
|
-
# Builder should take a block as the initializer parameter and respond to function +build+
|
63
|
-
# that returns the value of the config attribute.
|
64
|
-
#
|
65
|
-
# ==== Options
|
66
|
-
#
|
67
|
-
# * [:+as+] Set the builder method that goes inside +configure+ block
|
68
|
-
# * [+:default+] The default value in case no option was set
|
69
|
-
#
|
70
|
-
# ==== Examples
|
71
|
-
#
|
72
|
-
# option :name
|
73
|
-
# option :name, as: :set_name
|
74
|
-
# option :name, default: 'My Name'
|
75
|
-
# option :scopes builder_class: ScopesBuilder
|
76
|
-
#
|
77
|
-
def option(name, options = {})
|
78
|
-
attribute = options[:as] || name
|
79
|
-
attribute_builder = options[:builder_class]
|
80
|
-
|
81
|
-
Builder.instance_eval do
|
82
|
-
define_method name do |*args, &block|
|
83
|
-
# TODO: is builder_class option being used?
|
84
|
-
value = unless attribute_builder
|
85
|
-
block ? block : args.first
|
86
|
-
else
|
87
|
-
attribute_builder.new(&block).build
|
88
|
-
end
|
89
|
-
|
90
|
-
@config.instance_variable_set(:"@#{attribute}", value)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
define_method attribute do |*args|
|
95
|
-
if instance_variable_defined?(:"@#{attribute}")
|
96
|
-
instance_variable_get(:"@#{attribute}")
|
97
|
-
else
|
98
|
-
options[:default]
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
public attribute
|
103
|
-
end
|
104
|
-
|
105
|
-
def extended(base)
|
106
|
-
base.send(:private, :option)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
extend Option
|
111
|
-
|
112
|
-
option :token_payload,
|
113
|
-
default: proc{ { token: SecureRandom.method(:hex) } }
|
114
|
-
option :token_headers, default: proc { {} }
|
115
|
-
option :use_application_secret, default: false
|
116
|
-
option :secret_key, default: nil
|
117
|
-
option :secret_key_path, default: nil
|
118
|
-
option :encryption_method, default: nil
|
119
|
-
|
120
|
-
def use_application_secret
|
121
|
-
@use_application_secret ||= false
|
122
|
-
end
|
123
|
-
|
124
|
-
def secret_key
|
125
|
-
@secret_key ||= nil
|
126
|
-
end
|
127
|
-
|
128
|
-
def secret_key_path
|
129
|
-
@secret_key_path ||= nil
|
130
|
-
end
|
131
|
-
|
132
|
-
def encryption_method
|
133
|
-
@encryption_method ||= nil
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require "doorkeeper-jwt/version"
|