horse_power 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/horse_power/app_environment/app_environment_generator.rb +5 -11
- data/lib/generators/horse_power/setup/setup_generator.rb +5 -4
- data/lib/generators/horse_power/setup/templates/application_controller.rb +7 -2
- data/lib/generators/horse_power/user/templates/controller.rb.erb +3 -2
- data/lib/generators/horse_power/user/templates/model.rb.erb +5 -5
- data/lib/generators/horse_power/user/templates/specs/requests.rb.erb +4 -2
- data/lib/generators/horse_power/user/templates/tokenhash.rb +40 -0
- data/lib/generators/horse_power/user/user_generator.rb +3 -2
- data/lib/horse_power/version.rb +1 -1
- metadata +3 -3
- data/lib/generators/horse_power/app_environment/templates/identity_cache.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe53c436f835f2a2941759bb55f910c8a0e972da
|
4
|
+
data.tar.gz: 46bd713a02db23ffcb166af1563d7c7358a34028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f72d25da489952278ab4a4ecf97b887db5550363b90ebf7ee7f834d274262404c0bb1b9100b9b772d13a4ad1fe34f84799584f526a837c9178de29139384ffa4
|
7
|
+
data.tar.gz: 5960b0dcd977417456018c94c15246446bfad8c72ae95143a32b2126564cd991d5197086f58877e19044b6350052a200a39ca03972847b4e719b43f92f1fe411
|
@@ -20,10 +20,9 @@ module HorsePower
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def createSettings
|
23
|
-
copy_file "identity_cache.rb", "config/initializers/identity_cache.rb"
|
24
23
|
run "rails g rails_config:install"
|
25
24
|
prepend_to_file 'config/settings.yml' do
|
26
|
-
"token_header: \"Auth-Token\"\nmain_api_header: \"Main-Api-Header\"\n"
|
25
|
+
"token_header: \"Auth-Token\"\nmain_api_header: \"Main-Api-Header\"\nexpire_time: 20000\n"
|
27
26
|
end
|
28
27
|
createEnvSettings
|
29
28
|
end
|
@@ -54,7 +53,7 @@ module HorsePower
|
|
54
53
|
resource '*',
|
55
54
|
:headers => :any,
|
56
55
|
:methods => [:get, :post, :put, :delete, :options],
|
57
|
-
:expose => ['Logged-In-Status','Auth-Token','Main-Api-Header']
|
56
|
+
:expose => ['Logged-In-Status','Auth-Token','Main-Api-Header','Authorization']
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
@@ -67,8 +66,7 @@ module HorsePower
|
|
67
66
|
gsub_file "config/environments/development.rb", "config.action_mailer.raise_delivery_errors = false\n", "#config.action_mailer.raise_delivery_errors = false\n"
|
68
67
|
inject_into_file 'config/environments/development.rb', after: "configure do\n" do <<-'RUBY'
|
69
68
|
|
70
|
-
|
71
|
-
config.identity_cache_store = :memory_store, { size: 64.megabytes }
|
69
|
+
config.cache_store = :memory_store
|
72
70
|
config.action_mailer.perform_deliveries = false
|
73
71
|
config.action_mailer.raise_delivery_errors = false
|
74
72
|
config.action_mailer.default_options = {from: ENV['GMAIL_USERNAME']}
|
@@ -94,8 +92,7 @@ module HorsePower
|
|
94
92
|
gsub_file "config/environments/test.rb", "config.action_mailer.delivery_method = :test\n", "#config.action_mailer.delivery_method = :test\n"
|
95
93
|
inject_into_file 'config/environments/test.rb', after: "configure do\n" do <<-'RUBY'
|
96
94
|
|
97
|
-
|
98
|
-
config.identity_cache_store = :null_store
|
95
|
+
config.cache_store = :null_store
|
99
96
|
#config.action_mailer.perform_deliveries = false
|
100
97
|
config.action_mailer.raise_delivery_errors = true
|
101
98
|
config.action_mailer.default_options = {from: 'testing123@example.com'}
|
@@ -121,10 +118,7 @@ module HorsePower
|
|
121
118
|
::Settings.reload!
|
122
119
|
inject_into_file 'config/environments/production.rb', after: "configure do\n" do <<-'RUBY'
|
123
120
|
|
124
|
-
|
125
|
-
#identity_cache
|
126
|
-
#config.identity_cache_store = :mem_cache_store, Memcached::Rails.new(:servers => ["mem1.server.com"])
|
127
|
-
config.identity_cache_store = :null_store
|
121
|
+
config.cache_store = :null_store
|
128
122
|
config.force_ssl = true
|
129
123
|
config.action_mailer.perform_deliveries = true
|
130
124
|
config.action_mailer.raise_delivery_errors = true
|
@@ -144,11 +144,11 @@ module HorsePower
|
|
144
144
|
gem 'bcrypt', '~> 3.1.7'
|
145
145
|
gem 'type_cartographer'
|
146
146
|
gem 'devise', "~> 3.2.4"
|
147
|
-
gem 'arcadex', '
|
147
|
+
gem 'arcadex', '~> 1.2.3'
|
148
148
|
gem 'autoprefixer-rails'
|
149
149
|
gem 'bootstrap-sass', '~> 3.2.0'
|
150
150
|
gem 'activeadmin', :git => 'https://github.com/activeadmin/activeadmin.git', :branch => "master"
|
151
|
-
gem 'defcon'
|
151
|
+
gem 'defcon', '~> 1.2.7'
|
152
152
|
#gem 'authorization', :path => "gems/authorization"
|
153
153
|
gem 'whenever', :require => false
|
154
154
|
gem 'rack-cors', :require => 'rack/cors'
|
@@ -161,8 +161,9 @@ module HorsePower
|
|
161
161
|
end
|
162
162
|
gem 'rack-timeout'
|
163
163
|
gem 'puma'
|
164
|
-
gem '
|
165
|
-
gem '
|
164
|
+
gem 'jwt'
|
165
|
+
#gem 'identity_cache'
|
166
|
+
#gem 'cityhash' # optional, for faster hashing (C-Ruby only)
|
166
167
|
#gem 'websocket-rails'
|
167
168
|
end
|
168
169
|
|
@@ -1,6 +1,8 @@
|
|
1
|
+
require 'tokenhash'
|
2
|
+
|
1
3
|
class Api::V1::ApplicationController < ::ActionController::API
|
2
4
|
|
3
|
-
before_action :authenticate_app
|
5
|
+
#before_action :authenticate_app
|
4
6
|
before_action :authenticate_user
|
5
7
|
|
6
8
|
private
|
@@ -23,7 +25,7 @@ class Api::V1::ApplicationController < ::ActionController::API
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def set_hash
|
26
|
-
@instance_hash = ::
|
28
|
+
@instance_hash = ::TokenHash.decode(params,request)
|
27
29
|
end
|
28
30
|
|
29
31
|
def current_user
|
@@ -36,6 +38,9 @@ class Api::V1::ApplicationController < ::ActionController::API
|
|
36
38
|
|
37
39
|
def current_token
|
38
40
|
if !@instance_hash.nil?
|
41
|
+
if @instance_hash["current_token"].nil?
|
42
|
+
@instance_hash["current_token"] = ::Arcadex::Find.find_token_by_auth_token(@instance_hash["auth_token"])
|
43
|
+
end
|
39
44
|
return @instance_hash["current_token"]
|
40
45
|
else
|
41
46
|
return nil
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require_dependency "api/v1/application_controller"
|
2
2
|
require 'authorization/v1/user'
|
3
|
+
require 'tokenhash'
|
3
4
|
|
4
5
|
class Api::V1::UsersController < Api::V1::ApplicationController
|
5
6
|
|
@@ -99,9 +100,9 @@ class Api::V1::UsersController < Api::V1::ApplicationController
|
|
99
100
|
end
|
100
101
|
|
101
102
|
def successful_login(user,token)
|
102
|
-
::Arcadex::Create.set_token(token,
|
103
|
+
::Arcadex::Create.set_token(token,::Settings.expire_time,request,nil)
|
103
104
|
userHash = {id: user.id, username: user.username, email: user.email}
|
104
|
-
tokenHash = {auth_token: token.auth_token}
|
105
|
+
tokenHash = {auth_token: ::TokenHash.encode(token.auth_token,user.id)}
|
105
106
|
render :json => {user: userHash,token: tokenHash}
|
106
107
|
end
|
107
108
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'type_cartographer'
|
2
2
|
require 'facebook'
|
3
|
+
require 'tokenhash'
|
3
4
|
|
4
5
|
class User < ActiveRecord::Base
|
5
|
-
include IdentityCache
|
6
6
|
|
7
7
|
before_save { self.email = email.downcase }
|
8
8
|
before_save { self.username = username.downcase }
|
9
9
|
before_validation :sanitize_attributes
|
10
10
|
after_create :setup_user
|
11
11
|
|
12
|
-
|
12
|
+
has_secure_password
|
13
13
|
|
14
14
|
has_many :tokens, :as => :imageable, :class_name => "::Arcadex::Token", dependent: :destroy
|
15
15
|
|
@@ -23,7 +23,7 @@ class User < ActiveRecord::Base
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def setup_user
|
26
|
-
|
26
|
+
create_token
|
27
27
|
return true
|
28
28
|
end
|
29
29
|
|
@@ -74,9 +74,9 @@ class User < ActiveRecord::Base
|
|
74
74
|
#Log in a user
|
75
75
|
@api_token = @user.tokens.create
|
76
76
|
end
|
77
|
-
::Arcadex::Create.set_token(@api_token,
|
77
|
+
::Arcadex::Create.set_token(@api_token,::Settings.expire_time,request,nil)
|
78
78
|
userHash = {id: @user.id, username: @user.username, fb_user_id: @user.fb_user_id}
|
79
|
-
objHash = {user: userHash, api_token: @api_token.auth_token, fb_token: long_token}
|
79
|
+
objHash = {user: userHash, api_token: ::TokenHash.encode(@api_token.auth_token,@user.id), fb_token: long_token}
|
80
80
|
return objHash
|
81
81
|
end
|
82
82
|
|
@@ -149,7 +149,8 @@ RSpec.describe User, :type => :request do
|
|
149
149
|
#A valid token needs to be returned
|
150
150
|
expect(json["token"]["auth_token"]).to_not eq(nil)
|
151
151
|
token = User.find(1).tokens[0]
|
152
|
-
|
152
|
+
jwt = ::JWT.decode(json["token"]["auth_token"],::Rails.application.secrets.secret_key_base)[0]
|
153
|
+
expect(jwt["auth_token"]).to eq(token.auth_token)
|
153
154
|
end
|
154
155
|
# post /api/1/users/register
|
155
156
|
it "checks response of a register request with mismatched passwords" do
|
@@ -183,7 +184,8 @@ RSpec.describe User, :type => :request do
|
|
183
184
|
expect(json["token"]["auth_token"]).to_not eq(old_auth_token)
|
184
185
|
#This token should be the newest token in the database
|
185
186
|
new_auth_token = User.find(1).tokens.order("created_at").last.auth_token
|
186
|
-
|
187
|
+
jwt = ::JWT.decode(json["token"]["auth_token"],::Rails.application.secrets.secret_key_base)[0]
|
188
|
+
expect(jwt["auth_token"]).to eq(new_auth_token)
|
187
189
|
end
|
188
190
|
# post /api/1/users/login
|
189
191
|
it "checks response of an invalid login request with an invalid password" do
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class TokenHash
|
2
|
+
|
3
|
+
=begin
|
4
|
+
Ideally, the expiration for the jwt token would be less than the db token,
|
5
|
+
and we would return a new jwt token to the user if the current jwt token expired
|
6
|
+
but the db token was not yet expired.
|
7
|
+
=end
|
8
|
+
|
9
|
+
def self.encode(auth_token_hash,user_id)
|
10
|
+
obj = {}
|
11
|
+
obj["auth_token"] = auth_token_hash
|
12
|
+
obj["user_id"] = user_id
|
13
|
+
obj["exp"] = ::Time.now.to_i() + ::Settings.expire_time
|
14
|
+
return ::JWT.encode(obj,::Rails.application.secrets.secret_key_base)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.decode(params,request)
|
18
|
+
instance_hash = nil
|
19
|
+
auth_token_obj = ::Arcadex::Header.grab_param_header(params,request,::Settings.token_header,false)
|
20
|
+
begin
|
21
|
+
# Try JWT token
|
22
|
+
jwt = ::JWT.decode(auth_token_obj,::Rails.application.secrets.secret_key_base)
|
23
|
+
token = jwt[0]
|
24
|
+
user = ::User.find_by(id: token["user_id"])
|
25
|
+
instance_hash = {}
|
26
|
+
instance_hash["current_owner"] = user
|
27
|
+
instance_hash["current_token"] = nil
|
28
|
+
instance_hash["auth_token"] = token["auth_token"]
|
29
|
+
return instance_hash
|
30
|
+
rescue ::JWT::DecodeError, ::JWT::ExpiredSignature
|
31
|
+
# Try Arcadex token
|
32
|
+
instance_hash = ::Arcadex::Authentication.get_instance(params,request,::Settings.token_header)
|
33
|
+
if !instance_hash.nil?
|
34
|
+
instance_hash["auth_token"] = nil
|
35
|
+
end
|
36
|
+
return instance_hash
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -11,14 +11,15 @@ module HorsePower
|
|
11
11
|
create_admin
|
12
12
|
create_tests
|
13
13
|
create_routes
|
14
|
-
|
14
|
+
create_lib
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def
|
19
|
+
def create_lib
|
20
20
|
#run "mkdir app/facebook"
|
21
21
|
template "facebook.rb", "lib/facebook.rb"
|
22
|
+
template "tokenhash.rb", "lib/tokenhash.rb"
|
22
23
|
end
|
23
24
|
|
24
25
|
def create_migration
|
data/lib/horse_power/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: horse_power
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cleophus Robinson IV
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -58,7 +58,6 @@ files:
|
|
58
58
|
- config/routes.rb
|
59
59
|
- lib/generators/horse_power/app_environment/USAGE
|
60
60
|
- lib/generators/horse_power/app_environment/app_environment_generator.rb
|
61
|
-
- lib/generators/horse_power/app_environment/templates/identity_cache.rb
|
62
61
|
- lib/generators/horse_power/app_environment/templates/procfile.rb
|
63
62
|
- lib/generators/horse_power/app_environment/templates/puma.rb
|
64
63
|
- lib/generators/horse_power/app_environment/templates/timeout.rb
|
@@ -109,6 +108,7 @@ files:
|
|
109
108
|
- lib/generators/horse_power/user/templates/specs/model.rb.erb
|
110
109
|
- lib/generators/horse_power/user/templates/specs/requests.rb.erb
|
111
110
|
- lib/generators/horse_power/user/templates/specs/routing.rb.erb
|
111
|
+
- lib/generators/horse_power/user/templates/tokenhash.rb
|
112
112
|
- lib/generators/horse_power/user/user_generator.rb
|
113
113
|
- lib/horse_power.rb
|
114
114
|
- lib/horse_power/engine.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
IdentityCache.cache_backend = ActiveSupport::Cache.lookup_store(*Rails.configuration.identity_cache_store)
|