Skip to content

Commit

Permalink
Added endpoint authentication support to adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
basdenooijer committed Jan 22, 2013
1 parent c4a8b6a commit 3784276
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion library/Solarium/Core/Client/Adapter/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ public function createContext($request, $endpoint)
}
}

$authData = $request->getAuthentication();
// Try endpoint authentication first, fallback to request for backwards compatibility
$authData = $endpoint->getAuthentication();
if(empty($authData['username'])) $authData = $request->getAuthentication();

if ( !empty($authData['username']) && !empty($authData['password'])) {
$request->addHeader('Authorization: Basic ' . base64_encode($authData['username']. ':' . $authData['password'] ));
}
Expand Down
5 changes: 4 additions & 1 deletion library/Solarium/Core/Client/Adapter/PeclHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ public function toHttpRequest($request, $endpoint)
}
}

$authData = $request->getAuthentication();
// Try endpoint authentication first, fallback to request for backwards compatibility
$authData = $endpoint->getAuthentication();
if(empty($authData['username'])) $authData = $request->getAuthentication();

if ( !empty($authData['username']) && !empty($authData['password'])) {
$headers['Authorization'] = 'Basic ' . base64_encode($authData['username']. ':' . $authData['password'] );
}
Expand Down

0 comments on commit 3784276

Please sign in to comment.