MDL-59512 tool_oauth2: add option for basic authentication

This commit is contained in:
yair.spielmann
2017-11-17 10:22:01 +01:00
committed by Jan Dageförde
parent 6f1a49b8b7
commit afcb4cd69a
8 changed files with 46 additions and 5 deletions
+10 -2
View File
@@ -403,6 +403,8 @@ abstract class oauth2_client extends curl {
private $mocknextresponse = '';
/** @var array $upgradedcodes list of upgraded codes in this request */
private static $upgradedcodes = [];
/** @var bool basicauth */
protected $basicauth = false;
/**
* Returns the auth url for OAuth 2.0 request
@@ -542,12 +544,18 @@ abstract class oauth2_client extends curl {
public function upgrade_token($code) {
$callbackurl = self::callback_url();
$params = array('code' => $code,
'client_id' => $this->clientid,
'client_secret' => $this->clientsecret,
'grant_type' => 'authorization_code',
'redirect_uri' => $callbackurl->out(false),
);
if ($this->basicauth) {
$idsecret = urlencode($this->clientid) . ':' . urlencode($this->clientsecret);
$this->setHeader('Authorization: Basic ' . base64_encode($idsecret));
} else {
$params['client_id'] = $this->clientid;
$params['client_secret'] = $this->clientsecret;
}
// Requests can either use http GET or POST.
if ($this->use_http_get()) {
$response = $this->get($this->token_url(), $params);