Copied from GH https://github.com/d8-contrib-modules/cloudflare/issues/66

The php library you're using was last updated in 2016 and only supports global API keys which give full access to the cloudflare account.

CommentFileSizeAuthor
#2 3149855.patch510 byteslusitaniae

Comments

lusitaniae created an issue. See original summary.

lusitaniae’s picture

StatusFileSize
new510 bytes

I forked the library and add support for both kinds of api keys

This is just a temporary fix, using the official SDK and/or merging my PR in github is the end goal.

useernamee’s picture

Hello @lusitaniae,

I'd be very interested in using your fix, but I'm wondering how you were able to make your patch work? I'm getting this problem - a patch is applied after cloudflare module is installed by composer so required package stays at it's old value.

My workaround was to add your PR as a patch to my main composer.json file.

    "d8-contrib-modules/cloudflarephpsdk": {
        "3149588: Valid key is rejected as too long": "https://patch-diff.gith
ubusercontent.com/raw/d8-contrib-modules/cloudflarephpsdk/pull/33.patch"
    }

I'll let you know how it worked.

useernamee’s picture

@lusitaniae

I've came accross another issue. My api token has uppercase letters in it and that makes it invalid. I can roll out a PR to your fork if you'd like me to do it, but I'm wondering in the first place whether I'm testing with the right thing and even if we do that will cloudflarephpsdk be able to make requests with tokens instead of api key.

Well here is quick PR to your PR: https://github.com/Lusitaniae/cloudflarephpsdk/pull/1

useernamee’s picture

Status: Active » Needs review

I've just fixed the cloudflarephpsdk patch: https://github.com/d8-contrib-modules/cloudflarephpsdk/pull/34/files

This now works on our system. As you can see in the patch I also had to increase the timeout because authorization check requests were timing out.

alexgreyhead’s picture

In case it helps anyone else, the diff for useernamee's PR #34 can be found at:

https://patch-diff.githubusercontent.com/raw/d8-contrib-modules/cloudfla...

... and you can patch the SDK via Composer by saving that patch file to your patches directory and adding the following to extra > patches:

(You will need to change the patch filename to whatever you chose to name the patch file.)

{
    "extra": {
        "patches": {
            "d8-contrib-modules/cloudflarephpsdk": {
                "Patch Cloudflare SDK to allow different API key lengths - Drupal.org issue #3149855 patch from comment #5": "patches/patch-cloudflaresdk-for-longer-api-keys--34.diff.txt"
            }
        }
    }
}

/Al

froboy’s picture

I've added what I've deemed "one more API Key Length PR". As I've noted there:

CloudFlare makes no official definition of what a token should be in its documentation and I think trying to chase that is now a fools errand. If the key is valid, it will turn successfully. If the key is invalid, it will fail.

As an update to #6, you don't even need to download the patch to your local, you can use the direct url from GitHub:

            "d8-contrib-modules/cloudflarephpsdk": {
                "Patch Cloudflare SDK to allow different API key lengths - Drupal.org issue #3149855": "https://patch-diff.githubusercontent.com/raw/d8-contrib-modules/cloudflarephpsdk/pull/37.diff"
            }
bburg’s picture

I would urge against anyone using the diff of a pull request as a remote link in their composer patches. The diff could unpredictably, and fail to apply to future versions, or worse, a malicious developer could make unwanted changes to the code. Maybe less of an issue here, but this is something awareness is being raised around on Drupal module patches being created from Gitlab merge requests.

rosk0’s picture

Priority: Major » Normal
Status: Needs review » Needs work

This needs to be re-tested and confirmed if still an issue as #2915341: Proposal to switch Cloudflare library was committed and released in 8.x-1.0-beta3.