Skip to content

Commit

Permalink
deal with basic auth credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed May 12, 2024
1 parent 7a22150 commit cae2abc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/assets/javascripts/controllers/detailedDoc.js
Expand Up @@ -14,10 +14,16 @@ angular.module('QuepidApp')

$scope.linkToDoc = function() {
let url = $scope.doc._url();

if (settingsSvc.applicableSettings().basicAuthCredential){
var credentials = settingsSvc.applicableSettings().basicAuthCredential;
url = url.replace('://', '://' + credentials + '@');
}

if (settingsSvc.applicableSettings().proxyRequests === true) {
url = caseTryNavSvc.getQuepidProxyUrl() + url;
}

return url;
};

Expand Down
9 changes: 9 additions & 0 deletions app/controllers/proxy_controller.rb
Expand Up @@ -26,6 +26,10 @@ def fetch
uri = URI.parse(url_param)
url_without_path = "#{uri.scheme}://#{uri.host}"
url_without_path += ":#{uri.port}" unless uri.port.nil?





connection = Faraday.new(url: url_without_path) do |faraday|
# Configure the connection options, such as headers or middleware
Expand All @@ -43,6 +47,11 @@ def fetch
end

faraday.headers['Content-Type'] = 'application/json'
has_credentials = !uri.userinfo.nil?
if has_credentials
username, password = uri.userinfo.split(':')
faraday.headers['Authorization'] = 'Basic ' + Base64.strict_encode64("#{username}:#{password}")
end
faraday.adapter Faraday.default_adapter
end

Expand Down

0 comments on commit cae2abc

Please sign in to comment.