Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Исправление authorize #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 9 additions & 15 deletions src/TochkaApi/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use TochkaApi\Exceptions\TochkaApiClientException;
use TochkaApi\HttpAdapters\HttpClientInterface;
use TochkaApi\Models\BaseModel;
use TochkaApi\Utilities\TochkaPermissionsJWT;


/**
* @method \TochkaApi\Models\Balance balance($id = null)
Expand Down Expand Up @@ -176,18 +174,16 @@ public function getTokenUrl()
{
return static::HOST . "/connect/token";
}

/**
* @param string $jwt
* @return string
*/
public function generateAuthorizeUrl($jwt)

public function generateAuthorizeUrlByParams(string $consentId, ?string $state = null): string
{
$data = [
"client_id" => $this->getClientId(),
"redirect_uri" => $this->getRedirectUri(),
"request" => $jwt,
"response_type" => "code",
"state" => $state ?: uniqid(),
"redirect_uri" => $this->getRedirectUri(),
'scope' => $this->getScopes(),
'consent_id' => $consentId,
];

return static::HOST . "/connect/authorize?" . http_build_query($data);
Expand Down Expand Up @@ -245,7 +241,7 @@ protected function setClientSecret($client_secret)
* @return string
* @throws TochkaApiClientException
*/
public function authorize()
public function authorize(?string $state = null)
{
$data = [
"client_id" => $this->getClientId(),
Expand All @@ -261,9 +257,7 @@ public function authorize()
throw new TochkaApiClientException($e->getMessage());
}

$jwt = TochkaPermissionsJWT::generateJWT($response["Data"]["consentId"], static::HOST, $this->getClientId(), $this->getRedirectUri(), $this->getScopes());

return $this->generateAuthorizeUrl($jwt);
return $this->generateAuthorizeUrlByParams($response["Data"]["consentId"], $state);
}

/**
Expand Down Expand Up @@ -364,4 +358,4 @@ public function __call($name, $arguments)

return $model;
}
}
}
55 changes: 0 additions & 55 deletions src/TochkaApi/Utilities/TochkaPermissionsJWT.php

This file was deleted.

11 changes: 1 addition & 10 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use TochkaApi\Auth\BearerAuth;
use TochkaApi\Client;
use TochkaApi\HttpAdapters\CurlHttpClient;
use TochkaApi\Utilities\TochkaPermissionsJWT;

class ClientTest extends TestCase
{
Expand Down Expand Up @@ -41,14 +40,6 @@ public function testClient()
$client->token("test");
}

public function testJWT()
{
$jwt = TochkaPermissionsJWT::generateJWT("test", "https://example.com", "test", "https://example.com", "");

$this->assertNotEmpty($jwt);
$this->assertContains(".", $jwt);
}

public function testAccessTokenClass()
{
$token = new AccessToken("test", 7200, "test");
Expand All @@ -68,4 +59,4 @@ public function testBearerAuthClass()

$this->assertArrayHasKey("Authorization", $bearerAuth->getHeaders());
}
}
}