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

403 in PHP SDK when passing prefix or tags in the URL #205

Closed
valtonia opened this issue Jun 21, 2024 · 4 comments · Fixed by #206
Closed

403 in PHP SDK when passing prefix or tags in the URL #205

valtonia opened this issue Jun 21, 2024 · 4 comments · Fixed by #206
Labels
bug Something isn't working

Comments

@valtonia
Copy link

valtonia commented Jun 21, 2024

Describe the bug

Following the documentation when I try to pass in either a name prefix or tags in the URL using UnleashBuilder::create() I always get a 403 response.

Steps to reproduce the bug

With this code

$unleash = UnleashBuilder::create()
    ->withCacheHandler(new Cache\Adapter\PHPArray\ArrayCachePool())
    ->withAppName(APP_NAME)
    ->withAppUrl(new Url(UNLEASH_API_URL, "AH-"))
    ->withInstanceId(INSTANCE_ID)
    ->withHeader("Authorization", UNLEASH_API_KEY)
    ->build();

if ($unleash->isEnabled('AH-Experiment')) {
    echo "AH-Experiment: enabled\n";
}

Which gives a URL like this https://unleash.company.com/api?namePrefix=AH-

The response is always

Unleash\Client\Exception\HttpResponseException: Got invalid response code when getting features and no default bootstrap provided: 403 in ...

Expected behavior

The flag should be retrieved without error.

Logs, error output, etc.

Unleash\Client\Exception\HttpResponseException: Got invalid response code when getting features and no default bootstrap provided: 403 in ...

Screenshots

No response

Additional context

The same thing happens if I try to include any tags in the URL.

$url = new Url(UNLEASH_API_URL, null, ["myTag" => "myValue"]);

Unleash version

PHP SDK 2.4

Subscription type

None

Hosting type

Hosted by Unleash

SDK information (language and version)

PHP SDK 2.4

@valtonia valtonia added the bug Something isn't working label Jun 21, 2024
@chriswk chriswk transferred this issue from Unleash/unleash Jun 24, 2024
@ivarconr
Copy link
Member

thanks for raising this.

The biggest thing that stands out to me is that you say the URL it produces is
https://unleash.company.com/api?namePrefix=AH- while the expected URL for fetching feature flags is https://unleash.company.com/api/client/features.

In the PHP SDK doc it suggest to use the following format to use the namePrefix:

<?php

use Unleash\Client\UnleashBuilder;
use Unleash\Client\Helper\Url;

$builder = UnleashBuilder::create()
    ->withAppName('Some app name')
    ->withAppUrl(new Url('https://some-app-url.com', namePrefix: 'somePrefix.'))
    ->withInstanceId('Some instance id');

Have you tried this configuration?

@valtonia
Copy link
Author

Yes, I tried that.

Since raising the ticket I've been looking into the code and it seems the that the Url class is just appending the prefix (and tags) to the URL but other parts of the code are not expecting that and are then appending /client/features onto the end of it.

See line 120 of src/Repository/DefaultUnleashRepository.php in the SDK. Here we see this line

->createRequest('GET', $this->configuration->getUrl() . 'client/features')

But the result from ->getUrl() will already have the prefix and tags applied to it.

@RikudouSage
Copy link
Collaborator

@valtonia Can you test that the fix in #206 applies to your problem?

@valtonia
Copy link
Author

@RikudouSage Can confirm that your fix works.

@ivarconr ivarconr moved this from New to Support rotation in Issues and PRs Jun 25, 2024
@github-project-automation github-project-automation bot moved this from Support rotation to Done in Issues and PRs Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants