@@ -59,26 +59,32 @@ public static function authenticateGetRequest(string $shopSecret): bool
59
59
60
60
$ shop = new Shop ($ queries ['shop-id ' ], $ queries ['shop-url ' ], $ shopSecret );
61
61
62
- $ queryString = sprintf (
63
- 'shop-id=%s&shop-url=%s×tamp=%s&sw-version=%s ' ,
64
- $ shop ->getShopId (),
65
- $ shop ->getShopUrl (),
66
- $ queries ['timestamp ' ] ?? null ,
67
- $ queries ['sw-version ' ] ?? null ,
68
- );
69
-
70
- if (array_key_exists ('sw-context-language ' , $ queries ) && array_key_exists ('sw-context-language ' , $ queries )) {
71
- $ queryString = sprintf (
72
- 'shop-id=%s&shop-url=%s×tamp=%s&sw-version=%s&sw-context-language=%s&sw-user-language=%s ' ,
73
- $ shop ->getShopId (),
74
- $ shop ->getShopUrl (),
75
- $ queries ['timestamp ' ],
76
- $ queries ['sw-version ' ],
77
- $ queries ['sw-context-language ' ],
78
- $ queries ['sw-user-language ' ],
79
- );
62
+ $ queryParams = [
63
+ 'shop-id ' => $ shop ->getShopId (),
64
+ 'shop-url ' => $ shop ->getShopUrl (),
65
+ 'timestamp ' => $ queries ['timestamp ' ],
66
+ 'sw-version ' => $ queries ['sw-version ' ],
67
+ ];
68
+
69
+ if (array_key_exists ('sw-context-language ' , $ queries )) {
70
+ $ queryParams ['sw-context-language ' ] = $ queries ['sw-context-language ' ];
80
71
}
81
72
73
+ if (array_key_exists ('sw-user-language ' , $ queries )) {
74
+ $ queryParams ['sw-user-language ' ] = $ queries ['sw-user-language ' ];
75
+ }
76
+
77
+ if (array_key_exists ('location-id ' , $ queries )) {
78
+ $ queryParams ['location-id ' ] = $ queries ['location-id ' ];
79
+ }
80
+
81
+ if (array_key_exists ('privileges ' , $ queries )) {
82
+ $ queryParams ['privileges ' ] = urlencode ($ queries ['privileges ' ]);
83
+ }
84
+
85
+ $ queryString = http_build_query ($ queryParams );
86
+
87
+
82
88
$ hmac = \hash_hmac ('sha256 ' , htmlspecialchars_decode ($ queryString ), $ shopSecret );
83
89
84
90
return hash_equals ($ hmac , $ queries ['shopware-shop-signature ' ]);
0 commit comments