Skip to content

Commit

Permalink
UML-3132 service api one login dummy endpoint returns a user (#2398)
Browse files Browse the repository at this point in the history
* UML-3132 service api one login dummy endpoint returns a user

* Rename handler and return test user details

* Rename api calls
  • Loading branch information
MishNajam authored Nov 6, 2023
1 parent 46c77d1 commit 488c59b
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 5 deletions.
6 changes: 4 additions & 2 deletions service-api/app/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use App\Handler\LpasResourceHandler;
use App\Handler\LpasResourceImagesCollectionHandler;
use App\Handler\NotifyHandler;
use App\Handler\OneLoginAuthenticationCallbackHandler;
use App\Handler\OneLoginAuthenticationRequestHandler;
use App\Handler\RequestChangeEmailHandler;
use App\Handler\RequestCleanseHandler;
use App\Handler\RequestPasswordResetHandler;
Expand All @@ -29,7 +31,6 @@
use Mezzio\Application;
use Mezzio\MiddlewareFactory;
use Psr\Container\ContainerInterface;
use App\Handler\OneLoginAuthenticationRequestHandler;

/**
* Setup routes with a single request method:
Expand Down Expand Up @@ -135,7 +136,8 @@

$app->patch('/v1/auth', AuthHandler::class, 'user.auth');

$app->get('/v1/auth-one-login', OneLoginAuthenticationRequestHandler::class, 'user.auth-one-login');
$app->get('/v1/auth/start', OneLoginAuthenticationRequestHandler::class, 'user.auth-start');
$app->get('/v1/auth/callback', OneLoginAuthenticationCallbackHandler::class, 'user.auth-callback');

$app->post('/v1/email-user/{emailTemplate}', NotifyHandler::class, 'lpa.user.notify');
};
31 changes: 31 additions & 0 deletions service-api/app/features/context/Acceptance/AccountContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1292,4 +1292,35 @@ public function iShouldBeToldThatABadRequestWasMade(): void
{
$this->ui->assertSession()->statusCodeEquals(StatusCodeInterface::STATUS_BAD_REQUEST);
}

/**
* @Given /^I am on the temporary one login page$/
*/
public function iAmOnTheTemporaryOneLoginPage(): void
{
// Not needed in this context
}

/**
* @When /^I click the one login button$/
*/
public function iClickTheOneLoginButton(): void
{
// Not needed in this context
}

/**
* @Then /^I am redirected to the redirect page$/
*/
public function iAmRedirectedToTheRedirectPage(): void
{
$this->apiGet('/v1/auth/callback', []);

$this->ui->assertSession()->statusCodeEquals(StatusCodeInterface::STATUS_OK);

$response = $this->getResponseAsJson();

Assert::assertEquals('bf9e7e77-f283-49c6-a79c-65d5d309ef77', $response['Id']);
Assert::assertEquals('[email protected]', $response['Email']);
}
}
8 changes: 8 additions & 0 deletions service-api/app/features/one-login.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@actor @onelogin
Feature: Authorise One Login

@acceptance
Scenario: I initiate authentication via one login
Given I am on the temporary one login page
When I click the one login button
Then I am redirected to the redirect page
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace App\Handler;

use DateTime;
use DateTimeInterface;
use Exception;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
* @codeCoverageIgnore
*/
class OneLoginAuthenticationCallbackHandler implements RequestHandlerInterface
{
public function __construct()
{
}

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
* @throws Exception
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$requestData = $request->getQueryParams();

$user = [
'Id' => 'bf9e7e77-f283-49c6-a79c-65d5d309ef77',
'Email' => '[email protected]',
'LastLogin' => (new DateTime('-1 day'))->format(DateTimeInterface::ATOM),
];

return new JsonResponse($user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(private ApiClient $apiClient)

public function authenticate(string $uiLocale, string $redirectUrl): ?array
{
return $this->apiClient->httpGet('/v1/auth-one-login', [
return $this->apiClient->httpGet('/v1/auth/start', [
'ui_locale' => $uiLocale,
'redirect_url' => $redirectUrl,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function can_get_authentication_request_uri(): void

$apiClientProphecy
->httpGet(
'/v1/auth-one-login',
'/v1/auth/start',
[
'ui_locale' => 'en',
'ui_locale' => 'en',
'redirect_url' => $redirect,
]
)->willReturn(['state' => $state, 'nonce' => $nonce, 'url' => $uri]);
Expand Down

0 comments on commit 488c59b

Please sign in to comment.