All Projects → psecio → Jwt

psecio / Jwt

A JWT (JSON Web Token) Encoder & Decoder

Projects that are alternatives of or similar to Jwt

Cli
🧰 A zero trust swiss army knife for working with X509, OAuth, JWT, OATH OTP, etc.
Stars: ✭ 2,151 (+1910.28%)
Mutual labels:  security-tools, jwt
Jwtxploiter
A tool to test security of json web token
Stars: ✭ 130 (+21.5%)
Mutual labels:  security-tools, jwt
Arl
ARL(Asset Reconnaissance Lighthouse)资产侦察灯塔系统旨在快速侦察与目标关联的互联网资产,构建基础资产信息库。 协助甲方安全团队或者渗透测试人员有效侦察和检索资产,发现存在的薄弱点和攻击面。
Stars: ✭ 1,357 (+1168.22%)
Mutual labels:  security-tools
Zitadel
ZITADEL - Cloud Native Identity and Access Management
Stars: ✭ 105 (-1.87%)
Mutual labels:  jwt
M4ngl3m3
Common password pattern generator using strings list
Stars: ✭ 103 (-3.74%)
Mutual labels:  security-tools
Barong
Barong auth server
Stars: ✭ 100 (-6.54%)
Mutual labels:  jwt
Hacker Container
Container with all the list of useful tools/commands while hacking and pentesting Kubernetes Clusters
Stars: ✭ 105 (-1.87%)
Mutual labels:  security-tools
Django Auth0 Vue
A Django REST Framework + Vue.js CRUD Demo Secured Using Auth0
Stars: ✭ 99 (-7.48%)
Mutual labels:  jwt
Cupertinojwt
Parse Apple's .p8 private key file and sign JWT with ES256, without third-party dependencies.
Stars: ✭ 107 (+0%)
Mutual labels:  jwt
Fastsitephp
🌟 FastSitePHP 🌟 A Modern Open Source Framework for building High Performance Websites and API’s with PHP
Stars: ✭ 102 (-4.67%)
Mutual labels:  jwt
Parsevip
解析VIP资源,解析出酷狗、QQ音乐、腾讯视频、人人视频的真实地址
Stars: ✭ 105 (-1.87%)
Mutual labels:  jwt
Kitsvc
⚙ 一個基於 Golang、Consul、Prometheus、EventStore、Gin、Gorm、NSQ 的微服務起始結構。
Stars: ✭ 101 (-5.61%)
Mutual labels:  jwt
Hs Jose
Haskell JOSE and JWT library
Stars: ✭ 100 (-6.54%)
Mutual labels:  jwt
Express Jwt
An example API for creating/verifying json web tokens
Stars: ✭ 105 (-1.87%)
Mutual labels:  jwt
Awesome Aws Security
Curated list of links, references, books videos, tutorials (Free or Paid), Exploit, CTFs, Hacking Practices etc. which are related to AWS Security
Stars: ✭ 100 (-6.54%)
Mutual labels:  security-tools
Patrowldocs
PatrOwl - Open Source, Free and Scalable Security Operations Orchestration Platform
Stars: ✭ 105 (-1.87%)
Mutual labels:  security-tools
Powershellarmoury
A PowerShell armoury for penetration testers or other random security guys
Stars: ✭ 99 (-7.48%)
Mutual labels:  security-tools
Security Scripts
A collection of public offensive and defensive security related scripts for InfoSec students.
Stars: ✭ 101 (-5.61%)
Mutual labels:  security-tools
Karn
Simplifying Seccomp enforcement in containerized or non-containerized apps
Stars: ✭ 104 (-2.8%)
Mutual labels:  security-tools
Caddy Jwt
JWT middleware for the Caddy server
Stars: ✭ 107 (+0%)
Mutual labels:  jwt

JWT (JSON Web Token) Creation and Decoding Library

Build Status

This library allows for the creation and decoding of JWT (JSON Web Tokens).

Installation

This tool can be installed via Composer:

{
	"require": {
		"psecio/jwt": "1.*"
	}
}

Example Usage

In the example below, the JWT object is created and a Header instance is assigned (required). The JWt object is then assigned several claims: issuer, audience, issued at and not before to define data and how it could be processed. The encode method is then called with the key and a resulting JWT-formatted string is returned.

NOTE: The JWT token will be generated in the order the claims are provided. No sorting is done in the background.

The decode method can then be called on the data along with the key to return an object matching the state of the jwt object.

<?php

require_once 'vendor/autoload.php';

$key = "example_key";

$header = new \Psecio\Jwt\Header($key);
$jwt = new \Psecio\Jwt\Jwt($header);

$jwt
    ->issuer('http://example.org')
    ->audience('http://example.com')
	->issuedAt(1356999524)
	->notBefore(1357000000)
	->expireTime(time()+3600)
	->jwtId('id123456')
	->type('https://example.com/register');

$result = $jwt->encode();
echo 'ENCODED: '.print_r($result)."\n\n";
echo 'DECODED: '.var_export($jwt->decode($result), true);

?>

Encryption via OpenSSL

The JWT Library also supports encryption of the resulting JWT-formatted string. Here's an example of it in use:

<?php

require_once 'vendor/autoload.php';

$key = 'example_key';
$encryptKey = 'my-encryption-key';

$header = new \Psecio\Jwt\Header($key);
$jwt = new \Psecio\Jwt\Jwt($header);

$jwt
    ->issuer('http://example.org')
    ->audience('http://example.com')
	->issuedAt(1356999524)
	->notBefore(1357000000)
	->expireTime(time()+3600)
	->jwtId('id123456')
	->type('https://example.com/register');

$result = $jwt->encrypt('AES-256-CBC', '1234567812345678', $encryptKey);

echo 'ENCRYPTED: '.var_export($result, true)."\n";
echo "DECRYPTED: ".var_export($jwt->decrypt($result, 'AES-256-CBC', '1234567812345678', $encryptKey), true)."\n";

?>

Custom Claim values

You can also add your own custom claim values to the JWT payload using the custom method. The first paramater is the value and the second is the claim "type" (key):

<?php
require_once 'vendor/autoload.php';

$key = "example_key";

$header = new \Psecio\Jwt\Header($key);

$jwt = new \Psecio\Jwt\Jwt($header);
$jwt->custom('foobar', 'custom-claim');

// Or, you can add more than one at the same time with an array
$jwt->custom(array(
    'custom-claim' => 'foorbar',
    'key1' => 'value1'
));

$result = $jwt->encode();
echo 'ENCODED: '.print_r($result)."\n\n";
echo 'DECODED: '.var_export($jwt->decode($result), true);
?>

You can use any of the OpenSSL cypher methods provided by the openssl_get_cipher_methods on your system.

Supported Claim Types

  • Audience (aud)
  • Expire Time (exp)
  • Issued At (iat)
  • Issuer (iss)
  • JwtId (jit)
  • Not Before (nbf)
  • Subject (sub)
  • Private

Hashing types

By default this JWT tool uses HMAC hashing (HS256) to generate the signature for the request. There are other options for this that will use the OpenSSL functionality to let you use public and private keys for these methods:

  • HS256
  • HS384
  • HS512
  • ES256
  • ES384
  • ES512
  • RS256
  • RS384
  • RS512

You cannot use a simple text string for the key like you can with HMAC hashing, so you must provide a valid key instance for the library to use. Here's an example using a .pem private key file and the RS256 hashing:

<?php
$key = openssl_pkey_get_private('file://'.__DIR__.'/private.pem', 'test1234');

$header = new \Psecio\Jwt\Header($key);
$header->setAlgorithm('RS256');

// or you can define the hash algorithm on the init too:
$header = new \Psecio\Jwt\Header($key, 'RS256');
?>

An exception (\Psecio\Jwt\Exception\InvalidKeyException) will be thrown if the key is invalid and cannot be used in signing the request. If there is an error during the actual signing of the message, you will be thrown a \Psecio\Jwt\Exception\SignatureErrorException.

Documentation for JSON Web Tokens

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].