<?php
// AuthNogui.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Authentication\login;use Psr\Http\Message\ResponseInterface;use DI\Container;use Nyholm\Psr7\Stream;use Docuform\Api\Authentication\Repositories\UserRepository;use Docuform\Api\Authentication\Repositories\ApiClientRepository;use Docuform\Api\ApiScopes;global $g_params;$g_params=array();if(file_exists('auth/login-config.php'))include 'auth/login-config.php';require_once 'AuthInterface.php';class AuthNogui implements AuthInterface{private $m_container;public function __construct(Container $container,array $params){global $g_params;$this->m_container=$container;$g_params=$params;if($g_params===null){}}public function Authorize($request,$response):ResponseInterface{$this->initialize();$bodyStream=Stream::create('');$uri=$request->getUri();$jsPayload=array('uri'=>$uri->getPath());$bodyStream->write(json_encode($jsPayload,JSON_UNESCAPED_SLASHES));$response=$response->withStatus(200)->withBody($bodyStream);return $response;}public function ProcessResponse($response,$params):string{$result='';$authTokenNeeded=in_array(ApiScopes::mcs,explode(' ',$params['scope']));if(!empty($params['username'])&&(!empty($params['password'])||($authTokenNeeded&&!empty($params['authToken'])))){$clientrepo=new ApiClientRepository($this->m_container);$userrepo=new UserRepository($this->m_container);$client=$clientrepo->getClientEntity($params['client_id']);$password='';if(!empty($params['password'])){$password=$params['password'];}if($authTokenNeeded){$this->m_container->set('authToken',!empty($params['authToken'])?$params['authToken']:'?');}if($client!=null&&(!empty($password)||$authTokenNeeded))$user=$userrepo->getUserEntityByUserCredentials($params['username'],$password,$params['response_type'],$client,false);if($user!=null)$result=$user->getIdentifier();}return $result;}private function initialize():void{}}