diff --git a/lib/OIDCAuth.php b/lib/OIDCAuth.php index 58d04f2..a541dd3 100644 --- a/lib/OIDCAuth.php +++ b/lib/OIDCAuth.php @@ -40,6 +40,27 @@ public function Authenticate() } } + function ReAuthenticate() { + if ( !empty($this->refresh_token) ) { + $oidc = new OpenIDConnectClient(SparkAPI_OIDCAuth::SPARK_PROVIDER, + $this->oauth_key, + $this->oauth_secret + ); + + try { + $oidc->refreshToken($this->refresh_token); + $this->SetAccessToken($oidc->getAccessToken()); + $this->SetRefreshToken($oidc->getRefreshToken()); + + return true; + } catch (OpenIDConnectClientException $e) { + throw new \Exception($e->getMessage(), $e->getCode()); + } + + } + return false; + } + function sign_request($request) { $this->SetHeader('Authorization', 'Bearer '. $this->last_token); @@ -73,4 +94,9 @@ function forceHttps() { $this->force_https = true; } + + function is_auth_request($request) { + return ($request['uri'] == '/'. $this->api_version .'/openid/token') ? true : false; + } + } \ No newline at end of file