jwt_token_auth 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 959e6383e76b94c98e0061cc4548721d13f62593
4
+ data.tar.gz: ae3b4f326fddcdb817a4be1a12a36e172232c7b2
5
+ SHA512:
6
+ metadata.gz: f7437b8c3ee0b5825fae3b6c7c94daea7202b89a6a46fc53ccc5f736a9a2a902c2d823afeb72835ef5b9db719b42dbce0a652a25d90bc5945428c138fd2241cf
7
+ data.tar.gz: a4f21f784b4ae32082e47d787b43c4137e1fe291f094279dd5cad74cf39d2ff0cd5c383f4b63309563e7a26a3f20444a1687385a062a9a3b0487c723c5f9e207
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jwt_token_auth.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Kristopher Bredemeier
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,39 @@
1
+ # JwtTokenAuth
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jwt_token_auth`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'jwt_token_auth'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install jwt_token_auth
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/jwt_token_auth/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
8
+ task :console do
9
+ exec "irb -r jwt_token_auth -I ./lib"
10
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jwt_token_auth"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -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 'jwt_token_auth/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jwt_token_auth"
8
+ spec.version = JwtTokenAuth::VERSION
9
+ spec.authors = ["Kristopher Bredemeier"]
10
+ spec.email = ["k.bredemeier@gmail.com"]
11
+
12
+ spec.summary = %q{JWT Token Authemtication}
13
+ spec.description = %q{JWT Token Authenticationt}
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activesupport"
22
+ spec.add_dependency "jwt"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.8"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "pry-byebug"
28
+ end
@@ -0,0 +1,75 @@
1
+ require "delegate"
2
+
3
+ module JwtTokenAuth
4
+ # JWT doesn't encrypt the payload, it only sings it. That means
5
+ # that you should not store secret information in the payload but
6
+ # information that should be verified.
7
+ #
8
+ # @see http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#RegisteredClaimName
9
+ #
10
+ # @attr [String] iss The issue of the token
11
+ # @attr [String] sub The subject of the token
12
+ # @attr [String] aud The audience of the token
13
+ # @attr [UnixTimestamp] exp The expiration
14
+ # @attr [String] nbf Time before which the token must not be accepted for processing
15
+ # @attr [UnixTimestamp] iat The time the token was issued
16
+ # @attr [String] jti Unique identifier for the token
17
+ class AuthToken < SimpleDelegator
18
+ include Claims
19
+
20
+ claims :iss, :sub, :aud, :exp, :nbf, :iat, :jti
21
+
22
+ def initialize(params = {})
23
+ params = convert_keys_into_symbols(params)
24
+ @iss = params[:iss]
25
+ @sub = params[:sub]
26
+ @aud = params[:aud]
27
+ @exp = params.fetch :exp do
28
+ JwtTokenAuth.configuration.expiration_time.call().to_i
29
+ end
30
+ @nbf = params[:nbf]
31
+ @iat = params.fetch :iat do
32
+ Time.now.to_i
33
+ end
34
+ @jti = params[:jti]
35
+
36
+ __setobj__(params)
37
+ end
38
+
39
+ def secret
40
+ JwtTokenAuth.configuration.secret
41
+ end
42
+
43
+ def payload
44
+ self.except *claims_symbols
45
+ end
46
+
47
+ def encode
48
+ JWT.encode(self, secret)
49
+ end
50
+
51
+ class << self
52
+ def decode(encoded_token)
53
+ AuthToken.new(
54
+ JWT.decode(encoded_token, JwtTokenAuth.configuration.secret)[0]
55
+ )
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def convert_keys_into_symbols(hash)
62
+ converter =
63
+ lambda do |h|
64
+ Hash === h ?
65
+ Hash[
66
+ h.map do |k, v|
67
+ [k.respond_to?(:to_sym) ? k.to_sym : k, converter[v]]
68
+ end
69
+ ] : h
70
+ end
71
+
72
+ converter[hash]
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,23 @@
1
+ module JwtTokenAuth
2
+ module Claims
3
+ def claims_symbols
4
+ self.class.instance_variable_get("@claims")
5
+ end
6
+
7
+ module ClassMethods
8
+ def claims(*args)
9
+ @claims = args
10
+
11
+ args.each do |arg|
12
+ define_method arg.to_sym do
13
+ instance_variable_get("@#{arg}")
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ def self.included(base)
20
+ base.extend(ClassMethods)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ module JwtTokenAuth
2
+ class Configuration
3
+ attr_accessor :secret, :expiration_time
4
+
5
+ def initialize
6
+ @secret = "supersecret"
7
+ @expiration_time = proc { Time.now + (60 * 60) }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module JwtTokenAuth
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ require "jwt"
2
+ require "active_support/core_ext/hash/except"
3
+
4
+ require "jwt_token_auth/version"
5
+ require "jwt_token_auth/configuration"
6
+ require "jwt_token_auth/claims"
7
+ require "jwt_token_auth/auth_token"
8
+
9
+ begin
10
+ require "pry"
11
+ rescue LoadError
12
+ end
13
+
14
+ module JwtTokenAuth
15
+ class << self
16
+ attr_writer :configuration
17
+
18
+ def configuration
19
+ @configuration ||= Configuration.new
20
+ end
21
+
22
+ def reset
23
+ @configuration = Configuration.new
24
+ end
25
+
26
+ def configure
27
+ yield(configuration)
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jwt_token_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kristopher Bredemeier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jwt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
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.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
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
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: JWT Token Authenticationt
98
+ email:
99
+ - k.bredemeier@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - jwt_token_auth.gemspec
115
+ - lib/jwt_token_auth.rb
116
+ - lib/jwt_token_auth/auth_token.rb
117
+ - lib/jwt_token_auth/claims.rb
118
+ - lib/jwt_token_auth/configuration.rb
119
+ - lib/jwt_token_auth/version.rb
120
+ homepage:
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.5
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: JWT Token Authemtication
144
+ test_files: []