Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- All authenticators now return an `Innmind\Immutable\Attempt`
- All authenticators can return any type inside the `Attempt`
- Requires `innmind/foundation:~1.9`

### Removed

Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
},
"require": {
"php": "~8.2",
"innmind/immutable": "~5.18",
"innmind/http": "~7.0"
"innmind/foundation": "~1.9"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 3 additions & 9 deletions src/ViaAuthorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
use Innmind\Http\{
ServerRequest,
Header\Authorization,
Header\AuthorizationValue,
};
use Innmind\Immutable\{
Attempt,
Predicate\Instance,
};
use Innmind\Immutable\Attempt;

/**
* @template T
*/
final class ViaAuthorization
{
/** @var callable(AuthorizationValue): Attempt<T> */
/** @var callable(Authorization): Attempt<T> */
private $resolve;

/**
* @param callable(AuthorizationValue): Attempt<T> $resolve
* @param callable(Authorization): Attempt<T> $resolve
*/
public function __construct(callable $resolve)
{
Expand All @@ -37,8 +33,6 @@ public function __invoke(ServerRequest $request): Attempt
return $request
->headers()
->find(Authorization::class)
->flatMap(static fn($header) => $header->values()->find(static fn() => true))
->keep(Instance::of(AuthorizationValue::class))
->attempt(static fn() => new \RuntimeException('Failed to resolve identity'))
->flatMap(fn($value) => ($this->resolve)($value));
}
Expand Down
11 changes: 5 additions & 6 deletions tests/ViaAuthorizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
Method,
ProtocolVersion,
Headers,
Header\Header,
Header\Value\Value,
Header,
Header\Value,
Header\Authorization,
Header\AuthorizationValue,
};
use Innmind\Url\Url;
use Innmind\Immutable\Attempt;
Expand Down Expand Up @@ -47,7 +46,7 @@ public function testReturnNothingWhenAuthorizationHeaderNotParsedCorrectly()
Method::get,
ProtocolVersion::v11,
Headers::of(
new Header('Authorization', new Value('Basic foo')),
Header::of('Authorization', Value::of('Basic foo')),
),
);

Expand All @@ -62,13 +61,13 @@ public function testInvokation()
$authenticate = new ViaAuthorization(
static fn($value) => Attempt::result($value),
);
$expected = new AuthorizationValue('Bearer', 'foo');
$expected = Authorization::of('Bearer', 'foo');
$request = ServerRequest::of(
Url::of('/'),
Method::get,
ProtocolVersion::v11,
Headers::of(
new Authorization($expected),
$expected,
),
);

Expand Down
6 changes: 3 additions & 3 deletions tests/ViaBasicAuthorizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
Method,
ProtocolVersion,
Headers,
Header\Header,
Header\Value\Value,
Header,
Header\Value,
Header\Authorization,
};
use Innmind\Url\Url;
Expand Down Expand Up @@ -46,7 +46,7 @@ public function testReturnNothingWhenAuthorizationHeaderNotParsedCorrectly()
Method::get,
ProtocolVersion::v11,
Headers::of(
new Header('Authorization', new Value('Basic foo')),
Header::of('Authorization', Value::of('Basic foo')),
),
);

Expand Down
Loading