File tree 5 files changed +30
-9
lines changed
5 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -30,9 +30,20 @@ php artisan vendor:publish --tag="cloudflare-cache-config"
30
30
31
31
Add environment variables to .env file
32
32
33
+ ##### Using global api key:
34
+
33
35
``` dotenv
34
36
CLOUDFLARE_CACHE_EMAIL=info@example.com #Cloudflare account email address
35
- CLOUDFLARE_CACHE_KEY=XXXXXXX #Cloudflare API_KEY
37
+ CLOUDFLARE_CACHE_KEY=XXXXXXX #Cloudflare global api key
38
+ CLOUDFLARE_CACHE_IDENTIFIER=XXXXXXX #ZONE_ID
39
+ CLOUDFLARE_DEFAULT_CACHE_TTL=600 #10 minutes
40
+ CLOUDFLARE_CACHE_DEBUG=false
41
+ ```
42
+
43
+ ##### Using fine-grained api token:
44
+
45
+ ``` dotenv
46
+ CLOUDFLARE_CACHE_API_TOKEN=XXXXXXX
36
47
CLOUDFLARE_CACHE_IDENTIFIER=XXXXXXX #ZONE_ID
37
48
CLOUDFLARE_DEFAULT_CACHE_TTL=600 #10 minutes
38
49
CLOUDFLARE_CACHE_DEBUG=false
Original file line number Diff line number Diff line change 17
17
*/
18
18
'api_key ' => env ('CLOUDFLARE_CACHE_KEY ' ),
19
19
20
+ /**
21
+ * Fine-grained api token.
22
+ */
23
+ 'api_token ' => env ('CLOUDFLARE_CACHE_API_TOKEN ' ),
24
+
20
25
/**
21
26
* zone_id of your site on cloudflare dashboard.
22
27
*/
Original file line number Diff line number Diff line change @@ -99,13 +99,16 @@ public function isActive(): bool
99
99
return true ;
100
100
}
101
101
102
- if (! config ('cloudflare-cache.api_email ' )
103
- || ! config ('cloudflare-cache.api_key ' )
104
- || ! config ('cloudflare-cache.identifier ' )
105
- ) {
102
+ if (! config ('cloudflare-cache.identifier ' )) {
106
103
return false ;
107
104
}
108
105
106
+ if (! config ('cloudflare-cache.api_token ' )) {
107
+ if (! config ('cloudflare-cache.api_email ' ) || ! config ('cloudflare-cache.api_key ' )) {
108
+ return false ;
109
+ }
110
+ }
111
+
109
112
if (config ('cloudflare-cache.debug ' )) {
110
113
return true ;
111
114
}
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ public function registerClient(): static
47
47
config ('cloudflare-cache.api_email ' ),
48
48
config ('cloudflare-cache.api_key ' ),
49
49
config ('cloudflare-cache.identifier ' ),
50
+ config ('cloudflare-cache.api_token ' ),
50
51
);
51
52
});
52
53
Original file line number Diff line number Diff line change @@ -14,17 +14,18 @@ public function __construct(
14
14
private readonly ?string $ apiEmail ,
15
15
private readonly ?string $ apiKey ,
16
16
private readonly ?string $ identifier ,
17
+ private readonly ?string $ apiToken ,
17
18
) {
18
19
// .
19
20
}
20
21
21
22
private function request (): PendingRequest
22
23
{
23
24
/** @noinspection PhpIncompatibleReturnTypeInspection */
24
- return $ this ->client ->withHeaders ([
25
- ' X-Auth-Email ' => $ this ->apiEmail ,
26
- 'X-Auth-Key ' => $ this ->apiKey ,
27
- ] );
25
+ return $ this ->client ->withHeaders ($ this -> apiToken
26
+ ? [ ' Authorization ' => ' Bearer ' . $ this ->apiToken ]
27
+ : [ 'X-Auth-Email ' => $ this -> apiEmail , ' X-Auth-Key ' => $ this ->apiKey ]
28
+ );
28
29
}
29
30
30
31
protected function getBaseUrl (string $ endpoint ): string
You can’t perform that action at this time.
0 commit comments