pluggable_auth_token 0.1.2

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: 3c7d82ef0df93fea2c63c077061fd9d360ddf11e
4
+ data.tar.gz: 54538c3e43ba87d2936a0d13ef62c72350012ea7
5
+ SHA512:
6
+ metadata.gz: 063129c1c8a83e736c31f36c26df2204a49e4db21d5b15e54a9f6cf8f318f3f7b51e5644b534ef837c20dfd8b87e38b5275457db1006c5efeab016b8f655c77b
7
+ data.tar.gz: eafb6c6c97d0aa10c379978984fd9f7270c8b01abd84a52d81f692c9ab46026d9adea096e76ead5cec0570aca26675a4adc330856f01e5642faaefee890d4be8
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,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mac@bbtnetworks.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pluggable_auth_token.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # PluggableAuthToken
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/pluggable_auth_token`. 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 'pluggable_auth_token'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install pluggable_auth_token
22
+
23
+ Make sure Devise is installed
24
+
25
+ $ rails generate devise:install
26
+ $ rails generate devise User
27
+
28
+ ## Usage
29
+
30
+ If you verify from another app, make sure the secret_key_base matches
31
+
32
+ ```ruby
33
+ class ApplicationController < ActionController::API
34
+
35
+ require 'auth_token'
36
+
37
+ protected
38
+
39
+ def verify_jwt_token
40
+ head :unauthorized if request.headers['HTTP_AUTHORIZATION'].blank? ||
41
+ !AuthToken.new(token: request.headers['HTTP_AUTHORIZATION'].split('Token ').last).valid?
42
+ end
43
+ end
44
+ ```
45
+ in controllers that you want to protect
46
+
47
+ ` before_action :verify_jwt_token
48
+ `
49
+
50
+ ### ToDo
51
+ to use the json endpoints for api validation
52
+ ` mount PluggableAuthToken::Engine, at: "/auth" `
53
+
54
+ ```bash
55
+ curl -H "Content-Type: application/json" -X POST -d '{"user":{"email":"test@example.com","password":"12345678","password_confirm":"12345678"}}' http://localhost:3000/users/signup
56
+ ```
57
+
58
+ ```bash
59
+ curl -H "Content-Type: application/json" -X POST -d '{"user": {"email":"test@example.com","password":"12345678"}}' http://localhost:3000/auth/users/sign_in
60
+
61
+ ```
62
+
63
+
64
+ ```bash
65
+ curl -H "Authorization: Token [TOKEN]" http://localhost:3000/my_controller --HEAD
66
+ ```
67
+
68
+
69
+ ## Development
70
+
71
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also 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`, which will 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
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pluggable_auth_token. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
78
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,6 @@
1
+ class Users::RegistrationsController < Devise::RegistrationsController
2
+ skip_before_action :verify_authenticity_token
3
+ def flash(args={})
4
+ puts args.inspect
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ # Extend the devise sessions controller
2
+ # to support JSON based authentication and issuing a JWT.
3
+ class Users::SessionsController < Devise::SessionsController
4
+ skip_before_action :verify_authenticity_token
5
+ require 'auth_token'
6
+
7
+ def create
8
+
9
+ # This is the default behavior from devise - view the sessions controller source:
10
+ # https://github.com/plataformatec/devise/blob/master/app/controllers/devise/sessions_controller.rb#L16
11
+ self.resource = warden.authenticate!(auth_options)
12
+ sign_in(resource_name, resource)
13
+ yield resource if block_given?
14
+
15
+ # Here we're deviating from the standard behavior by issuing our JWT
16
+ # to any JS based client.
17
+ token = AuthToken.new(payload: { user_id: resource.id }).token
18
+ # contents = AuthToken.new(token: token).decoded
19
+
20
+ render json: {user: resource.email, token: token}
21
+
22
+ end
23
+
24
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pluggable_auth_token"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config/routes.rb ADDED
@@ -0,0 +1,12 @@
1
+ PluggableAuthToken::Engine.routes.draw do
2
+ # devise_for :users, controllers: {
3
+ # sessions: 'users/sessions',
4
+ # registrations: 'users/registrations'
5
+ # }
6
+ devise_scope :user do
7
+ namespace :users do
8
+ resources :sessions, path: '/sign_in', only: :create
9
+ resources :registrations, path: '/', only: :create
10
+ end
11
+ end
12
+ end
data/lib/auth_token.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'jwt'
2
+ require 'active_support/all'
3
+
4
+ class AuthToken
5
+ DEFAULT_EXPIRE_INTERVAL = 1.year
6
+
7
+ attr_accessor :payload, :token, :expire_interval
8
+
9
+ def initialize(args={})
10
+ @expire_interval = args[:expire_interval] || DEFAULT_EXPIRE_INTERVAL
11
+ @payload = args[:payload]
12
+ @token = args[:token]
13
+ @expiration = @expire_interval.from_now.to_time.to_i
14
+ @token ||= issue if args[:payload]
15
+ end
16
+
17
+ def issue
18
+ @payload[:expiration] = expiration # Set expiration
19
+ @token = JWT.encode(@payload, Rails.application.secrets.secret_key_base)
20
+ end
21
+
22
+ def valid?
23
+ begin
24
+ !expired? && !decoded.blank?
25
+ rescue
26
+ false
27
+ end
28
+ end
29
+
30
+ # reset token if expired
31
+ def expiration
32
+ @expiration = expired? ? @expire_interval.from_now.to_time.to_i : @expiration
33
+ end
34
+
35
+ def expired?
36
+ @token.blank? || Time.at(decoded[:expiration]) > Time.zone.now.to_time.to_i
37
+ end
38
+
39
+ def decoded
40
+ @token.blank? ? false : JWT.decode(@token, Rails.application.secrets.secret_key_base).first.symbolize_keys
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ require "pluggable_auth_token/version"
2
+
3
+ module PluggableAuthToken
4
+ class Engine < ::Rails::Engine; end
5
+ end
@@ -0,0 +1,3 @@
1
+ module PluggableAuthToken
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pluggable_auth_token/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pluggable_auth_token"
8
+ spec.version = PluggableAuthToken::VERSION
9
+ spec.authors = ["Mac Rosel"]
10
+ spec.email = ["mac@bbtnetworks.com"]
11
+
12
+ spec.summary = %q{Simple plugin for creating and validating a JWT token }
13
+ spec.homepage = "https://bbtnetworks.com"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
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_development_dependency "bundler", "~> 1.13"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "rspec-rails"
26
+ spec.add_development_dependency "rails"
27
+
28
+ spec.add_dependency "devise"
29
+ spec.add_dependency "jwt"
30
+ spec.add_dependency "rack-cors"
31
+
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pluggable_auth_token
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Mac Rosel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
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: devise
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: jwt
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rack-cors
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - mac@bbtnetworks.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - CODE_OF_CONDUCT.md
136
+ - Gemfile
137
+ - README.md
138
+ - Rakefile
139
+ - app/controllers/users/registrations_controller.rb
140
+ - app/controllers/users/sessions_controller.rb
141
+ - bin/console
142
+ - bin/setup
143
+ - config/routes.rb
144
+ - lib/auth_token.rb
145
+ - lib/pluggable_auth_token.rb
146
+ - lib/pluggable_auth_token/version.rb
147
+ - pluggable_auth_token.gemspec
148
+ homepage: https://bbtnetworks.com
149
+ licenses: []
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.5.1
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Simple plugin for creating and validating a JWT token
171
+ test_files: []