Skip to content

Commit

Permalink
gets userinfo from PMSSO access_token
Browse files Browse the repository at this point in the history
  • Loading branch information
tamw-wnet committed Sep 13, 2024
1 parent a3cf5b0 commit 2e68e83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions classes/class-PMSSO-Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function code_exchange($code= '', $code_verifier= ''){
$tokeninfo['messages'] = 'broke on code exchange';
return $tokeninfo;
}
$tokeninfo = $this->update_pbs_tokeninfo($tokeninfo);
$tokeninfo = $this->update_pmsso_tokeninfo($tokeninfo);
return $tokeninfo;
}

Expand Down Expand Up @@ -492,19 +492,20 @@ public function get_latest_pbs_userinfo($access_token = '') {
$ch = $this->build_curl_handle($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $customheaders);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$userinfo_json = curl_exec($ch);
$response_json = curl_exec($ch);
$info = curl_getinfo($ch);
$errors = curl_error($ch);
curl_close($ch);
$userinfo = json_decode($userinfo_json, true);
if (isset($userinfo['email'])){
$response = json_decode($response_json, true);
if (isset($response['profile'])) {
$userinfo = $response['profile'];
// append the VPPA status
$userinfo = $this->derive_and_append_vppa_status($userinfo);
return $userinfo;
} else {
$userinfo['curlinfo'] = $info;
$userinfo['curlerrors'] = $errors;
return $userinfo;
$response['curlinfo'] = $info;
$response['curlerrors'] = $errors;
return $response;
}
}

Expand Down Expand Up @@ -558,12 +559,12 @@ private function store_pbs_userinfo($userinfo) {

public function derive_and_append_vppa_status($userinfo) {
$vppa_status = 'false';
if (!empty($userinfo['vppa']['vppa_last_updated'])) {
if (!empty($userinfo['vppa_last_updated'])) {
$vppa_status = 'valid';
if (strtotime($userinfo['vppa']['vppa_last_updated']) < strtotime('-2 years') ){
if (strtotime($userinfo['vppa_last_updated']) < strtotime('-2 years') ){
$vppa_status = 'expired';
}
if ($userinfo['vppa']['vppa_accepted'] !== true) {
if ($userinfo['vppa_accepted'] !== true) {
$vppa_status = 'rejected';
}
}
Expand Down
2 changes: 1 addition & 1 deletion classes/class-pbs-passport-authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function get_pmsso_client($args = null){
$defaults = $this->defaults;
$redirect_uri = ( !empty($args['redirect_uri']) ? $args['redirect_uri'] : site_url('pbsoauth/callback/') );
$client_id = ( !empty($args['pmsso_client_id']) ? $args['pmsso_client_id'] : $defaults['pmsso_client_id'] );
$customer_id = ( !empty($args['pmsso_customer_id']) ? $args['pmsso_customer_id'] : $defaults['pmsso_customer_id'] );
$customer_id = ( !empty($args['pmsso_customerid']) ? $args['pmsso_customerid'] : $defaults['pmsso_customerid'] );
$client_secret = ( !empty($args['pmsso_client_secret']) ? $args['pmsso_client_secret'] : null );
$app_id = ( !empty($args['pmsso_app_id']) ? $args['pmsso_app_id'] : $defaults['pmsso_app_id'] );

Expand Down

0 comments on commit 2e68e83

Please sign in to comment.