| Conditions | 4 |
| Paths | 3 |
| Total Lines | 33 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 42 | public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise |
||
| 43 | { |
||
| 44 | switch ($request->getMethod()) { |
||
| 45 | case 'POST': |
||
| 46 | $data = sprintf( |
||
| 47 | '%s%s%s%s', |
||
| 48 | $this->key, |
||
| 49 | 'POST', |
||
| 50 | $request->getUri()->getPath(), |
||
| 51 | (string) $request->getBody() |
||
| 52 | ); |
||
| 53 | break; |
||
| 54 | case 'GET': |
||
| 55 | $data = sprintf( |
||
| 56 | '%s%s%s%s', |
||
| 57 | $this->key, |
||
| 58 | 'GET', |
||
| 59 | $request->getUri()->getPath(), |
||
| 60 | $request->getUri()->getQuery() ? '?'.$request->getUri()->getQuery() : null |
||
| 61 | ); |
||
| 62 | break; |
||
| 63 | default: |
||
| 64 | throw new \LogicException('Invalid Method'); |
||
| 65 | } |
||
| 66 | |||
| 67 | $password = hash_hmac('sha256', $data, $this->secret); |
||
| 68 | |||
| 69 | $header = sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->key, $password))); |
||
| 70 | |||
| 71 | $request = $request->withHeader('Authorization', $header); |
||
| 72 | |||
| 73 | return $next($request); |
||
| 74 | } |
||
| 75 | } |
||
| 76 |