jwt

package
v0.0.0-...-9f41b84 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2020 License: MIT Imports: 5 Imported by: 0

README

Kira

JWT for kira framework

Getting Started | Configuration


Getting Started

package main

import (
    "github.com/go-kira/kira"
    "github.com/go-kira/kira/middlewares/jwt"
)

func main() {
    app := kira.New()
    app.Use(csrf.NewCSRF()) // We use the middleware globally

    app.Get("/jwt", func(ctx *kira.Context) {
        token, err := jwt.CreateToken(ctx, map[string]interface{}{
            "foo": "bar",
        })
        if err != nil {
            ctx.Error(err)
        }

        ctx.Stringf("JWT token: %s", token)
    })

    app.Post("/jwt", func(ctx *kira.Context) {
        ctx.String("Protected.")
    })

    app.Run()
}

Configuration

You can configure this middleware from your config.toml file.

  • [app.key]: It's used to encrypt the JWT token.
  • [jwt.lookup]: You can shouls which method to use in the lookup: <method>:<name>. By default it's header:Authorization

You can use in the lookup only: header, cookie. Maybe in the future we support more methods like query...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateToken

func CreateToken(ctx *kira.Context, claims jwt.MapClaims) (string, error)

CreateToken generate JWT token.

Types

type JWT

type JWT struct{}

JWT - Middleware.

func New

func New() *JWT

New - return JWT instance

func (*JWT) Middleware

func (j *JWT) Middleware(ctx *kira.Context, next kira.HandlerFunc)

Middleware handler

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL