doorkeeper-jwt 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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +81 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/doorkeeper-jwt.gemspec +28 -0
- data/lib/doorkeeper-jwt.rb +37 -0
- data/lib/doorkeeper-jwt/config.rb +124 -0
- data/lib/doorkeeper-jwt/doorkeeper-jwt.rb +1 -0
- data/lib/doorkeeper-jwt/version.rb +5 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1791769530ac6ad399efbb8a26146c17e2348ec9
|
4
|
+
data.tar.gz: 473b621043f01eddae55661dafce3b46b5c8e379
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ee55933a1bc248459885ef1fece175aa70feda72ac7d29027ac580db8be4f882b1a114e63de7a724c3b42b91e0ee84db52362b5cd219da0a5afaaa1780f6cd2
|
7
|
+
data.tar.gz: e0517f1209e9ee6a9b8a5b4c73ed5daf3542369367d21fcd70e0ccaaaac86515909d48b02a3c5ec9f077d5f0f8f4956ee505e8e7c4a0933baaf4fae00cb169c4
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Christopher Warren
|
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,81 @@
|
|
1
|
+
[](https://coveralls.io/r/chriswarren/doorkeeper-jwt?branch=master)
|
2
|
+
[](https://travis-ci.org/chriswarren/doorkeeper-jwt)
|
3
|
+
[](https://codeclimate.com/github/chriswarren/doorkeeper-jwt)
|
4
|
+
|
5
|
+
# Doorkeeper::JWT
|
6
|
+
|
7
|
+
Doorkeeper JWT adds JWT token support to the Doorkeeper OAuth library.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'doorkeeper-jwt'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install doorkeeper-jwt
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
In your `doorkeeper.rb` initializer add the follow to the `Doorkeeper.configure` block:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
access_token_generator "Doorkeeper::JWT"
|
31
|
+
```
|
32
|
+
|
33
|
+
Then add a `Doorkeeper::JWT.configure` block below the `Doorkeeper.configure` block to set your JWT preferences.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
Doorkeeper::JWT.configure do
|
37
|
+
# Set the payload for the JWT token. This should contain unique information
|
38
|
+
# about the user.
|
39
|
+
# Defaults to a randomly generated token in a hash
|
40
|
+
# { token: "RANDOM-TOKEN" }
|
41
|
+
payload do
|
42
|
+
{
|
43
|
+
user: {
|
44
|
+
id: 123,
|
45
|
+
first_name: "Jane",
|
46
|
+
last_name: "Doe",
|
47
|
+
email: "jdoe@example.com"
|
48
|
+
}
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
# Set the encryption secret. This would be shared with any other applications
|
53
|
+
# that should be able to read the payload of the token.
|
54
|
+
# Defaults to "secret"
|
55
|
+
secret_key "MY-SECRET"
|
56
|
+
|
57
|
+
# If you want to use RS* encoding specify the path to the RSA key
|
58
|
+
# to use for signing.
|
59
|
+
# If you specify a secret_key_path it will be used instead of secret_key
|
60
|
+
secret_key_path "path/to/file.pem"
|
61
|
+
|
62
|
+
# Specify encryption type. Supports any algorithim in
|
63
|
+
# https://github.com/progrium/ruby-jwt
|
64
|
+
# defaults to nil
|
65
|
+
encryption_method :hs512
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
## Development
|
70
|
+
|
71
|
+
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.
|
72
|
+
|
73
|
+
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).
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
1. Fork it ( https://github.com/[my-github-username]/doorkeeper-jwt/fork )
|
78
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
79
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
80
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
81
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "doorkeeper-jwt"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'doorkeeper-jwt/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "doorkeeper-jwt"
|
8
|
+
spec.version = Doorkeeper::JWT::VERSION
|
9
|
+
spec.authors = ["Chris Warren"]
|
10
|
+
spec.email = ["chris@expectless.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{JWT token generator for Doorkeeper}
|
13
|
+
spec.description = %q{JWT token generator extension for Doorkeeper}
|
14
|
+
spec.homepage = "https://github.com/chriswarren/doorkeeper-jwt"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "jwt", "~> 1.4", ">= 1.4.1"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.8", ">= 1.8"
|
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 "pry", "~> 0"
|
28
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "doorkeeper-jwt/version"
|
2
|
+
require "doorkeeper-jwt/config"
|
3
|
+
require 'jwt'
|
4
|
+
|
5
|
+
module Doorkeeper
|
6
|
+
module JWT
|
7
|
+
def self.generate(resource_owner_id)
|
8
|
+
::JWT.encode(
|
9
|
+
token_payload(resource_owner_id),
|
10
|
+
secret_key,
|
11
|
+
encryption_method
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.token_payload(resource_owner_id)
|
18
|
+
Doorkeeper::JWT.configuration.token_payload.call resource_owner_id
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.secret_key
|
22
|
+
secret_key_file || Doorkeeper::JWT.configuration.secret_key
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.secret_key_file
|
26
|
+
return nil if Doorkeeper::JWT.configuration.secret_key_path.nil?
|
27
|
+
OpenSSL::PKey::RSA.new(
|
28
|
+
File.open(Doorkeeper::JWT.configuration.secret_key_path)
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.encryption_method
|
33
|
+
return nil unless Doorkeeper::JWT.configuration.encryption_method
|
34
|
+
Doorkeeper::JWT.configuration.encryption_method.to_s.upcase
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,124 @@
|
|
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 secret_key(secret_key)
|
29
|
+
@config.instance_variable_set('@secret_key', secret_key)
|
30
|
+
end
|
31
|
+
|
32
|
+
def secret_key_path(secret_key_path)
|
33
|
+
@config.instance_variable_set('@secret_key_path', secret_key_path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def encryption_method(encryption_method)
|
37
|
+
@config.instance_variable_set(
|
38
|
+
'@encryption_method', encryption_method)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module Option
|
43
|
+
# Defines configuration option
|
44
|
+
#
|
45
|
+
# When you call option, it defines two methods. One method will take place
|
46
|
+
# in the +Config+ class and the other method will take place in the
|
47
|
+
# +Builder+ class.
|
48
|
+
#
|
49
|
+
# The +name+ parameter will set both builder method and config attribute.
|
50
|
+
# If the +:as+ option is defined, the builder method will be the specified
|
51
|
+
# option while the config attribute will be the +name+ parameter.
|
52
|
+
#
|
53
|
+
# If you want to introduce another level of config DSL you can
|
54
|
+
# define +builder_class+ parameter.
|
55
|
+
# Builder should take a block as the initializer parameter and respond to function +build+
|
56
|
+
# that returns the value of the config attribute.
|
57
|
+
#
|
58
|
+
# ==== Options
|
59
|
+
#
|
60
|
+
# * [:+as+] Set the builder method that goes inside +configure+ block
|
61
|
+
# * [+:default+] The default value in case no option was set
|
62
|
+
#
|
63
|
+
# ==== Examples
|
64
|
+
#
|
65
|
+
# option :name
|
66
|
+
# option :name, as: :set_name
|
67
|
+
# option :name, default: 'My Name'
|
68
|
+
# option :scopes builder_class: ScopesBuilder
|
69
|
+
#
|
70
|
+
def option(name, options = {})
|
71
|
+
attribute = options[:as] || name
|
72
|
+
attribute_builder = options[:builder_class]
|
73
|
+
|
74
|
+
Builder.instance_eval do
|
75
|
+
define_method name do |*args, &block|
|
76
|
+
# TODO: is builder_class option being used?
|
77
|
+
value = unless attribute_builder
|
78
|
+
block ? block : args.first
|
79
|
+
else
|
80
|
+
attribute_builder.new(&block).build
|
81
|
+
end
|
82
|
+
|
83
|
+
@config.instance_variable_set(:"@#{attribute}", value)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
define_method attribute do |*args|
|
88
|
+
if instance_variable_defined?(:"@#{attribute}")
|
89
|
+
instance_variable_get(:"@#{attribute}")
|
90
|
+
else
|
91
|
+
options[:default]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
public attribute
|
96
|
+
end
|
97
|
+
|
98
|
+
def extended(base)
|
99
|
+
base.send(:private, :option)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
extend Option
|
104
|
+
|
105
|
+
option :token_payload,
|
106
|
+
default: proc{ { token: SecureRandom.method(:hex) } }
|
107
|
+
option :secret_key, default: nil
|
108
|
+
option :secret_key_path, default: nil
|
109
|
+
option :encryption_method, default: nil
|
110
|
+
|
111
|
+
def secret_key
|
112
|
+
@secret_key ||= nil
|
113
|
+
end
|
114
|
+
|
115
|
+
def secret_key_path
|
116
|
+
@secret_key_path ||= nil
|
117
|
+
end
|
118
|
+
|
119
|
+
def encryption_method
|
120
|
+
@encryption_method ||= nil
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "doorkeeper-jwt/version"
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: doorkeeper-jwt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Warren
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-31 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: '1.4'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.4.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.4'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.4.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.8'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.8'
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.8'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '1.8'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rake
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '10.0'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '10.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '10.0'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '10.0'
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: rspec
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 3.2.0
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.2'
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.2.0
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '3.2'
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: pry
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - "~>"
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
description: JWT token generator extension for Doorkeeper
|
108
|
+
email:
|
109
|
+
- chris@expectless.com
|
110
|
+
executables: []
|
111
|
+
extensions: []
|
112
|
+
extra_rdoc_files: []
|
113
|
+
files:
|
114
|
+
- ".gitignore"
|
115
|
+
- ".rspec"
|
116
|
+
- ".travis.yml"
|
117
|
+
- Gemfile
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.md
|
120
|
+
- Rakefile
|
121
|
+
- bin/console
|
122
|
+
- bin/setup
|
123
|
+
- doorkeeper-jwt.gemspec
|
124
|
+
- lib/doorkeeper-jwt.rb
|
125
|
+
- lib/doorkeeper-jwt/config.rb
|
126
|
+
- lib/doorkeeper-jwt/doorkeeper-jwt.rb
|
127
|
+
- lib/doorkeeper-jwt/version.rb
|
128
|
+
homepage: https://github.com/chriswarren/doorkeeper-jwt
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.4.6
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: JWT token generator for Doorkeeper
|
152
|
+
test_files: []
|