Skip to content

Commit

Permalink
Add CSRF support packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Triple-Z committed Mar 13, 2019
1 parent 1515b53 commit b25f3d6
Show file tree
Hide file tree
Showing 38 changed files with 3,224 additions and 0 deletions.
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import (
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
"github.com/gin-contrib/sessions"
"github.com/utrack/gin-csrf"
"github.com/gin-contrib/sessions/cookie"
)

func Migrate(db *gorm.DB) {
Expand Down Expand Up @@ -86,6 +89,7 @@ func main() {
r := gin.Default()

// After init router
// CORS
if common.DEBUG {
r.Use(cors.New(cors.Config{
AllowAllOrigins: true,
Expand All @@ -106,6 +110,17 @@ func main() {
}))
}

// CSRF
store := cookie.NewStore([]byte("secret"))
r.Use(sessions.Sessions("mysession", store))
r.Use(csrf.Middleware(csrf.Options{
Secret: "secret123",
ErrorFunc: func(c *gin.Context){
c.String(400, "CSRF token mismatch")
c.Abort()
},
}))

r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
Expand Down
97 changes: 97 additions & 0 deletions vendor/github.com/dchest/uniuri/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions vendor/github.com/dchest/uniuri/uniuri.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/gin-contrib/sessions/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b25f3d6

Please sign in to comment.