Skip to content

Commit

Permalink
Merge pull request #171 from codebar-ag/fix-oauth
Browse files Browse the repository at this point in the history
Fixed OAuth-Bug resolves #170
  • Loading branch information
StanBarrows authored Sep 23, 2024
2 parents fecfb38 + 1837987 commit 3ce4e4a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .phpunit.cache/test-results

Large diffs are not rendered by default.

41 changes: 14 additions & 27 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" backupGlobals="false"
bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false"
executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="codebar Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
Expand All @@ -38,19 +21,23 @@
</logging>
<php>
<env name="APP_KEY" value="base64:F+mHMDBbavrsp/I3WYA5lDSwDJJI/0wQG4eM3csq/lo="/>
<env name="DOCUWARE_URL" value="https://domain.docuware.cloud"/>
<env name="DOCUWARE_USERNAME" value="[email protected]"/>
<env name="DOCUWARE_URL" value="https://laravel.docuware.cloud"/>
<env name="DOCUWARE_USERNAME" value="username"/>
<env name="DOCUWARE_PASSWORD" value="password"/>
<env name="DOCUWARE_PASSPHRASE" value="passphrase"/>
<env name="DOCUWARE_TIMEOUT" value="30"/>
<env name="DOCUWARE_CACHE_DRIVER" value="array" />
<env name="DOCUWARE_CACHE_DRIVER" value="file"/>
<env name="DOCUWARE_CACHE_LIFETIME_IN_SECONDS" value="0"/>

<env name="DOCUWARE_TESTS_FILE_CABINET_ID" value="17eaf4ba-41a8-43ec-8be5-80a5f5f1eaf1"/>
<env name="DOCUWARE_TESTS_DIALOG_ID" value="5afd9126-6cb1-4c7b-8ab2-2ca0bbbeb7be"/>
<env name="DOCUWARE_TESTS_BASKET_ID" value="b_ac921d68-983b-4b0f-8a20-34ab05ff19c6"/>
<env name="DOCUWARE_TESTS_ORGANIZATION_ID" value="1"/>
<env name="DOCUWARE_TESTS_GROUP_ID" value="ae49d31e-41ce-46b2-9ebb-64db58e90046"/>
<env name="DOCUWARE_TESTS_ROLE_ID" value="2444928d-1312-44db-aa79-101f198ac946"/>
</php>
</phpunit>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
4 changes: 4 additions & 0 deletions src/Connectors/DocuWareConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ protected function defaultAuth(): TokenAuthenticator
*/
protected function getOrCreateNewOAuthToken(): string
{
//ray($this->configuration->identifier);

$cache = Cache::store($this->configuration->cacheDriver);

$cacheKey = 'docuware.oauth.'.$this->configuration->identifier;

//ray($cache->has($cacheKey),'hasCachkey?');

// Check if the token exists in cache and return it if found
if ($cache->has($cacheKey)) {
$token = Crypt::decrypt($cache->get($cacheKey));
Expand Down
68 changes: 34 additions & 34 deletions src/DTO/Authentication/OAuth/IdentityServiceConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,44 @@ public static function make(array $data): self
frontchannelLogoutSessionSupported: Arr::get($data, 'frontchannel_logout_session_supported'),
backchannelLogoutSupported: Arr::get($data, 'backchannel_logout_supported'),
backchannelLogoutSessionSupported: Arr::get($data, 'backchannel_logout_session_supported'),
scopesSupported: Arr::get($data, 'scopes_supported'),
claimsSupported: Arr::get($data, 'claims_supported'),
grantTypesSupported: Arr::get($data, 'grant_types_supported'),
responseTypesSupported: Arr::get($data, 'response_types_supported'),
responseModesSupported: Arr::get($data, 'response_modes_supported'),
tokenEndpointAuthMethodsSupported: Arr::get($data, 'token_endpoint_auth_methods_supported'),
idTokenSigningAlgValuesSupported: Arr::get($data, 'id_token_signing_alg_values_supported'),
subjectTypesSupported: Arr::get($data, 'subject_types_supported'),
codeChallengeMethodsSupported: Arr::get($data, 'code_challenge_methods_supported'),
scopesSupported: Arr::get($data, 'scopes_supported', []),
claimsSupported: Arr::get($data, 'claims_supported', []),
grantTypesSupported: Arr::get($data, 'grant_types_supported', []),
responseTypesSupported: Arr::get($data, 'response_types_supported', []),
responseModesSupported: Arr::get($data, 'response_modes_supported', []),
tokenEndpointAuthMethodsSupported: Arr::get($data, 'token_endpoint_auth_methods_supported', []),
idTokenSigningAlgValuesSupported: Arr::get($data, 'id_token_signing_alg_values_supported', []),
subjectTypesSupported: Arr::get($data, 'subject_types_supported', []),
codeChallengeMethodsSupported: Arr::get($data, 'code_challenge_methods_supported', []),
requestParameterSupported: Arr::get($data, 'request_parameter_supported'),
requestObjectSigningAlgValuesSupported: Arr::get($data, 'request_object_signing_alg_values_supported'),
promptValuesSupported: Arr::get($data, 'prompt_values_supported'),
requestObjectSigningAlgValuesSupported: Arr::get($data, 'request_object_signing_alg_values_supported', []),
promptValuesSupported: Arr::get($data, 'prompt_values_supported', []),
authorizationResponseIssParameterSupported: Arr::get($data, 'authorization_response_iss_parameter_supported'),
backchannelTokenDeliveryModesSupported: Arr::get($data, 'backchannel_token_delivery_modes_supported'),
backchannelTokenDeliveryModesSupported: Arr::get($data, 'backchannel_token_delivery_modes_supported', []),
backchannelUserCodeParameterSupported: Arr::get($data, 'backchannel_user_code_parameter_supported'),
dpopSigningAlgValuesSupported: Arr::get($data, 'dpop_signing_alg_values_supported'),
dpopSigningAlgValuesSupported: Arr::get($data, 'dpop_signing_alg_values_supported', []),
windowsAuthEndpoint: Arr::get($data, 'windows_auth_endpoint'),
);
}

public function __construct(
public string $issuer,
public string $jwksUri,
public string $authorizationEndpoint,
public string $tokenEndpoint,
public string $userinfoEndpoint,
public string $endSessionEndpoint,
public string $checkSessionIframe,
public string $revocationEndpoint,
public string $introspectionEndpoint,
public string $deviceAuthorizationEndpoint,
public string $backchannelAuthenticationEndpoint,
public string $pushedAuthorizationRequestEndpoint,
public bool $requirePushedAuthorizationRequests,
public bool $frontchannelLogoutSupported,
public bool $frontchannelLogoutSessionSupported,
public bool $backchannelLogoutSupported,
public bool $backchannelLogoutSessionSupported,
public ?string $issuer,
public ?string $jwksUri,
public ?string $authorizationEndpoint,
public ?string $tokenEndpoint,
public ?string $userinfoEndpoint,
public ?string $endSessionEndpoint,
public ?string $checkSessionIframe,
public ?string $revocationEndpoint,
public ?string $introspectionEndpoint,
public ?string $deviceAuthorizationEndpoint,
public ?string $backchannelAuthenticationEndpoint,
public ?string $pushedAuthorizationRequestEndpoint,
public ?bool $requirePushedAuthorizationRequests,
public ?bool $frontchannelLogoutSupported,
public ?bool $frontchannelLogoutSessionSupported,
public ?bool $backchannelLogoutSupported,
public ?bool $backchannelLogoutSessionSupported,
public array $scopesSupported,
public array $claimsSupported,
public array $grantTypesSupported,
Expand All @@ -73,13 +73,13 @@ public function __construct(
public array $idTokenSigningAlgValuesSupported,
public array $subjectTypesSupported,
public array $codeChallengeMethodsSupported,
public bool $requestParameterSupported,
public ?bool $requestParameterSupported,
public array $requestObjectSigningAlgValuesSupported,
public array $promptValuesSupported,
public bool $authorizationResponseIssParameterSupported,
public ?bool $authorizationResponseIssParameterSupported,
public array $backchannelTokenDeliveryModesSupported,
public bool $backchannelUserCodeParameterSupported,
public ?bool $backchannelUserCodeParameterSupported,
public array $dpopSigningAlgValuesSupported,
public string $windowsAuthEndpoint,
public ?string $windowsAuthEndpoint,
) {}
}
5 changes: 1 addition & 4 deletions src/DTO/Config/ConfigWithCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace CodebarAg\DocuWare\DTO\Config;

use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Hash;

final class ConfigWithCredentials
{
public string $identifier;
Expand Down Expand Up @@ -55,6 +52,6 @@ public function __construct(

$this->scope = filled($scope) ? $scope : config('laravel-docuware.configurations.scope');

$this->identifier = Hash::make($this->url.$this->username.Crypt::encrypt($this->password));
$this->identifier = hash('sha256', $this->url.$this->username.$this->password);
}
}
5 changes: 1 addition & 4 deletions src/DTO/Config/ConfigWithCredentialsTrustedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace CodebarAg\DocuWare\DTO\Config;

use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Hash;

final class ConfigWithCredentialsTrustedUser
{
public string $identifier;
Expand Down Expand Up @@ -59,6 +56,6 @@ public function __construct(

$this->scope = filled($scope) ? $scope : config('laravel-docuware.configurations.scope');

$this->identifier = Hash::make($this->url.$this->username.Crypt::encrypt($this->password));
$this->identifier = hash('sha256', $this->url.$this->username.$this->password);
}
}
27 changes: 0 additions & 27 deletions src/DocuWare.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,8 @@

namespace CodebarAg\DocuWare;

use CodebarAg\DocuWare\DTO\Authentication\OAuth\RequestToken as RequestTokenDto;
use CodebarAg\DocuWare\Requests\Authentication\OAuth\GetIdentityServiceConfiguration;
use CodebarAg\DocuWare\Requests\Authentication\OAuth\GetResponsibleIdentityService;
use CodebarAg\DocuWare\Requests\Authentication\OAuth\RequestTokenWithCredentials;

class DocuWare
{
public function getNewAuthenticationOAuthToken(
?string $username = '',
?string $password = '',
?string $grantType = 'password',
?string $clientId = 'docuware.platform.net.client'
): RequestTokenDto {
$responsibleIdentityServiceResponse = (new GetResponsibleIdentityService)->send();

$identityServiceConfigurationResponse = (new GetIdentityServiceConfiguration(
identityServiceUrl: $responsibleIdentityServiceResponse->dto()->identityServiceUrl
))->send();

$requestTokenResponse = (new RequestTokenWithCredentials(
tokenEndpoint: $identityServiceConfigurationResponse->dto()->tokenEndpoint,
clientId: $clientId,
username: $username,
password: $password,
))->send();

return $requestTokenResponse->dto();
}

public function searchRequestBuilder(): DocuWareSearchRequestBuilder
{
return new DocuWareSearchRequestBuilder;
Expand Down
2 changes: 0 additions & 2 deletions src/Facades/DocuWare.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Carbon\Carbon;
use CodebarAg\DocuWare\DocuWareSearchRequestBuilder;
use CodebarAg\DocuWare\DocuWareUrl;
use CodebarAg\DocuWare\DTO\Cookie;
use CodebarAg\DocuWare\DTO\Documents\Document;
use CodebarAg\DocuWare\DTO\Documents\DocumentThumbnail;
use CodebarAg\DocuWare\DTO\Documents\Field;
Expand All @@ -19,7 +18,6 @@
/**
* @see \CodebarAg\DocuWare\DocuWare
*
* @method static Cookie cookie(string $url, string $username, string $password, $rememberMe = false, $redirectToMyselfInCaseOfError = false, $licenseType = null)
* @method static string login()
* @method static void logout()
* @method static Organization getOrganization(string $organizationId)
Expand Down

0 comments on commit 3ce4e4a

Please sign in to comment.