registration procedure: WIP

parent a2ec19ff
......@@ -183,31 +183,17 @@ class OAuthOSTConsumer implements AuthenticationProviderInterface
$oauth->enableDebug();
$this->logger->warning("i am here:" . "oauthToken=" . $authToken . " state=" . $_SESSION['state']);
if (($authToken == null || !$authToken) && !$_SESSION['state']) {
$this->logger->warning("send request token");
$requestToken = $oauth->getRequestToken($this->request_token_url, $this->callback_url);
$this->logger->warning("send request token");
$requestToken = $oauth->getRequestToken($this->request_token_url, $this->callback_url);
// store auth token
$this->logger->warning("requestToken=" . $requestToken['oauth_token_secret']);
$_SESSION['secret'] = $requestToken['oauth_token_secret'];
$_SESSION['state'] = 1;
$this->logger->warning("requestToken=" . $requestToken['oauth_token_secret']);
$_SESSION['secret'] = $requestToken['oauth_token_secret'];
$_SESSION['state'] = 1;
// $_SESSION['secret'] = $request_token['oauth_token_secret'];
header('Location: '.$this->user_authorization_url.'?oauth_token='.$requestToken['oauth_token']);
exit;
} else if ($_SESSION['state']==1) {
$oauth->setToken($authToken, $_SESSION['secret']);
$this->logger->warning("oauthToken=" . $authToken . "***" . $_SESSION['secret']);
$accessToken = $oauth->getAccessToken($this->access_token_url, '', $authVerifier);
$this->logger->warning("accessToken=" . $accessToken['oauth_token'] . "***" . $accessToken['oauth_token_secret']);
$_SESSION['state'] = 2;
$_SESSION['token'] = $accessToken['oauth_token'];
$_SESSION['secret'] = $accessToken['oauth_token_secret'];
// $_SESSION['token'] = serialize($access_token);
}
$this->logger->warning("about to call web service");
$oauth->setToken($_SESSION['token'],$_SESSION['secret']);
$oauth->fetch($this->api_url);
header('Location: '.$this->user_authorization_url.'?oauth_token='.$requestToken['oauth_token']);
$this->logger->warning("redirected to:" . $this->user_authorization_url . '?oauth_token=' . $requestToken['oauth_token']);
exit;
} catch (OAuthException $e) {
......@@ -221,6 +207,7 @@ class OAuthOSTConsumer implements AuthenticationProviderInterface
// return null;
}
/**
* {@inheritdoc}
*/
......
......@@ -9,6 +9,9 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\oauthost\Authentication\Provider;
use OAuth;
use OAuthException;
class CBController extends ControllerBase {
......@@ -17,6 +20,17 @@ class CBController extends ControllerBase {
protected $request;
protected $logger;
protected $consumer_key = 'tc97t89';
protected $consumer_secret = 'xr7tgt9AbK3';
protected $request_token_url = 'https://www1.gsis.gr/gsisapps/gsisdemo/oauth/request_token';
protected $user_authorization_url = 'https://www1.gsis.gr/gsisapps/gsisdemo/oauth/confirm_access';
protected $access_token_url = 'https://www1.gsis.gr/gsisapps/gsisdemo/oauth/access_token';
protected $signature_method = 'PLAINTEXT';
protected $api_url = 'https://www1.gsis.gr/gsisapps/gsisdemo/gsisdemoservice/resource_one';
protected $callback_url = 'http://eepal.dev/drupal/oauth/cb';
protected $logout_url = 'https://www1.gsis.gr/testgsisapps/gsisdemo/logout.htm?logout_token=';
public function __construct(EntityTypeManagerInterface $entityTypeManager, QueryFactory $query_factory) {
$this->entityTypeManager = $entityTypeManager;
$this->query_factory = $query_factory;
......@@ -38,7 +52,58 @@ public function loginCB() {
$this->logger->notice("authToken=".$authToken."***authVerifier=".$authVerifier);
/* $response = new JsonResponse(['hello' => 'world', 'name' => $name, 'authToken' => $authToken, 'accessKey' => $accessKey]);
$response->headers->set('X-AUTH-TOKEN', 'HELLOTOKEN'); */
return new RedirectResponse('/dist/#/?auth_token=' . $authToken . '&auth_role=student',302,[]);
$authenticated = $this->authenticatePhase2($authToken, $authVerifier);
if ($authenticated) {
return new RedirectResponse('/dist/#/?auth_token=' . $authToken . '&auth_role=student',302,[]);
}
else {
return new RedirectResponse('/dist/#/',403,[]);
}
}
public function authenticatePhase2($authToken, $authVerifier)
{
try {
$oauth = new OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_PLAINTEXT, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
$this->logger->warning("i am here:" . "oauthToken=" . $authToken . " state=" . $_SESSION['state']);
$oauth->setToken($authToken, $_SESSION['secret']);
$this->logger->warning("oauthToken=" . $authToken . "***" . $_SESSION['secret']);
$accessToken = $oauth->getAccessToken($this->access_token_url, '', $authVerifier);
$this->logger->warning("accessToken=" . $accessToken['oauth_token'] . "***" . $accessToken['oauth_token_secret']);
$_SESSION['state'] = 2;
$_SESSION['token'] = $accessToken['oauth_token'];
$_SESSION['secret'] = $accessToken['oauth_token_secret'];
$this->logger->warning("about to call web service");
$oauth->setToken($_SESSION['token'],$_SESSION['secret']);
$oauth->fetch($this->api_url);
$this->logger->warning($oauth->getLastResponse());
$epalUser = $this->entityTypeManager()->getStorage('epal_users')->loadByProperties(['taxis_userid' => '12345']);
if ($epalUser === null || !$epalUser) {
}
return true;
} catch (OAuthException $e) {
$this->logger->warning($e->getMessage());
return false;
}
return false;
// Check if we found a user.
/* if (!empty($this->user)) {
return $this->user;
} */
// return null;
}
}
export class AppSettings {
public static get API_ENDPOINT(): string {
return 'http://localhost/drupal';
// return 'http://eepal.dev/drupal';
// return 'http://localhost/drupal';
return 'http://eepal.dev/drupal';
// return 'http://eduslim2.minedu.gov.gr/drupal';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment