<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 擴展庫 *此處的示例從假設的依賴注入容器中獲取配置對象。您可以在同一個腳本中創建它或從不同的文件中要求它。它基本上取決于您的系統是如何引導的。* -------------------------- 這個庫中設計了一些擴展點。如果他們愿意,這些應該使人們能夠輕松地自定義我們的核心組件。 ## 建造者 令牌構建器為普通令牌創建定義了一個流暢的接口。 要創建自己的構建器,您必須實現`Lcobucci\JWT\Builder`接口: ~~~php use Lcobucci\JWT\Builder; final class MyCustomTokenBuilder implements Builder { // implement all methods } ~~~ 然后,在[配置對象中](https://lcobucci-jwt.readthedocs.io/en/latest/configuration/)注冊一個自定義工廠: ~~~php use Lcobucci\JWT\Builder; use Lcobucci\JWT\ClaimsFormatter; use Lcobucci\JWT\Configuration; $config = $container->get(Configuration::class); assert($config instanceof Configuration); $config->setBuilderFactory( static function (ClaimsFormatter $formatter): Builder { return new MyCustomTokenBuilder($formatter); } ); ~~~ ## 索賠格式化程序 默認情況下,我們提供以下格式化程序: * 統一受眾聲明,確保我們在聲明中只有一項時使用字符串 * 使用微秒(浮點數)格式化基于日期的聲明 您可以自定義甚至創建自己的格式化程序: ~~~php use Lcobucci\JWT\ClaimsFormatter; use Lcobucci\JWT\Configuration; use Serializable; final class ClaimSerializer implements ClaimsFormatter { /** @inheritdoc */ public function formatClaims(array $claims): array { foreach ($claims as $claim => $claimValue) { if ($claimValue instanceof Serializable) { $claims[$claim] = $claimValue->serialize(); } } return $claims; } } $config = $container->get(Configuration::class); assert($config instanceof Configuration); $config->builder(new ClaimSerializer()); ~~~ 該類`Lcobucci\JWT\Encoding\ChainedFormatter`允許用戶組合多個格式化程序。 ## 解析器 令牌解析器定義了如何將 JWT 字符串轉換為令牌對象。 要創建自己的解析器,您必須實現`Lcobucci\JWT\Parser`接口: ~~~php use Lcobucci\JWT\Parser; final class MyCustomTokenParser implements Parser { // implement all methods } ~~~ 然后在[配置對象)注冊一個實例: ~~~php use Lcobucci\JWT\Configuration; $config = $container->get(Configuration::class); assert($config instanceof Configuration); $config->setParser(new MyCustomTokenParser()); ~~~ ## 簽名者 簽名者定義如何創建和驗證簽名。 要創建自己的簽名者,您必須實現`Lcobucci\JWT\Signer`接口: ~~~php use Lcobucci\JWT\Signer; final class SignerForAVeryCustomizedAlgorithm implements Signer { // implement all methods } ~~~ 然后在創建置對象)的實例、發出令牌])或[驗證令牌時]傳遞它的一個實例。 ## 鑰匙 密鑰對象被傳遞給簽名者并提供必要的信息來創建和驗證簽名。 要創建自己的簽名者,您必須實現`Lcobucci\JWT\Signer\Key`接口: ~~~php use Lcobucci\JWT\Signer\Key; final class KeyWithSomeMagicalProperties implements Key { // implement all methods } ~~~ ## 驗證器 令牌驗證器定義了如何將驗證約束應用于驗證或斷言令牌。 要創建自己的驗證器,您必須實現`Lcobucci\JWT\Validator`接口: ~~~php use Lcobucci\JWT\Validator; final class MyCustomTokenValidator implements Validator { // implement all methods } ~~~ 然后在[配置對象中注冊一個實例: ~~~php use Lcobucci\JWT\Configuration; $config = $container->get(Configuration::class); assert($config instanceof Configuration); $config->setValidator(new MyCustomTokenValidator()); ~~~ ## 驗證約束 驗證約束定義應如何驗證一個或多個聲明/標題。自定義驗證約束可方便地為注冊聲明提供高級規則或驗證私有聲明。 要創建自己的約束實現,您必須實現`Lcobucci\JWT\Validation\Constraint`接口: ~~~php use Lcobucci\JWT\Token; use Lcobucci\JWT\UnencryptedToken; use Lcobucci\JWT\Validation\Constraint; use Lcobucci\JWT\Validation\ConstraintViolation; final class SubjectMustBeAValidUser implements Constraint { public function assert(Token $token): void { if (! $token instanceof UnencryptedToken) { throw new ConstraintViolation('You should pass a plain token'); } if (! $this->existsInDatabase($token->claims()->get('sub'))) { throw new ConstraintViolation('Token related to an unknown user'); } } private function existsInDatabase(string $userId): bool { // ... } } ~~~ 然后在)[驗證令牌](%E9%AA%8C%E8%AF%81%E4%BB%A4%E7%89%8C.md)使用它。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看