Code Monkey home page Code Monkey logo

gin-csrf's People

Contributors

pkix avatar tommy351 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gin-csrf's Issues

Examples do not work

Using the example from your README:

package main

import (
        "github.com/gin-gonic/gin"
        "github.com/tommy351/gin-sessions"
        "github.com/tommy351/gin-csrf"
)


func main(){
        g := gin.New()
        store := sessions.NewCookieStore([]byte("secret123"))
        g.Use(sessions.Middleware("my_session", store))
        g.Use(csrf.Middleware(csrf.Options{
                Secret: "secret123",
                ErrorFunc: func(c *gin.Context){
                        c.String(400, "invalid csrf")
                        c.Abort()
                },
        }))

        g.GET("/protected", func(c *gin.Context){
                csrf.GetToken(c)
                c.String(200, csrf.GetToken(c))
        })

        g.POST("/protected", func(c *gin.Context){
                csrf.GetToken(c)
                c.String(200, "CSRF token is valid")
        })

        g.Run(":3000")
}

I am able to POST to /protected without any cookies and I receive a message that the CSRF token is valid.

Making it work with gin-contrib/sessions?

I was already using gin-contrib sessions in a project, but then when I needed csrf token support and found this library, I find out that this needs your session library instead of the gin-contrib one I was already using.

Is there much difference between your session library and the one from gin-contrib? both seem to be based on gorilla/session and look pretty much identical. Can the gin-csrf library be made compatible with gin-contrib sessions or not really?

Is there any reason why gorilla/csrf was not used as a foundation? I am just looking at the code and it looks like this library implements csrf from scratch.

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.