Paasword 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/paasword.rb +46 -0
  3. metadata +49 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: '03329d6367462d6d6f91761b183ae1fd5b3254d2'
4
+ data.tar.gz: 32ed5d1b9ea8863592feaacc15b217010ff4a8a1
5
+ SHA512:
6
+ metadata.gz: d33420bb3968f9838f7d5cc07f76fe4531af4037aa87da60a0f9677e5af4ce8bfdbb822073cd631207397c04a46353b6b0906e299044a301aad1f0afaf750d08
7
+ data.tar.gz: 91e0a5d85c1e482abba260af0d368563c5a56ac1f59bd14fe8673f7fd69f33300c95c111b9d26643b488725697aa1473c49b24b38a49d8abf43f980f0aab0ee9
@@ -0,0 +1,46 @@
1
+ require 'jwt'
2
+
3
+ class Paasword
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ begin
10
+ @req = Rack::Request.new(env)
11
+
12
+ token = env['HTTP_X_AUTH_TOKEN']
13
+ appPrivateKey = ENV['PAASWORD_APP_PRIVATE_KEY']
14
+ if !token
15
+ error("MISSING_ELEMENT", "x-auth-token")
16
+ elsif !appPrivateKey
17
+ error("MISSING_ELEMENT", "PAASWORD_APP_PRIVATE_KEY")
18
+ else
19
+ user = JWT.decode token, appPrivateKey, true
20
+ user = user[0]
21
+
22
+ if user && !user['AutoLogout']['IsEnabled']
23
+ loginTime = user['iat'];
24
+ hoursSinceLogin = ((Time.now.to_i - loginTime)/3600).round;
25
+ limit = user['AutoLogout']['LogoutEveryXHours']
26
+ if hoursSinceLogin > limit
27
+ error("SESSION_EXPIRED", "")
28
+ end
29
+ end
30
+
31
+ env['user'] = user
32
+
33
+ status, headers, body = @app.call(env)
34
+ [status, headers, body]
35
+ end
36
+ rescue Exception => ex
37
+ error("INTERNAL_ERROR", ex.message)
38
+ end
39
+ end
40
+
41
+ def error(errorType, errorMessage)
42
+ body = { "ErrorType" => errorType, "ErrorMessage" => errorMessage }
43
+ [401, { 'Content-Type' => 'application/json; charset=utf-8' }, [ body.to_json ]]
44
+ end
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Paasword
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gilad Soffer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-02-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ Paas-Word is an online authentication and user management service.
15
+ This Ruby on Rails Rack middleware library by Paas-Word enables website owners with a Ruby backend to restrict their endpoints to authenticated users only and retrieve user data.
16
+ email: paasword.cto@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/paasword.rb
22
+ homepage: http://rubygems.org/gems/paasword
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.5.2.3
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Paas-Word is an online authentication and user management service. This Ruby
46
+ on Rails Rack middleware library by Paas-Word enables website owners with a Ruby
47
+ backend to restrict their endpoints to authenticated users only and retrieve user
48
+ data.
49
+ test_files: []