All Projects → adhocore → Php Jwt

adhocore / Php Jwt

Licence: mit
Ultra lightweight, dependency free and standalone JSON web token (JWT) library for PHP5.6 to PHP8.0. This library makes JWT a cheese.

Projects that are alternatives of or similar to Php Jwt

Laravel Jwt
Dead simple, plug and play JWT API Authentication for Laravel (5.4+)
Stars: ✭ 225 (+5.14%)
Mutual labels:  jwt, jwt-authentication, jwt-auth, json-web-token
Jose2go
Golang (GO) implementation of Javascript Object Signing and Encryption specification
Stars: ✭ 150 (-29.91%)
Mutual labels:  jwt, oauth2, jwt-authentication, jwt-auth
Jwt Auth Guard
JWT Auth Guard for Laravel and Lumen Frameworks.
Stars: ✭ 319 (+49.07%)
Mutual labels:  jwt, jwt-authentication, jwt-auth
Reallysimplejwt
A really simple library to generate JSON Web Tokens in PHP.
Stars: ✭ 218 (+1.87%)
Mutual labels:  jwt, jwt-auth, json-web-token
Nest Angular
NestJS, Angular 6, Server Side Rendering (Angular Universal), GraphQL, JWT (JSON Web Tokens) and Facebook/Twitter/Google Authentication, Mongoose, MongoDB, Webpack, TypeScript
Stars: ✭ 307 (+43.46%)
Mutual labels:  jwt, jwt-authentication, jwt-auth
React Login
A client side implementation of authentication using react.js for my blog on medium. This is the second part of my previous blog on how to implement scalable node.js server.
Stars: ✭ 105 (-50.93%)
Mutual labels:  jwt, jwt-authentication, jwt-auth
Jwt
Go JWT signing, verifying and validating
Stars: ✭ 394 (+84.11%)
Mutual labels:  jwt, jwt-authentication, jwt-auth
Jwt Spring Security Jpa
Backend MVP showcasing JWT (Json Web Token) authentication with multiple login, timeout / refresh / logout (with in memory invalidation) using Spring Security & MySQL JPA.
Stars: ✭ 202 (-5.61%)
Mutual labels:  jwt, jwt-authentication, jwt-auth
Jose Jwt
Ultimate Javascript Object Signing and Encryption (JOSE) and JSON Web Token (JWT) Implementation for .NET and .NET Core
Stars: ✭ 692 (+223.36%)
Mutual labels:  jwt, oauth2, jwt-authentication
Jwt
Kotlin JWT 🔑 implementation (Json Web Token) as required by APNs 🔔 (Apple Push Notifications) or Sign in with Apple 🍏
Stars: ✭ 31 (-85.51%)
Mutual labels:  jwt, jwt-authentication, json-web-token
Netcoreblockly
.NET Core API to Blockly - generate from WebAPI, Swagger, OData, GraphQL =>
Stars: ✭ 121 (-43.46%)
Mutual labels:  jwt, jwt-authentication, jwt-auth
Go Jose
An implementation of JOSE standards (JWE, JWS, JWT) in Go
Stars: ✭ 1,849 (+764.02%)
Mutual labels:  jwt, json-web-token
Loginsrv
JWT login microservice with plugable backends such as OAuth2, Google, Github, htpasswd, osiam, ..
Stars: ✭ 1,835 (+757.48%)
Mutual labels:  jwt, oauth2
Microservice Scaffold
基于Spring Cloud(Greenwich.SR2)搭建的微服务脚手架(适用于在线系统),已集成注册中心(Nacos Config)、配置中心(Nacos Discovery)、认证授权(Oauth 2 + JWT)、日志处理(ELK + Kafka)、限流熔断(AliBaba Sentinel)、应用指标监控(Prometheus + Grafana)、调用链监控(Pinpoint)、以及Spring Boot Admin。
Stars: ✭ 211 (-1.4%)
Mutual labels:  jwt, oauth2
Auth0.swift
Swift toolkit for Auth0 API
Stars: ✭ 146 (-31.78%)
Mutual labels:  jwt, oauth2
Httpie Jwt Auth
JWTAuth (JSON Web Tokens) auth plugin for HTTPie
Stars: ✭ 140 (-34.58%)
Mutual labels:  jwt, jwt-authentication
Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (-31.78%)
Mutual labels:  jwt, jwt-authentication
React Role Based Authorization Example
React - Role Based Authorization Example with Webpack 4
Stars: ✭ 147 (-31.31%)
Mutual labels:  jwt, jwt-authentication
Spring Boot2 Oauth2 Jwt
Read more http://blog.marcosbarbero.com/centralized-authorization-jwt-spring-boot2/
Stars: ✭ 135 (-36.92%)
Mutual labels:  jwt, oauth2
Express Mongodb Rest Api Boilerplate
A boilerplate for Node.js apps / Rest API / Authentication from scratch - express, mongodb (mongoose).
Stars: ✭ 153 (-28.5%)
Mutual labels:  jwt, jwt-authentication

adhocore/jwt

If you are new to JWT or want to refresh your familiarity with it, please check jwt.io

Latest Version Travis Build Scrutinizer CI Codecov branch StyleCI Software License

  • Lightweight JSON Web Token (JWT) library for PHP7.
  • If you still use PHP5.6, use version 0.1.2

Installation

# PHP7.0+
composer require adhocore/jwt

# PHP5.6
composer require adhocore/jwt:0.1.2

# For PHP5.4-5.5, use version 0.1.2 with a polyfill for https://php.net/hash_equals

Features

  • Six algorithms supported:
'HS256', 'HS384', 'HS512', 'RS256', 'RS384', 'RS512'
  • kid support.
  • Leeway support 0-120 seconds.
  • Timestamp spoofing for tests.
  • Passphrase support for RS* algos.

Usage

use Ahc\Jwt\JWT;

// Instantiate with key, algo, maxAge and leeway.
$jwt = new JWT('secret', 'HS256', 3600, 10);

Only the key is required. Defaults will be used for the rest:

$jwt = new JWT('secret');
// algo = HS256, maxAge = 3600, leeway = 0

For RS* algo, the key should be either a resource like below:

$key = openssl_pkey_new([
    'digest_alg' => 'sha256',
    'private_key_bits' => 1024,
    'private_key_type' => OPENSSL_KEYTYPE_RSA,
]);

OR, a string with full path to the RSA private key like below:

$key = '/path/to/rsa.key';

// Then, instantiate JWT with this key and RS* as algo:
$jwt = new JWT($key, 'RS384');

Pro You dont need to specify pub key path, that is deduced from priv key.

Generate JWT token from payload array:

$token = $jwt->encode([
    'uid'    => 1,
    'aud'    => 'http://site.com',
    'scopes' => ['user'],
    'iss'    => 'http://api.mysite.com',
]);

Retrieve the payload array:

$payload = $jwt->decode($token);

Oneliner:

$token   = (new JWT('topSecret', 'HS512', 1800))->encode(['uid' => 1, 'scopes' => ['user']]));
$payload = (new JWT('topSecret', 'HS512', 1800))->decode($token);

Pro

Can pass extra headers into encode() with second parameter:

$token = $jwt->encode($payload, ['hdr' => 'hdr_value']);

Test mocking

Spoof time() for testing token expiry:

$jwt->setTestTimestamp(time() + 10000);

// Throws Exception.
$jwt->parse($token);

Call again without parameter to stop spoofing time():

$jwt->setTestTimestamp();

Examples with kid

$jwt = new JWT(['key1' => 'secret1', 'key2' => 'secret2']);

// Use key2
$token = $jwt->encode(['a' => 1, 'exp' => time() + 1000], ['kid' => 'key2']);

$payload = $jwt->decode($token);

$token = $jwt->encode(['a' => 1, 'exp' => time() + 1000], ['kid' => 'key3']);
// -> Exception with message Unknown key ID key3

Stabillity

The library is now marked at version 1.*.* as being stable in functionality and API.

Integration

Phalcon

Check adhocore/phalcon-ext.

Laravel/Lumen

Coming soon laravel-jwt.

Consideration

Be aware of some security related considerations as outlined here which can be valid for any JWT implementations.

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].