Skip to content

Commit

Permalink
revert "remove legacy auth validation"
Browse files Browse the repository at this point in the history
This reverts commit da0bd09.
  • Loading branch information
michavie committed Feb 29, 2024
1 parent 4267a68 commit 3814724
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Auth/NativeAuthServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __construct(
public ?string $apiUrl = null,
public array $acceptedOrigins = [],
public int $maxExpirySeconds = 86400,
public bool $skipLegacyValidation = false,
) {
}

Expand Down Expand Up @@ -70,6 +71,17 @@ public function validate(string $accessToken): NativeAuthValidateResult
$valid = UserVerifier::fromAddress(Address::fromBech32($decoded->address))
->verify(new Bytes($verifiable->serializeForSigning()), new Bytes($verifiable->signature->hex()), $verifiable->address->getPublicKey());

if (! $valid && ! $this->skipLegacyValidation) {
$verifiable = new SignableMessage(
message: "{$decoded->address}{$decoded->body}{}",
signature: new Signature($decoded->signature),
address: Address::fromBech32($decoded->address),
);

$valid = UserVerifier::fromAddress(Address::fromBech32($decoded->address))
->verify(new Bytes($verifiable->serializeForSigning()), new Bytes($verifiable->signature->hex()), $verifiable->address->getPublicKey());
}

throw_unless($valid, NativeAuthInvalidSignatureException::class);

return new NativeAuthValidateResult(
Expand Down
1 change: 1 addition & 0 deletions src/Multiversx.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static function verifyNativeAuthToken(string $accessToken): NativeAuthVal
apiUrl: config('multiversx.urls.api') ?? throw new Exception('missing config: urls.api'),
acceptedOrigins: config('multiversx.native_auth.accepted_origins') ?? throw new Exception('missing native auth config: accepted_origins'),
maxExpirySeconds: config('multiversx.native_auth.max_expiry_seconds') ?? throw new Exception('missing native auth config: max_expiry_seconds'),
skipLegacyValidation: config('multiversx.native_auth.skip_legacy_validation') ?? throw new Exception('missing native auth config: skip_legacy_validation'),
);

return $nativeAuth->validate($accessToken);
Expand Down
2 changes: 2 additions & 0 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@
],

'max_expiry_seconds' => 86400,

'skip_legacy_validation' => false,
],
];

0 comments on commit 3814724

Please sign in to comment.