other changes
This commit is contained in:
parent
29c8bb368f
commit
62730b3f31
|
@ -1,3 +1,5 @@
|
|||
bin/
|
||||
auth/data/
|
||||
|
||||
*.db
|
||||
|
||||
|
|
|
@ -17,5 +17,4 @@ end
|
|||
|
||||
def generate_random_string(length)
|
||||
SecureRandom.urlsafe_base64(length)
|
||||
end
|
||||
|
||||
end
|
|
@ -76,7 +76,6 @@ def update_user_password(user_id, password)
|
|||
end
|
||||
|
||||
def get_claims (user_id)
|
||||
puts "Getting claims for #{user_id}"
|
||||
db = SQLite3::Database.new( DATA_LOCATION + DATABASE_SUBPATH + DATABASE_NAME )
|
||||
results = db.execute('
|
||||
SELECT C.claim
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,53 @@
|
|||
|
||||
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