Giter VIP home page Giter VIP logo

plack-middleware-auth-jwt's Introduction

NAME

Plack::Middleware::Auth::JWT - Token-based Auth (aka Bearer Token) using JSON Web Tokens (JWT)

VERSION

version 0.907

SYNOPSIS

# use Crypt::JWT to decode the JWT
use Plack::Builder;
builder {
    enable "Plack::Middleware::Auth::JWT",
        decode_args => { key => '12345' },
    ;
    $app;
};

# or provide your own decoder in a callback
use Plack::Builder;
builder {
    enable "Plack::Middleware::Auth::JWT",
        decode_callback => sub {
            my $token = shift;
            ....
        },
    ;
    $app;
};


# curl -H 'Authorization: Bearer eyJhbG...'
# if the JWT is valid, two keys will be added to $env->{psgix}
# $env->{'psgix.token'}  = 'original_token'
# $env->{'psgix.claims'} = { sub => 'bart' } # claims as hashref

DESCRIPTION

Plack::Middleware::Auth::JWT helps you to use JSON Web Tokens (or JWT) for authentificating HTTP requests. Tokens can be provided in the Authorization HTTP Header, or as a query parameter (though passing the JWT via the header is the prefered method).

Configuration

TODO

decode_args

See "decode_jwt" in Crypt::JWT

Please note that key might has to be passed as a string-ref or an object, see Crypt::JWT

It is very much recommended that you only allow the algorithms you are actually using by setting accepted_alg! Per default, 'none' is not allowed.

Hardcoded:

    decode_payload = 1
    decode_header  = 0

Different defaults:

    verify_exp = 1
    leeway     = 5

You either have to use decode_args, or provide a decode_callback.

decode_callback

Callback to decode the token. Gets the token as a string and the psgi-env, has to return a hashref with claims.

You have to either provide a callback, or use decode_args.

psgix_claims

Default: claims

Name of the entry in psgix were the claims are stored, so you can get the (for example) sub claim via

$env->{'psgix.claims'}->{sub}

psgix_token

Default: token

Name of the entry in psgix were the raw token is stored.

token_required

Default: false

If set to a true value, all requests need to include a valid JWT. Default false, so you have to check in your application code if a token was submitted.

ignore_invalid_token

Default: false

If set to a true value, passing an invalid JWT will not abort the requerst with status 401. Instead the app will be called as if no token was passed at all.

You can use this to implement another token check in a later middleware, or even in your app. Of course you will then have to check for $env->{psgix.token} in your controller actions.

token_header_name

Default: Bearer

Name of the token in the HTTP Authorization header. If you set it to 0, headers will be ignored.

token_query_name

Default: token

Name of the HTTP query param that contains the token. If you set it to 0, tokens in the query will be ignored.

Example

TODO, in the meantime you can take a look at the tests.

SEE ALSO

THANKS

Thanks to

AUTHOR

Thomas Klausner [email protected]

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 - 2022 by Thomas Klausner.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

plack-middleware-auth-jwt's People

Contributors

domm avatar jwrightecs avatar mrdvt92 avatar

Watchers

 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.