From 80ab4b191c3acd435355664d9974c71ccee7a1f9 Mon Sep 17 00:00:00 2001 From: Andrew Scofield Date: Wed, 17 Jul 2019 13:53:49 -0500 Subject: [PATCH] added reauthentication and is_auth_request functions to OIDCAuth since they get called from Core --- lib/OIDCAuth.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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