Skip to content

Commit

Permalink
Return app_name and domain when parsing url
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsantos-sfdc committed Apr 5, 2024
1 parent 8fccc2c commit 1faf796
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions app/controllers/authenticating_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def heroku_app
unless match
raise 'Could not determine heroku app from host'
end

match[1]
# match[1] is the app name, [2] would be the high level domain (herokuapp or staging.herokuappdev)
return match[1], match[2]
end
end

Expand All @@ -40,18 +40,25 @@ def get_app_info(heroku_api, app_name)
end
end

def platform_api_client(token, domain)
if domain.end_with?("herokuappdev")
return PlatformAPI.connect_oauth(token, url: "https://api.staging.herokudev.com")
end
PlatformAPI.connect_oauth(token)
end

def authenticate_user!
auth_header = request.authorization
app_name = heroku_app
app_name, domain = heroku_app
# try first to authenticate the request from Bearer token authorization header and
# if that doesn't work try the previous session_id from the cookies
if auth_header
token = auth_header.match(/Bearer (.*)$/)[1]
heroku_api = PlatformAPI.connect_oauth(token)
heroku_api = platform_api_client(token, domain)
get_app_info(heroku_api, app_name)
elsif session && session['token'] && session['email']
session = cookies.encrypted[:_session_id]
heroku_api = PlatformAPI.connect_oauth(session['token'])
heroku_api = platform_api_client(session['token'], domain)
get_app_info(heroku_api, app_name)
session['email']
end
Expand Down

0 comments on commit 1faf796

Please sign in to comment.