-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdoc_test.go
32 lines (26 loc) · 819 Bytes
/
doc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package jwt_test
import (
jwt "github.com/akhettar/gin-jwt-cognito"
"github.com/gin-gonic/gin"
)
func ExampleAuthMiddleware() {
// Creates a gin router with default middleware:
router := gin.Default()
// Create Cognito JWT auth middleware and set it in all authenticated endpoints
mw, err := jwt.AuthJWTMiddleware("<some_iss>", "<some_userpool_id>", "region")
if err != nil {
panic(err)
}
router.GET("/someGet", mw.MiddlewareFunc(), func(context *gin.Context) {
// some implementation
})
router.POST("/somePost", mw.MiddlewareFunc(), func(context *gin.Context) {
// some implementation
})
router.PUT("/somePut", mw.MiddlewareFunc(), func(context *gin.Context) {
// some implementation
})
// By default it serves on :8080 unless a
// PORT environment variable was defined.
router.Run()
}