-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponseTypeGuesser.php
More file actions
41 lines (33 loc) · 1.61 KB
/
ResponseTypeGuesser.php
File metadata and controls
41 lines (33 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace OAuth2Framework\Component\AuthorizationEndpoint;
use Assert\Assertion;
use OAuth2Framework\Component\AuthorizationEndpoint\AuthorizationRequest\AuthorizationRequest;
use OAuth2Framework\Component\AuthorizationEndpoint\ResponseType\ResponseType;
use OAuth2Framework\Component\AuthorizationEndpoint\ResponseType\ResponseTypeManager;
use function Safe\sprintf;
class ResponseTypeGuesser
{
private ResponseTypeManager $responseTypeManager;
public function __construct(ResponseTypeManager $responseTypeManager)
{
$this->responseTypeManager = $responseTypeManager;
}
public function get(AuthorizationRequest $authorization): ResponseType
{
// @see http://tools.ietf.org/html/rfc6749#section-3.1.1
Assertion::true($authorization->hasQueryParam('response_type'), 'The parameter "response_type" is mandatory.');
$responseTypeName = $authorization->getQueryParam('response_type');
Assertion::true($this->responseTypeManager->has($responseTypeName), sprintf('The response type "%s" is not supported by this server', $responseTypeName));
Assertion::true($authorization->getClient()->isResponseTypeAllowed($responseTypeName), sprintf('The response type "%s" is not allowed for this client.', $responseTypeName)); // Should try to find the response mode before exception
return $this->responseTypeManager->get($responseTypeName);
}
}