added README.md

This commit is contained in:
Darko Luketic 2021-11-17 11:46:34 +01:00
parent 7f3f67364f
commit 879c7be1bc

42
README.md Normal file
View File

@ -0,0 +1,42 @@
# ginoidc
ginoidc is a package based on [XenitAB's gin oidc middleware](github.com/XenitAB/go-oidc-middleware).
It features the handler being permissive and adds errors to the `*gin.Context`'s context values under the `"oidcerrors"` key.
You can also extract keycloak claims from the `*gin.Context` via `keycloakclaims.FromRequest(*gin.Context)`.
```go
package main
import (
"git.icod.de/dalu/ginoidc"
"git.icod.de/dalu/oidc/options"
)
func main() {
r := gin.Default()
var cfg config.OIDCConfig
oidcHandler := ginoidc.New(
options.WithIssuer(cfg.Issuer),
options.WithRequiredTokenType("JWT"),
options.WithRequiredAudience(cfg.Audience),
options.WithPermissive(),
)
v1 := r.Group("/api/v1")
v1.Use(oidcHandler)
entity := v1.Group("/entity")
entity.GET("/", List)
entity.GET("/:id", GetOne)
entity.POST("/", CreateOne)
entity.PUT("/:id", UpdateOne)
entity.DELETE("/:id", DeleteOne)
}
// example handler
func List(cx *gin.Context) {
claims := keycloakclaims.FromRequest(cx)
cx.JSON(200, claims)
}
```