Coder Social home page Coder Social logo

nette-jwt-user-storage's Introduction

nette-jwt-user-storage

Join the chat at https://gitter.im/klimesf/nette-jwt-user-storage Latest Stable Version License Build Status

JWT

Nette IUserStorage implementation using JWT access token instead of PHP sessions.

Disclaimer: If you don't know what JWT is, please refer to JWT draft or to JWT homepage.

On user login, the application stores jwt_access_token cookie instead of bad old PHPSESSID one. The cookie contains an encoded JWT signed by the application. The user authentication is then based on verifying the JWT rather than the session.

Warning: CSRF protection rules still apply!

This means you no longer need to solve PHP session implementation, scaling and testing problems. All the things that you would normally store in the SessionStorage can be stored in a key-value storage, where the JWT is a key.

This also means your application is ready to become SPA in the future. :)

Configuration

Register the extension in your config.neon.

extensions:
	jwtUserStorage: Klimesf\Security\DI\JWTUserStorageExtension

Then configure its required properties.

JWTUserStorage:
	privateKey: 'secret-cat'    # this secret is used to sign the JWT
	algorithm: 'HS256'          # this is the signing algorithm

Both the JWT and the cookie in which it's stored is by default set to expire in 20 days. If you want to fiddle with expiration time, use expiration option:

JWTUserStorage:
	expiration: 20 days     # sets JWT and cookie expiration time to 20 days (this is the default option)
	expiration: 20 minutes  # sets JWT and cookie expiration time to 20 minutes
	expiration: false       # sets JWT and cookie to never expire

By default, jti and iat (see JWT draft) are added to your JWTs. If you don't want to use them, set generateJti and generateIat options to false.

JWTUserStorage:
	generateJti: false          # disables jti generation for your JWT access tokens
	generateIat: false          # disables iat generation for your JWT access tokens

If you want to define your own Nette\Security\IIdentity serializer, which serializes your identity implementation into the JWT body, you can implement Klimesf\Security\IIdentitySerializer

namespace Your\Own;

class IdentitySerializer implements \Klimesf\Security\IIdentitySerializer
{
	// ...
}

and register it in configuration.

JWTUserStorage:
	identitySerializer: Your\Own\IdentitySerializer

And that's it, you're ready to go!

Known issues

  • If you are developing an app with JWT User Storage and you still see PHPSESSID in your cookies, it's probably because Tracy\Tracy uses it.

Discussion threads

Literature

nette-jwt-user-storage's People

Contributors

gitter-badger avatar klimesf avatar slepic avatar

Watchers

 avatar  avatar

Forkers

fallesk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.