jwt_handler_ruby 0.0.1

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: 2340e3de9faf852451d2d196d24fbbd93db9c3a0
4
+ data.tar.gz: a90aca41c6b3932387e1c2c06d5e95af19af028d
5
+ SHA512:
6
+ metadata.gz: c2e284fac81e1f89feba340ae90ff63e44c1077d0acb347f4890d0769b14a103e49aef5d1924d12cd30a286f0af1bb28cf2481f62aba70cfa5aa3051074300fc
7
+ data.tar.gz: a6213eb8a57f4b25024c01a871f7e6769c33bb7371d1f05ec600bd5d21ed9326ad3062651a22bcd0f80b0ddce858a9cc7bec33df6b1ba612bdf2305e0bd3e4ba
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 AndriiAkulov
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.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # JwtHandlerRuby
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+ Gem has next methods:
7
+ `decode_user(jwt)` - expects jwt with user and returns decoded payload(in our case user info).
8
+ `valid_jwt?(jwt)` - expects jwt and checks if it is valid. Return `true` when it is valid, otherwise returns `false`
9
+
10
+ Gem adds next endpoints to your application:
11
+ `/logins` which has next methods:
12
+ - `POST` - expects {"jwt": <jwt_signed by UM private key>}. It checks if jwt is valid and if so, then save it to the cookies called 'jwt'.
13
+ if jwt is not valid then it delete it from the cookies. When jwt was added to cookies than it will be sent with every request.
14
+
15
+
16
+ ## Installation
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'jwt_handler_ruby'
21
+ ```
22
+
23
+ And then execute:
24
+ ```bash
25
+ $ bundle
26
+ ```
27
+
28
+ Or install it yourself as:
29
+ ```bash
30
+ $ gem install jwt_handler_ruby
31
+ ```
32
+
33
+ ## Requirements
34
+ To use gem you should provide environment variable with UM public key called 'JWT_PUBLIC_KEY'.
35
+ Also, in your routes.rb file you should specify where `/login` endpoint will be mount.
36
+ Example:
37
+ ```ruby
38
+ mount JwtHandlerRuby::Engine, at: '/'
39
+ ```
40
+ in this case gems '/login' endpoint will be mounted at: `domain.com/logins`.
41
+ If you already have a '/login' endpoint you can isolate it by
42
+ ```ruby
43
+ mount JwtHandlerRuby::Engine, at: '/some_path'
44
+ ```
45
+ Then gems `/login` endpoint will be mounted on `domain.com/some_path/logins`
46
+
47
+ ## Contributing
48
+ Contribution directions go here.
49
+
50
+ ## License
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'JwtHandlerRuby'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/jwt_handler_ruby .js
2
+ //= link_directory ../stylesheets/jwt_handler_ruby .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,5 @@
1
+ module JwtHandlerRuby
2
+ class ApplicationController < ActionController::Base
3
+ wrap_parameters false
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ require_dependency 'jwt_handler_ruby/application_controller'
2
+
3
+ module JwtHandlerRuby
4
+ class LoginsController < ApplicationController
5
+ def create
6
+ if JwtHandlerRuby.valid_jwt?(user_jwt)
7
+ cookies[:jwt] = user_jwt
8
+ else
9
+ cookies.delete :jwt
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def user_jwt
16
+ permitted_params[:jwt]
17
+ end
18
+
19
+ def permitted_params
20
+ params.permit(:jwt)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ module JwtHandlerRuby
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module JwtHandlerRuby
2
+ module LoginsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module JwtHandlerRuby
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module JwtHandlerRuby
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module JwtHandlerRuby
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ <h1>Logins#create</h1>
2
+ <p>Find me in app/views/jwt_handler_ruby/logins/create.html.erb</p>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Jwt handler ruby</title>
5
+ <%= stylesheet_link_tag "jwt_handler_ruby/application", media: "all" %>
6
+ <%= javascript_include_tag "jwt_handler_ruby/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ JwtHandlerRuby::Engine.routes.draw do
2
+ resources :logins, only: %i[create]
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'jwt_handler_ruby/engine'
2
+
3
+ module JwtHandlerRuby
4
+ def self.decode_user(jwt)
5
+ pub_key = OpenSSL::PKey::RSA.new(ENV['JWT_PUBLIC_KEY'])
6
+ JWT.decode(jwt, pub_key, true, algorithm: 'RS256')[0]
7
+ end
8
+
9
+ def self.valid_jwt?(jwt)
10
+ pub_key = OpenSSL::PKey::RSA.new(ENV['JWT_PUBLIC_KEY'])
11
+ begin
12
+ JWT.decode(jwt, pub_key, true, algorithm: 'RS256')[0]
13
+ rescue JWT::DecodeError
14
+ return false
15
+ end
16
+ true
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module JwtHandlerRuby
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace JwtHandlerRuby
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module JwtHandlerRuby
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :jwt_handler_ruby do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,220 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jwt_handler_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ''
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.5
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: dotenv-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: config
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.3.6
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.3.6
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
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
+ - !ruby/object:Gem::Dependency
98
+ name: active_model_serializers
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
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: factory_girl_rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: config
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: jwt
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: timecop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Helps to integrate RingCaptcha widget with Ruby on Rails applications.
168
+ email:
169
+ - ''
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - MIT-LICENSE
175
+ - README.md
176
+ - Rakefile
177
+ - app/assets/config/jwt_handler_ruby_manifest.js
178
+ - app/assets/javascripts/jwt_handler_ruby/application.js
179
+ - app/assets/javascripts/jwt_handler_ruby/logins.js
180
+ - app/assets/stylesheets/jwt_handler_ruby/application.css
181
+ - app/assets/stylesheets/jwt_handler_ruby/logins.css
182
+ - app/controllers/jwt_handler_ruby/application_controller.rb
183
+ - app/controllers/jwt_handler_ruby/logins_controller.rb
184
+ - app/helpers/jwt_handler_ruby/application_helper.rb
185
+ - app/helpers/jwt_handler_ruby/logins_helper.rb
186
+ - app/jobs/jwt_handler_ruby/application_job.rb
187
+ - app/mailers/jwt_handler_ruby/application_mailer.rb
188
+ - app/models/jwt_handler_ruby/application_record.rb
189
+ - app/views/jwt_handler_ruby/logins/index.html.erb
190
+ - app/views/layouts/jwt_handler_ruby/application.html.erb
191
+ - config/routes.rb
192
+ - lib/jwt_handler_ruby.rb
193
+ - lib/jwt_handler_ruby/engine.rb
194
+ - lib/jwt_handler_ruby/version.rb
195
+ - lib/tasks/jwt_handler_ruby_tasks.rake
196
+ homepage: https://www.ringcaptcha.com/
197
+ licenses:
198
+ - MIT
199
+ metadata: {}
200
+ post_install_message:
201
+ rdoc_options: []
202
+ require_paths:
203
+ - lib
204
+ required_ruby_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ requirements: []
215
+ rubyforge_project:
216
+ rubygems_version: 2.6.11
217
+ signing_key:
218
+ specification_version: 4
219
+ summary: RingCaptcha widget RoR helper.
220
+ test_files: []