Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T16396 jwt addheader #16397

Merged
merged 8 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

- Parse multipart/form-data from PUT request [#16271](https://github.com/phalcon/cphalcon/issues/16271)

### Added

- Added `Phalcon\Encryption\Security\JWT\Builder::addHeader()` to allow adding custom headers [#16396](https://github.com/phalcon/cphalcon/issues/16396)


## [5.2.3](https://github.com/phalcon/cphalcon/releases/tag/v5.2.3) (2023-07-26)

### Fixed

- Tried to reproduce the behavior described in #16244 but had no success. [#16244](https://github.com/phalcon/cphalcon/issues/16244)
- Extended `Phalcon\Di\Injectable` from `stdClass` to remove the deprecation warning (dynamic properties) for PHP 8.2 [#16308](https://github.com/phalcon/cphalcon/issues/16308)
- Corrected the return type of `Phalcon\Mvc\View::getVar()` so that stubs can be accurate. [#16276](https://github.com/phalcon/cphalcon/issues/16276)
Expand All @@ -18,6 +23,7 @@
- Fixed `Phalcon\Http\Request::getJsonRawBody` to protect from empty body [#16373](https://github.com/phalcon/cphalcon/issues/16373)

### Added

- Added `getAdapter()` in `Phalcon\Mvc\Model\Metadata` to retrieve the internal cache adapter if necessary. [#16244](https://github.com/phalcon/cphalcon/issues/16244)
- Added `Phalcon\Storage\Adapter\Weak` implemented with WeakReference has a cache/retrieval solution for objects not yet collected by the Garbage Collection. [#16372](https://github.com/phalcon/cphalcon/issues/16372)

Expand Down
24 changes: 23 additions & 1 deletion phalcon/Encryption/Security/JWT/Builder.zep
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ use Phalcon\Support\Collection\CollectionInterface;
use Phalcon\Support\Helper\Json\Encode;

/**
* JWT Builder
* Builder
*
* The builder offers
*
* @property CollectionInterface $claims
* @property CollectionInterface $jose
* @property string $passphrase
* @property SignerInterface $signer
*
* @link https://tools.ietf.org/html/rfc7519
*/
Expand Down Expand Up @@ -103,6 +110,21 @@ class Builder
return this;
}

/**
* Adds a custom claim
*
* @param string $name
* @param mixed $value
*
* @return Builder
*/
public function addHeader(string! name, var value) -> <Builder>
{
this->jose->set(name, value);

return this;
}

/**
* @return array|string
*/
Expand Down
10 changes: 10 additions & 0 deletions phalcon/Encryption/Security/JWT/Token/Token.zep
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Token
}

/**
* Return the registered claims
*
* @return Item
*/
public function getClaims() -> <Item>
Expand All @@ -64,6 +66,8 @@ class Token
}

/**
* Return the registered headers
*
* @return Item
*/
public function getHeaders() -> <Item>
Expand All @@ -72,6 +76,8 @@ class Token
}

/**
* Return the payload
*
* @return string
*/
public function getPayload() -> string
Expand All @@ -80,6 +86,8 @@ class Token
}

/**
* Return the signature
*
* @return Signature
*/
public function getSignature() -> <Signature>
Expand All @@ -88,6 +96,8 @@ class Token
}

/**
* Return the token
*
* @return string
*/
public function getToken() -> string
Expand Down
36 changes: 36 additions & 0 deletions phalcon/Encryption/Security/JWT/Validator.zep
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,23 @@ class Validator
];
}

/**
* Return an array with validation errors (if any)
*
* @return array
*/
public function getErrors() -> array
{
return this->errors;
}

/**
* Return the value of a claim
*
* @param string $claim
*
* @return mixed
*/
public function get(string claim) -> mixed | null
{
if isset this->claims[claim] {
Expand All @@ -78,6 +90,14 @@ class Validator
return null;
}

/**
* Set the value of a claim, for comparison with the token values
*
* @param string $claim
* @param mixed $value
*
* @return Validator
*/
public function set(string claim, var value) -> <Validator>
{
let this->claims[claim] = value;
Expand All @@ -86,6 +106,8 @@ class Validator
}

/**
* Set the token to be validated
*
* @param Token $token
*
* @return Validator
Expand All @@ -98,6 +120,8 @@ class Validator
}

/**
* Validate the audience
*
* @param string|array $audience
*
* @return Validator
Expand Down Expand Up @@ -129,6 +153,8 @@ class Validator
}

/**
* Validate the expiration time of the token
*
* @param int $timestamp
*
* @return Validator
Expand All @@ -151,6 +177,8 @@ class Validator
}

/**
* Validate the id of the token
*
* @param string $id
*
* @return Validator
Expand All @@ -170,6 +198,8 @@ class Validator
}

/**
* Validate the issued at (iat) of the token
*
* @param int $timestamp
*
* @return Validator
Expand All @@ -189,6 +219,8 @@ class Validator
}

/**
* Validate the issuer of the token
*
* @param string $issuer
*
* @return Validator
Expand All @@ -208,6 +240,8 @@ class Validator
}

/**
* Validate the notbefore (nbf) of the token
*
* @param int $timestamp
*
* @return Validator
Expand All @@ -227,6 +261,8 @@ class Validator
}

/**
* Validate the signature of the token
*
* @param SignerInterface $signer
* @param string $passphrase
*
Expand Down
3 changes: 2 additions & 1 deletion tests/_config/generate-api-docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
layout: default
title: '{$document['title']}'
---
{%- include env-setup.html -%}
";
foreach ($document['docs'] as $file) {
$link = str_replace(['.zep', DIRECTORY_SEPARATOR], ['', '\\'], $file);
Expand Down Expand Up @@ -86,7 +87,7 @@

<h1 id=\"{$href}\">{$signature}</h1>

[Source on GitHub](https://github.com/phalcon/cphalcon/blob/v{{ pageVersion }}.0/phalcon/{$github})
[Source on GitHub](https://github.com/phalcon/cphalcon/blob/{{ pageVersion }}.x/phalcon/{$github})
";

if (!empty($namespace)) {
Expand Down
Loading