MDL-58220 oauth2: Add is_configured to issuer

Saves repeated checks for clientid and clientsecret.
This commit is contained in:
Damyon Wiese 2017-03-28 11:25:04 +08:00
parent 5aa0f0ae48
commit 5b0b35c096
3 changed files with 14 additions and 4 deletions

View File

@ -85,7 +85,7 @@ class renderer extends plugin_renderer_base {
$namecell->header = true;
// Configured.
if (!empty($issuer->get('clientid')) && !empty($issuer->get('clientsecret'))) {
if ($issuer->is_configured()) {
$configured = $OUTPUT->pix_icon('yes', get_string('configured', 'tool_oauth2'), 'tool_oauth2');
} else {
$configured = $OUTPUT->pix_icon('no', get_string('notconfigured', 'tool_oauth2'), 'tool_oauth2');

View File

@ -187,9 +187,7 @@ class auth extends \auth_plugin_base {
*/
private function is_ready_for_login_page(\core\oauth2\issuer $issuer) {
return $issuer->get('enabled') &&
!empty($issuer->get('clientid')) &&
!empty($issuer->get('clientsecret')) &&
$issuer->is_authentication_supported() &&
$issuer->is_configured() &&
!empty($issuer->get('showonloginpage'));
}

View File

@ -162,6 +162,15 @@ class issuer extends persistent {
return (!empty($this->get_endpoint_url('userinfo')));
}
/**
* Return true if this issuer looks like it has been configured.
*
* @return boolean
*/
public function is_configured() {
return (!empty($this->get('clientid')) && !empty($this->get('clientsecret')));
}
/**
* Does this OAuth service support system authentication?
* @return boolean
@ -175,6 +184,9 @@ class issuer extends persistent {
* @return boolean
*/
public function is_system_account_connected() {
if (!$this->is_configured()) {
return false;
}
$sys = system_account::get_record(['issuerid' => $this->get('id')]);
if (!empty($sys) and !empty($sys->get('refreshtoken'))) {
return true;