diff --git a/auth/.env b/auth/.env index 1984457..8436766 100644 --- a/auth/.env +++ b/auth/.env @@ -1,5 +1,5 @@ -version: '3' -services: - your-service: - environment: - - JWT_SECRET_KEY=your_actual_secret_key \ No newline at end of file +# .env + +DATABASE_URL=postgres://username:password@localhost/mydatabase +JWT_SECRET_KEY=qd9NLicyHJNF9A85IrE72a4GL5Rrk6rQzbERvYn6Z7BZN0SrlLZQWruJCcIRXEh4GKH_WyXquzUGTs4zvh65L84B9ZCg7r99257U2yu1WzhF8mpj7uZ06j9jBNTBvCgNO3qemh-kd4XjekpYZ9Et38T1sgksPFpF5w99gOLsHm3iUfIqa-slTplGQr3rzqIy_9HJAXv66lmx12XOAYEWv9cISIHVp6itL8v7pl38dqn0RoYGJxc2f6BHKpNzESGrsmg-xQztfkRw-EtoDEIBEdBEvitc_h2ilj2Dm2dVaEYR41jlBrWsuCi13c0EWh_N5hq37U7rOQzZwFhzAKzujw +API_KEY=your_api_key \ No newline at end of file diff --git a/auth/Gemfile b/auth/Gemfile index 5d8e98d..b238a1b 100644 --- a/auth/Gemfile +++ b/auth/Gemfile @@ -13,6 +13,6 @@ gem 'bcrypt' gem 'securerandom' gem 'json' gem 'multipart-post' - +gem 'dotenv' # bundle install \ No newline at end of file diff --git a/auth/Gemfile.lock b/auth/Gemfile.lock index b15c7c4..6ecbd40 100644 --- a/auth/Gemfile.lock +++ b/auth/Gemfile.lock @@ -2,6 +2,7 @@ GEM remote: https://rubygems.org/ specs: bcrypt (3.1.20) + dotenv (2.8.1) json (2.7.1) jwt (2.7.1) multipart-post (2.3.0) @@ -26,6 +27,7 @@ PLATFORMS DEPENDENCIES bcrypt + dotenv json jwt multipart-post diff --git a/auth/auth.rb b/auth/auth.rb index c23dd6f..2afee24 100644 --- a/auth/auth.rb +++ b/auth/auth.rb @@ -9,31 +9,10 @@ require 'sinatra' require 'json' require 'sqlite3' require 'jwt' +require 'dotenv/load' -TOKEN_SECRET = 'WChX-tQWbGbj_pGJQREoFAZGC9JWh58KSk8O7KPj-P8Nd-J88g3eSFDVuNe6zddj0ZB3yxjm_IuPNPyLhiSnxlWHImqXR6ajh3OzrzYm0bNb3f5C4IAScphyEdAfYGMcM-HvYOXxxxp5u5mryfiV3JH1CTqL1CzGyO8df7zUpRKXEXZ5SKmUvhfLU0XKCR_28FAZUgPCAi3GywkDDsH0by68j33BU5cnMT8KiEkHOX4wVUVDQc85_AuE7fN3ji_WkhnDCSLXU9dBCcXM3ziFFeX0RbvIRDG0vKdzwt4TOr4Jws7NP9w11GrUGDFKARZqvT7FTxwxO3MM-mmjb2xyGg' - -set :public_folder, DATA_LOCATION + FILE_STORAGE_LOCATION - -#puts generate_random_string(256) - - -# -#token = JWT.encode payload, hmac_secret, 'HS256' -##puts token -# -#begin -# decoded_token = JWT.decode token, hmac_secret, true, { algorithm: 'HS256' } -# puts "Token is valid!" -# puts "Decoded token: #{decoded_token}" -# -# puts data_value = decoded_token.first['data'] -# puts test_value = decoded_token.first['test'] -#rescue JWT::DecodeError -# puts "Invalid token or signature!" -#end - -#puts decoded_token - +TOKEN_SECRET = ENV['JWT_SECRET_KEY'] +puts TOKEN_SECRET initialize_database post '/auth/login' do @@ -79,9 +58,9 @@ post '/auth/reauthenticate' do # At this point, the token is valid # You can access the claims inside the 'decoded_token' variable - uid = decoded_token.first['uid'] + # Your reauthentication logic here... # Return a response (replace with your own logic) diff --git a/auth/initialize_database.rb b/auth/initialize_database.rb index 266281f..fa8d742 100644 --- a/auth/initialize_database.rb +++ b/auth/initialize_database.rb @@ -7,7 +7,6 @@ def initialize_database database_path = DATA_LOCATION + DATABASE_SUBPATH file_path = DATA_LOCATION + FILE_STORAGE_LOCATION - puts database_path unless File.directory?(DATA_LOCATION) Dir.mkdir(DATA_LOCATION)