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

@ -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;