doorkeeper-jwt_assertion 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27fd53398a97014fdf2e15738c0a3e8b614fe9c9
4
+ data.tar.gz: 122d76d1dfee424e13f85983aaf6e3bbfb69b142
5
+ SHA512:
6
+ metadata.gz: 1f58e5c6f1ca803e953c95567729a1aba332173560c27a9c339426f2346603430c60e78f17d3088a8a650e7a79a5db1f893319f66dce708a5a93417a713d0623
7
+ data.tar.gz: 57f040de3c1bd245eb7ea76db943003320eade8a2dc8126e3c379def4b499c74c6e5b53417919fa857313d59931c7040ae89ea819a41eb4cf6e74bf3da2237ea
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in doorkeeper-jwt_assertion.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Omac
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Doorkeeper JWT Assertion
2
+
3
+ ## Description
4
+
5
+ Extending (Doorkeeper)[https://github.com/doorkeeper-gem/doorkeeper] to support JWT Assertion grant type using a secret or a private key file.
6
+
7
+ **This library is in alpha. Future incompatible changes may be necessary.**
8
+
9
+ ## Install
10
+
11
+ Add the gem to the Gemfile
12
+
13
+ ```ruby
14
+ gem 'doorkeeper-jwt_assertion'
15
+ ```
16
+
17
+ ## Configuration
18
+
19
+ Inside your doorkeeper configuration file add the one of the fallowing:
20
+
21
+ ``` ruby
22
+ Doorkeeper.configure do
23
+
24
+ jwt_private_key Rails.root.join('config', 'keys', 'private.key')
25
+
26
+ jwt_secret 'notasecret'
27
+ end
28
+ ```
29
+
30
+ This will automatically push `assertion` into the Doorkeeper's grant_types configuration attribute.
31
+
32
+ You can also use the `resource_owner_authenticator` in the configuration to identify the owner based on the JWT claim values.
33
+ If the client request a token with an invalid assertion, an error will be raised. So you can rely on the `jwt` getter if an assertion grant was requested.
34
+
35
+ ``` ruby
36
+ Doorkeeper.configure do
37
+
38
+ resource_owner_authenticator do
39
+
40
+ if jwt
41
+ head :unauthorized unless user = User.where(:email => jwt['prn']).first
42
+ return user
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ ```
50
+
51
+ ## Client Usage
52
+
53
+ Generate an assertion request token using a private key file or a secret:
54
+
55
+ ``` ruby
56
+ client = OAuth2::Client.new('client_id', 'client_secret', :site => 'http://my-site.com')
57
+
58
+ p12 = OpenSSL::PKCS12.new( Rails.root.join('config', 'keys', 'private.p12').open )
59
+
60
+ params = { :private_key => p12.key,
61
+ :aud => 'audience',
62
+ :prn => 'person', # or :sub => 'subject', not suported on OAuth2 1.0.0 yet.
63
+ :iss => 'issuer',
64
+ :scope => 'scope',
65
+ :exp => Time.now.utc.to_i + 5.minutes }
66
+
67
+ token = client.assertion.get_token(params)
68
+ ```
69
+
70
+ ## TO DO
71
+
72
+ * Better error handling
73
+ * Testing
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
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_assertion/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "doorkeeper-jwt_assertion"
8
+ spec.version = Doorkeeper::JwtAssertion::VERSION
9
+ spec.authors = ["Omac"]
10
+ spec.email = ["omar@kioru.com"]
11
+ spec.summary = 'OAuth JWT assertion extension for Doorkeeper'
12
+ spec.description = 'Extend your Doorkeeper implementation adding a new grant type: assertion. And decoding JWT claim messages to generate access tokens.'
13
+ spec.homepage = 'https://github.com/kioru/doorkeeper-jwt_assertion'
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "doorkeeper", '~> 2.1'
22
+ spec.add_dependency "jwt", '~> 1.4'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,71 @@
1
+ require "doorkeeper/jwt_assertion/version"
2
+ require "doorkeeper/request/assertion"
3
+ require "doorkeeper/jwt_assertion/railtie"
4
+
5
+ require 'jwt'
6
+
7
+ module Doorkeeper
8
+ module JWTAssertion
9
+
10
+ attr_reader :jwt
11
+
12
+ end
13
+ end
14
+
15
+ module Doorkeeper
16
+ class Server
17
+
18
+ attr_reader :jwt
19
+
20
+ def jwt=(jwt)
21
+ @jwt = jwt
22
+ context.instance_variable_set('@jwt', jwt)
23
+ end
24
+
25
+
26
+ end
27
+ end
28
+
29
+ module Doorkeeper
30
+ class Config
31
+
32
+ option :jwt_key
33
+
34
+ class Builder
35
+
36
+ def jwt_secret( key )
37
+ set_jwt(key)
38
+ end
39
+
40
+ def jwt_private_key ( key_file, passphrase = nil )
41
+ key = OpenSSL::PKey::RSA.new( File.open(key_file), passphrase )
42
+ set_jwt(key)
43
+ end
44
+
45
+ private
46
+
47
+ def set_jwt( key )
48
+
49
+ Config.class_eval do
50
+ alias_method :remember_calculate_token_grant_types, :calculate_token_grant_types
51
+
52
+ define_method :calculate_token_grant_types do
53
+ remember_calculate_token_grant_types << 'assertion'
54
+ end
55
+ end
56
+
57
+ jwt_key key
58
+
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
65
+
66
+ module Doorkeeper
67
+ module Errors
68
+ class ExpiredSignature < DoorkeeperError
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,9 @@
1
+ module Doorkeeper
2
+ module JWTAssertion
3
+ class Railtie < ::Rails::Railtie
4
+ initializer "doorkeeper.jwt_assertion" do
5
+ Doorkeeper::Helpers::Controller.send :include, Doorkeeper::JWTAssertion
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Doorkeeper
2
+ module JwtAssertion
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ module Doorkeeper
2
+ module Request
3
+
4
+ class Assertion
5
+ def self.build(server)
6
+ assertion = server.parameters[:assertion]
7
+ begin
8
+ jwt = JWT.decode(assertion, Doorkeeper.configuration.jwt_key)
9
+ rescue JWT::ExpiredSignature => e
10
+ raise Errors::ExpiredSignature
11
+ end
12
+ server.jwt = jwt.is_a?(Array) ? jwt.first : jwt
13
+
14
+ new(server.credentials, server.current_resource_owner, server)
15
+ end
16
+
17
+ attr_accessor :credentials, :resource_owner, :server
18
+
19
+ def initialize(credentials, resource_owner, server)
20
+ @credentials = credentials
21
+ @resource_owner = resource_owner
22
+ @server = server
23
+ end
24
+
25
+ def request
26
+ @request ||= OAuth::PasswordAccessTokenRequest.new(
27
+ Doorkeeper.configuration,
28
+ credentials,
29
+ resource_owner,
30
+ server.parameters)
31
+ end
32
+
33
+ def authorize
34
+ request.authorize
35
+ end
36
+ end
37
+
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doorkeeper-jwt_assertion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Omac
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: doorkeeper
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jwt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: 'Extend your Doorkeeper implementation adding a new grant type: assertion.
70
+ And decoding JWT claim messages to generate access tokens.'
71
+ email:
72
+ - omar@kioru.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - doorkeeper-jwt_assertion.gemspec
83
+ - lib/doorkeeper/jwt_assertion.rb
84
+ - lib/doorkeeper/jwt_assertion/railtie.rb
85
+ - lib/doorkeeper/jwt_assertion/version.rb
86
+ - lib/doorkeeper/request/assertion.rb
87
+ homepage: https://github.com/kioru/doorkeeper-jwt_assertion
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: OAuth JWT assertion extension for Doorkeeper
111
+ test_files: []
112
+ has_rdoc: