forked from apoloz/alfa-bank-sdk
Add H2H authentication service and new example flows
- Implement H2H authentication service for secure client authentication - Add new examples for authorization code flow and H2H auth service - Include example for generating client secret - Update core connector and token request functionality - Enhance README with new features Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -79,6 +79,55 @@ class AlfaBankConnector extends Connector implements HasPagination
|
||||
return new AlfaOffsetPaginator($this, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exchange Authorization Code for tokens (H2H Flow).
|
||||
*/
|
||||
public function authWithCode(string $code, string $redirectUri): \Apoloz\AlfaBank\Data\Auth\TokenData
|
||||
{
|
||||
if (!$this->alfaConfig->clientId || !$this->alfaConfig->clientSecret) {
|
||||
throw new \RuntimeException("Client ID/Secret not configured.");
|
||||
}
|
||||
|
||||
$request = new GetTokenRequest(
|
||||
clientId: $this->alfaConfig->clientId,
|
||||
clientSecret: $this->alfaConfig->clientSecret,
|
||||
code: $code,
|
||||
redirectUri: $redirectUri,
|
||||
grantType: 'authorization_code'
|
||||
);
|
||||
|
||||
$response = $this->send($request);
|
||||
$data = $response->dto();
|
||||
|
||||
$this->authenticate(new \Saloon\Http\Auth\TokenAuthenticator($data->access_token));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh access token using refresh token.
|
||||
*/
|
||||
public function refreshToken(string $refreshToken): \Apoloz\AlfaBank\Data\Auth\TokenData
|
||||
{
|
||||
if (!$this->alfaConfig->clientId || !$this->alfaConfig->clientSecret) {
|
||||
throw new \RuntimeException("Client ID/Secret not configured.");
|
||||
}
|
||||
|
||||
$request = new GetTokenRequest(
|
||||
clientId: $this->alfaConfig->clientId,
|
||||
clientSecret: $this->alfaConfig->clientSecret,
|
||||
refreshToken: $refreshToken,
|
||||
grantType: 'refresh_token'
|
||||
);
|
||||
|
||||
$response = $this->send($request);
|
||||
$data = $response->dto();
|
||||
|
||||
$this->authenticate(new \Saloon\Http\Auth\TokenAuthenticator($data->access_token));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function login(?string $clientId = null, ?string $clientSecret = null): static
|
||||
{
|
||||
// Allow overriding config via method arguments
|
||||
|
||||
Reference in New Issue
Block a user