Compare commits
No commits in common. "b742e228b304ae356ea375174179f2b309ea0f44" and "29c8bb368f3e53543084e7f6d421983cdecd24d6" have entirely different histories.
b742e228b3
...
29c8bb368f
|
@ -1,5 +1,3 @@
|
||||||
bin/
|
bin/
|
||||||
auth/data/
|
|
||||||
|
|
||||||
*.db
|
*.db
|
||||||
|
|
||||||
|
|
|
@ -18,3 +18,4 @@ end
|
||||||
def generate_random_string(length)
|
def generate_random_string(length)
|
||||||
SecureRandom.urlsafe_base64(length)
|
SecureRandom.urlsafe_base64(length)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,7 @@ def update_user_password(user_id, password)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_claims (user_id)
|
def get_claims (user_id)
|
||||||
|
puts "Getting claims for #{user_id}"
|
||||||
db = SQLite3::Database.new( DATA_LOCATION + DATABASE_SUBPATH + DATABASE_NAME )
|
db = SQLite3::Database.new( DATA_LOCATION + DATABASE_SUBPATH + DATABASE_NAME )
|
||||||
results = db.execute('
|
results = db.execute('
|
||||||
SELECT C.claim
|
SELECT C.claim
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
|
|
||||||
def get_reauth_jwt (user_id)
|
|
||||||
#claims = get_claims user_id
|
|
||||||
|
|
||||||
iat = Time.now.to_i
|
|
||||||
exp = iat + 10
|
|
||||||
|
|
||||||
payload = {
|
|
||||||
sub: 'reauthentication' ,
|
|
||||||
admin: check_if_user_is_admin(user_id),
|
|
||||||
iss: 'roysathome.net',
|
|
||||||
uid: user_id, #Example id
|
|
||||||
iat: Time.now.to_i,
|
|
||||||
exp: Time.now.to_i + 3600
|
|
||||||
}
|
|
||||||
|
|
||||||
return JWT.encode payload, TOKEN_SECRET, 'HS256'
|
|
||||||
#data: {time: 'now', help: 'no'}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_jwt (user_id)
|
|
||||||
claims = get_claims user_id
|
|
||||||
|
|
||||||
iat = Time.now.to_i
|
|
||||||
exp = iat + 60
|
|
||||||
|
|
||||||
payload = {
|
|
||||||
sub: 'authentication' ,
|
|
||||||
admin: check_if_user_is_admin(user_id),
|
|
||||||
iss: 'roysathome.net',
|
|
||||||
uid: user_id, #Example id
|
|
||||||
iat: iat,
|
|
||||||
exp: exp,
|
|
||||||
claims: claims
|
|
||||||
}
|
|
||||||
|
|
||||||
return JWT.encode payload, TOKEN_SECRET, 'HS256'
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def decode_token(base64_encoded_token)
|
|
||||||
return JWT.decode(base64_encoded_token, TOKEN_SECRET, true, algorithm: 'HS256')
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_and_check_token(request)
|
|
||||||
authorization_header = request.env['HTTP_AUTHORIZATION']
|
|
||||||
|
|
||||||
unless authorization_header && authorization_header.match(/^Bearer (.+)/)
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
return reauth_token = Regexp.last_match(1)
|
|
||||||
end
|
|
Loading…
Reference in New Issue