public function authorize(HeaderInterface $authHeader) { list($jwt) = sscanf($authHeader->toString(), 'Authorization: Bearer %s'); if ($jwt) { try { /* * decode the jwt using the key from config */ $secretKey = base64_decode($this->config->get('jwt')->get('key')); $this->token = JWT::decode($jwt, $secretKey, [$this->config->get('jwt')->get('algorithm')]); $this->isAuthorized = true; $this->response = Response::createMessage("10"); } catch (Exception $e) { /* * the token was not able to be decoded. * this is likely because the signature was not able to be verified (tampered token) */ $this->isAuthorized = false; $this->response = Response::createMessage("03"); $this->response["data"] = $jwt; } } else { /* * No token was able to be extracted from the authorization header */ $this->isAuthorized = false; $this->response = Response::createMessage("01"); } }
public function testAroundResultWithPluginDeveloperMode() { $this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')->willReturn(true); $this->state->expects($this->once())->method('getMode')->willReturn(\Magento\Framework\App\State::MODE_DEVELOPER); $this->header->expects($this->any())->method('getFieldValue')->willReturnOnConsecutiveCalls('test', 'tag,tag2'); $this->response->expects($this->any())->method('setHeader')->withConsecutive(['X-Magento-Cache-Control', 'test'], ['X-Magento-Cache-Debug', 'MISS', true], ['X-Magento-Tags', 'tag,tag2,' . \Magento\PageCache\Model\Cache\Type::CACHE_TAG]); $this->response->expects($this->once())->method('clearHeader')->with('X-Magento-Tags'); $this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')->will($this->returnValue(true)); $this->kernel->expects($this->once())->method('process')->with($this->response); $result = call_user_func($this->closure); $this->assertSame($result, $this->plugin->aroundRenderResult($this->subject, $this->closure, $this->response)); }
/** * Add a Header to this container, for raw values @see addHeaderLine() and addHeaders() * * @param Header\HeaderInterface $header * @return Headers */ public function addHeader(Header\HeaderInterface $header) { $key = str_replace(array('-', '_', ' ', '.'), '', strtolower($header->getFieldName())); $this->headersKeys[] = $key; $this->headers[] = $header; return $this; }
/** * Add a Header to this container, for raw values @see addHeaderLine() and addHeaders() * * @param Header\HeaderInterface $header * @return Headers */ public function addHeader(Header\HeaderInterface $header) { $this->headersKeys[] = static::createKey($header->getFieldName()); $this->headers[] = $header; return $this; }