user_management_rails 0.0.7

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: c93d2d2357864445057c3c1694099f4a886f00db
4
+ data.tar.gz: db82293e835498f9934699001a993feeab5fefa2
5
+ SHA512:
6
+ metadata.gz: d4fe06c84fb0ab6a87806298832aa74cd33b414d805637966a3e0bcee186036b37ff19edc6e8b36bbdef551e3293e249b7a650c81e7d353133ce62a9fcb731fe
7
+ data.tar.gz: d02bdc7264b60d9e84ea4ca26b07014074a7ef4288a540c9f7064c089b4eccba61bd0ceccb831c9aa0d892fc514451d159ef386085aacae0664beac770fe7ec1
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 'user_management_rails'
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 = 'UserManagementRails'
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/user-management-rails .js
2
+ //= link_directory ../stylesheets/user_management_rails .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 UserManagementRails
2
+ class ApplicationController < ActionController::Base
3
+ wrap_parameters false
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ require_dependency 'user_management_rails/application_controller'
2
+
3
+ module UserManagementRails
4
+ class LoginsController < ApplicationController
5
+ def create
6
+ if UserManagementRails.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 UserManagementRails
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module UserManagementRails
2
+ module LoginsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module UserManagementRails
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module UserManagementRails
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module UserManagementRails
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>User management rails</title>
5
+ <%= stylesheet_link_tag "user_management_rails/application", media: "all" %>
6
+ <%= javascript_include_tag "user_management_rails/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,2 @@
1
+ <h1>Logins#create</h1>
2
+ <p>Find me in app/views/jwt_handler_ruby/logins/create.html.erb</p>
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ UserManagementRails::Engine.routes.draw do
2
+ resources :logins, only: %i[create]
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :user_management_rails do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,7 @@
1
+ require 'jwt'
2
+ require 'dotenv-rails'
3
+ module UserManagementRails
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace UserManagementRails
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module UserManagementRails
2
+ VERSION = '0.0.7'
3
+ end
@@ -0,0 +1,20 @@
1
+ require 'user_management_rails/engine'
2
+ require 'jwt'
3
+ require 'dotenv-rails'
4
+
5
+ module UserManagementRails
6
+ def self.decode_user(jwt)
7
+ pub_key = OpenSSL::PKey::RSA.new(ENV['JWT_PUBLIC_KEY'])
8
+ JWT.decode(jwt, pub_key, true, algorithm: 'RS256')[0]
9
+ end
10
+
11
+ def self.valid_jwt?(jwt)
12
+ pub_key = OpenSSL::PKey::RSA.new(ENV['JWT_PUBLIC_KEY'])
13
+ begin
14
+ JWT.decode(jwt, pub_key, true, algorithm: 'RS256')[0]
15
+ rescue JWT::DecodeError
16
+ return false
17
+ end
18
+ true
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: user_management_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ platform: ruby
6
+ authors:
7
+ - RingCaptcha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-15 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.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.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: 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: Makes it easy for RoR backend to interact with front-end and external
168
+ services to manage User lifecycle, e.g., signup, login, etc.
169
+ email:
170
+ - ''
171
+ executables: []
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - MIT-LICENSE
176
+ - README.md
177
+ - Rakefile
178
+ - app/assets/config/user_management_rails_manifest.js
179
+ - app/assets/javascripts/jwt_handler_ruby/application.js
180
+ - app/assets/javascripts/jwt_handler_ruby/logins.js
181
+ - app/assets/stylesheets/jwt_handler_ruby/application.css
182
+ - app/assets/stylesheets/jwt_handler_ruby/logins.css
183
+ - app/controllers/user_management_rails/application_controller.rb
184
+ - app/controllers/user_management_rails/logins_controller.rb
185
+ - app/helpers/user_management_rails/application_helper.rb
186
+ - app/helpers/user_management_rails/logins_helper.rb
187
+ - app/jobs/user_management_rails/application_job.rb
188
+ - app/mailers/user_management_rails/application_mailer.rb
189
+ - app/models/user_management_rails/application_record.rb
190
+ - app/views/layouts/user_management_rails/application.html.erb
191
+ - app/views/user_managemet_rails/logins/index.html.erb
192
+ - config/routes.rb
193
+ - lib/tasks/user_management_rails_tasks.rake
194
+ - lib/user_management_rails.rb
195
+ - lib/user_management_rails/engine.rb
196
+ - lib/user_management_rails/version.rb
197
+ homepage: https://www.ringcaptcha.com/
198
+ licenses:
199
+ - MIT
200
+ metadata: {}
201
+ post_install_message:
202
+ rdoc_options: []
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ requirements: []
216
+ rubyforge_project:
217
+ rubygems_version: 2.6.11
218
+ signing_key:
219
+ specification_version: 4
220
+ summary: RingCaptcha widget RoR helper.
221
+ test_files: []