horse_power 0.9.0 → 1.0.0
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 +4 -4
- data/lib/generators/horse_power/app_environment/app_environment_generator.rb +1 -1
- data/lib/generators/horse_power/setup/templates/application_controller.rb +4 -1
- data/lib/generators/horse_power/user/templates/tokenhash.rb +58 -51
- data/lib/horse_power/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d38ab66e62fa078e82fc8290d67faa8adcf2842
|
4
|
+
data.tar.gz: f58d61a10861b6a9fc9e95ae705dc517c925b107
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30f683ea6e670a7007f1969cbb2b0a13676f9ce41a5d66152236e06ce8788c35b54b3f2def55b8391566b2559c0fe0fdc5bea9e7b6b066971f81966087a419a0
|
7
|
+
data.tar.gz: 748158b74f3dd373bd3506d67f1b8ab048919be09317dfd94a08b2602f8a1dcec30e84ca4a88520dedd6264d11a1729f16b0e57c50f46bdaa6eb0a195d4ac895
|
@@ -22,7 +22,7 @@ module HorsePower
|
|
22
22
|
def createSettings
|
23
23
|
run "rails g rails_config:install"
|
24
24
|
prepend_to_file 'config/settings.yml' do
|
25
|
-
"token_header: \"Authorization\"\nmain_api_header: \"Main-Api-Header\"\nexpire_time: 4000\
|
25
|
+
"token_header: \"Authorization\"\nmain_api_header: \"Main-Api-Header\"\nexpire_time: 4000\nrevalidate_tokens: \"true\""
|
26
26
|
end
|
27
27
|
createEnvSettings
|
28
28
|
end
|
@@ -25,11 +25,14 @@ class Api::V1::ApplicationController < ::ActionController::API
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def set_hash
|
28
|
-
@instance_hash = ::TokenHash.decode(params,request)
|
28
|
+
@instance_hash = ::TokenHash.decode(params,request,response)
|
29
29
|
end
|
30
30
|
|
31
31
|
def current_user
|
32
32
|
if !@instance_hash.nil?
|
33
|
+
if !@instance_hash["user_id"].nil?
|
34
|
+
@instance_hash["current_owner"] = ::User.find_by(id: @instance_hash["user_id"])
|
35
|
+
end
|
33
36
|
return @instance_hash["current_owner"]
|
34
37
|
else
|
35
38
|
return nil
|
@@ -1,59 +1,66 @@
|
|
1
1
|
class TokenHash
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
def self.encode(auth_token_hash,user_id)
|
4
|
+
obj = {}
|
5
|
+
obj["auth_token"] = auth_token_hash
|
6
|
+
obj["user_id"] = user_id
|
7
|
+
#Lasts a 4th of the time as the db tokens
|
8
|
+
obj["exp"] = ::Time.now.to_i() + ::Settings.expire_time*15
|
9
|
+
return ::JWT.encode(obj,::Rails.application.secrets.secret_key_base)
|
10
|
+
end
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def self.decode(params,request,response)
|
13
|
+
instance_hash = nil
|
14
|
+
auth_token_obj = ::Arcadex::Header.grab_param_header(params,request,::Settings.token_header,false)
|
15
|
+
begin
|
16
|
+
# Try JWT token
|
17
|
+
jwt = ::JWT.decode(auth_token_obj,::Rails.application.secrets.secret_key_base)
|
18
|
+
token = jwt[0]
|
19
|
+
return make_hash(token["user_id"],token["auth_token"])
|
20
|
+
rescue ::JWT::ExpiredSignature
|
21
|
+
return handle_expired(auth_token_obj,params,request,response)
|
22
|
+
rescue ::JWT::DecodeError
|
23
|
+
return handle_abnormal(auth_token_obj,params,request,response)
|
24
|
+
end
|
25
|
+
end
|
16
26
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
def self.handle_expired(auth_token_obj,params,request,response)
|
28
|
+
# Token expired, destroy arcadex token
|
29
|
+
jwt = ::JWT.decode(auth_token_obj,::Rails.application.secrets.secret_key_base,true,{verify_expiration: false})
|
30
|
+
token = jwt[0]
|
31
|
+
# This is nil if the db_token is expired
|
32
|
+
db_token = ::Arcadex::Find.find_token_by_auth_token(token["auth_token"])
|
33
|
+
if db_token.nil?
|
34
|
+
return nil
|
35
|
+
else
|
36
|
+
if ::Settings.revalidate_tokens == "true"
|
37
|
+
# Send a new JWT back to the user since the db_token is still valid
|
38
|
+
new_token = encode(db_token.auth_token,token["user_id"])
|
39
|
+
response.headers[::Settings.token_header] = new_token
|
40
|
+
return make_hash(token["user_id"],token["auth_token"])
|
41
|
+
else
|
42
|
+
db_token.destroy
|
43
|
+
return nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
36
47
|
|
37
|
-
|
48
|
+
def self.handle_abnormal(auth_token_obj,params,request,response)
|
49
|
+
# Try Arcadex token
|
50
|
+
instance_hash = ::Arcadex::Authentication.get_instance(params,request,::Settings.token_header)
|
51
|
+
if !instance_hash.nil?
|
52
|
+
instance_hash["auth_token"] = nil
|
53
|
+
end
|
54
|
+
return instance_hash
|
55
|
+
end
|
38
56
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
return nil
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.handle_abnormal(params,request)
|
51
|
-
# Try Arcadex token
|
52
|
-
instance_hash = ::Arcadex::Authentication.get_instance(params,request,::Settings.token_header)
|
53
|
-
if !instance_hash.nil?
|
54
|
-
instance_hash["auth_token"] = nil
|
55
|
-
end
|
56
|
-
return instance_hash
|
57
|
-
end
|
57
|
+
def self.make_hash(user_id,auth_token)
|
58
|
+
instance_hash = {}
|
59
|
+
instance_hash["current_owner"] = nil
|
60
|
+
instance_hash["current_token"] = nil
|
61
|
+
instance_hash["user_id"] = user_id
|
62
|
+
instance_hash["auth_token"] = auth_token
|
63
|
+
return instance_hash
|
64
|
+
end
|
58
65
|
|
59
66
|
end
|
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: 1.0.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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|