json-jwt 0.0.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.

Potentially problematic release.


This version of json-jwt might be problematic. Click here for more details.

@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=documentation
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby
6
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ platform :jruby do
4
+ gem 'jruby-openssl', '>= 0.7'
5
+ end
6
+
7
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 nov matake
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ = OpenIDConnect
2
+
3
+ JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and JSON Web Key) in Ruby
4
+
5
+ == Installation
6
+
7
+ gem install json-jwt
8
+
9
+ == Resources
10
+
11
+ * View Source on GitHub (https://github.com/nov/json-jwt)
12
+ * Report Issues on GitHub (https://github.com/nov/json-jwt/issues)
13
+
14
+ == Examples
15
+
16
+ claim = {
17
+ iss: 'nov',
18
+ exp: 1.week.from_now,
19
+ nbf: Time.now
20
+ }
21
+
22
+ # No signature, no encryption
23
+ JSON::JWT.new(claim).to_s
24
+
25
+ # With signiture, no encryption
26
+ JSON::JWT.new(claim).sign(key, algorithm).to_s
27
+
28
+ # With signature & encryption
29
+ JSON::JWT.new(claim).sign(key, algorithm).encrypt(key, algorithm).to_s
30
+
31
+ == Note on Patches/Pull Requests
32
+
33
+ * Fork the project.
34
+ * Make your feature addition or bug fix.
35
+ * Add tests for it. This is important so I don't break it in a
36
+ future version unintentionally.
37
+ * Commit, do not mess with rakefile, version, or history.
38
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
39
+ * Send me a pull request. Bonus points for topic branches.
40
+
41
+ == Copyright
42
+
43
+ Copyright (c) 2011 nov matake. See LICENSE for details.
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
7
+ spec.rcov = true
8
+ spec.rcov_opts = ['-Ilib -Ispec --exclude spec,gems']
9
+ end
10
+
11
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "json-jwt"
3
+ s.version = File.read("VERSION")
4
+ s.authors = ["nov matake"]
5
+ s.email = ["nov@matake.jp"]
6
+ s.homepage = "https://github.com/nov/json-jwt"
7
+ s.summary = %q{JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and JSON Web Key) in Ruby}
8
+ s.description = %q{JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and JSON Web Key) in Ruby}
9
+ s.files = `git ls-files`.split("\n")
10
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
11
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ s.require_paths = ["lib"]
13
+ s.add_runtime_dependency "json", ">= 1.4.3"
14
+ s.add_runtime_dependency "url_safe_base64"
15
+ s.add_development_dependency "rake", ">= 0.8"
16
+ s.add_development_dependency "rcov", ">= 0.9"
17
+ s.add_development_dependency "rspec", ">= 2"
18
+ end
@@ -0,0 +1,5 @@
1
+ module JSON
2
+ class JWE < JWT
3
+ # TODO
4
+ end
5
+ end
@@ -0,0 +1,42 @@
1
+ module JSON
2
+ class JWS < JWT
3
+ def initialize(jwt)
4
+ @header = jwt.header
5
+ @claim = jwt.claim
6
+ end
7
+
8
+ def sign(private_key_or_secret, algorithm)
9
+ header[:alg] = algorithm
10
+ digest = OpenSSL::Digest::Digest.new "SHA#{algorithm.to_s[2, 3]}"
11
+ self.signature = case algorithm
12
+ when :HS256, :HS384, :HS512
13
+ secret = private_key_or_secret
14
+ OpenSSL::HMAC.digest(
15
+ digest,
16
+ secret,
17
+ signature_base_string
18
+ )
19
+ when :RS256, :RS384, :RS512
20
+ private_key = private_key_or_secret
21
+ private_key.sign(
22
+ digest,
23
+ signature_base_string
24
+ )
25
+ when :ES256, :ES384, :ES512
26
+ # TODO
27
+ end
28
+ self
29
+ end
30
+
31
+ private
32
+
33
+ def signature_base_string
34
+ [
35
+ header.to_json,
36
+ claim.to_json
37
+ ].collect do |segment|
38
+ UrlSafeBase64.encode64 segment
39
+ end.join('.')
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ require 'openssl'
2
+ require 'url_safe_base64'
3
+ require 'json'
4
+
5
+ module JSON
6
+ class JWT
7
+ attr_accessor :header, :claim, :signature
8
+
9
+ def initialize(claim)
10
+ @header = {
11
+ :typ => :JWT,
12
+ :alg => :none
13
+ }
14
+ [:exp, :nbf, :iat].each do |key|
15
+ if claim[key]
16
+ claim[key] = claim[key].to_i
17
+ end
18
+ end
19
+ @claim = claim
20
+ end
21
+
22
+ def sign(private_key_or_secret, algorithm = :RS256)
23
+ JWS.new(self).sign(private_key_or_secret, algorithm)
24
+ end
25
+
26
+ def to_s
27
+ [
28
+ header.to_json,
29
+ claim.to_json,
30
+ signature
31
+ ].collect do |segment|
32
+ UrlSafeBase64.encode64 segment.to_s
33
+ end.join('.')
34
+ end
35
+ end
36
+ end
37
+
38
+ require 'json/jws'
39
+ require 'json/jwe'
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ require 'json/jwt'
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json-jwt
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.0
6
+ platform: ruby
7
+ authors:
8
+ - nov matake
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-09-14 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.4.3
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: url_safe_base64
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0.8"
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: rcov
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0.9"
57
+ type: :development
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "2"
68
+ type: :development
69
+ version_requirements: *id005
70
+ description: JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and JSON Web Key) in Ruby
71
+ email:
72
+ - nov@matake.jp
73
+ executables: []
74
+
75
+ extensions: []
76
+
77
+ extra_rdoc_files: []
78
+
79
+ files:
80
+ - .gitignore
81
+ - .rspec
82
+ - .travis.yml
83
+ - Gemfile
84
+ - LICENSE
85
+ - README.rdoc
86
+ - Rakefile
87
+ - VERSION
88
+ - json-jwt.gemspec
89
+ - lib/json/jwe.rb
90
+ - lib/json/jws.rb
91
+ - lib/json/jwt.rb
92
+ - spec/spec_helper.rb
93
+ homepage: https://github.com/nov/json-jwt
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options: []
98
+
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: "0"
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.10
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and JSON Web Key) in Ruby
120
+ test_files:
121
+ - spec/spec_helper.rb