method) { case "GET": try { $profile = new oAuthProfile(common::clearInput($request->function,"0-9")); } catch (\Exception $e) { if ($e->getCode()==691) { throw new foxException("Not found",404); } else { throw $e; } } if ($profile->deleted || !$profile->enabled) { throw new foxException("Not found",404); } return [ "id"=>$profile->id, "name"=>$profile->name, "url"=>$profile->getClient(config::get("SITEPREFIX")."/auth/oauth")->getAuthURL(), "icon"=>$profile->getClient(config::get("SITEPREFIX"))->getAuthIcon(), ]; break; case "POST": $profile = oAuthProfile::getByHash(common::clearInput($request->requestBody->hash)); $oac = $profile->getClient(config::get("SITEPREFIX")."/auth/oauth"); $oac->getTokenByCode(common::clearInput($request->requestBody->code)); $userInfo=$oac->getUserInfo(); $userRefId=$profile->id.":".$userInfo->sub; $u=user::getByRefID("oauth",$userRefId); if (!$u) { foxException::throw("ERR", "User not registered",401,"UNR"); } $t = authToken::issue($u, "WEB"); return [ "token" => $t->token, "expire" => $t->expireStamp->isNull() ? "Never" : $t->expireStamp, "jwt"=>authJwt::issueByAuthToken($t) ]; break; default: throw new foxException("Method not implemented",405); } } }