GithubHelp home page GithubHelp logo

forging2012 / jwtauth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lpar/jwtauth

0.0 3.0 0.0 15 KB

Session-based authentication in Go using JWT & JWS

License: BSD 3-Clause "New" or "Revised" License

Go 100.00%

jwtauth's Introduction

jwtauth

This library implements (mostly) stateless web session authentication using JSON Web Tokens (JWT).

As of 2018, I recommend pasetosession instead.

Initiating login and checking credentials is left to the caller, as it depends heavily on the sign-in technology used. Once you've established who the user is once, this library gives you a way to track that information securely throughout your application without needing to keep extensive server-side state.

Things to note:

  • The tokens are signed and encrypted to prevent tampering, using RSA. Tokens which fail decryption and signature checking are not accepted.

  • Nonce values are embedded in the encrypted tokens as jti parameters, to ensure that tokens cannot be reused and guard against replay attacks.

  • Cookies and tokens are both given expiry periods, to implement idle session timeout.

  • Cookies are marked HttpOnly to guard against XSS attacks.

  • Don't forget to protect your forms against CSRF, including your login form.

A handler is provided to deal with protecting routes which require authentication. The detected identity is passed to the next handler in the chain using Go's Context mechanism.

Since tokens are one time only, sessions must be kept alive by reissuing updated tokens. A heartbeat handler is provided to do this for page loads which do not require authentication.

Other options

If you want a lot more configurability at the cost of some complexity, you might want to check out adam-hanna/jwt-auth instead.

jwtauth's People

Contributors

lpar avatar

Watchers

 avatar  avatar  avatar

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.