Go to file
2022-11-03 15:59:48 +01:00
ginerror bad copy/paste, changed ginerror.Error field 2021-11-15 14:58:15 +01:00
keycloakclaims added utils test 2022-11-03 15:59:48 +01:00
gin.go move to code.icod.de 2022-10-18 12:04:48 +02:00
go.mod migration to code.icod.de go mods 2022-10-18 12:12:55 +02:00
go.sum migration to code.icod.de go mods 2022-10-18 12:12:55 +02:00
README.md update README 2022-10-18 12:14:31 +02:00

ginoidc

ginoidc is a package based on XenitAB's gin 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).

package main
import (
    "code.icod.de/dalu/ginoidc"
    "code.icod.de/dalu/ginoidc/keycloakclaims"
    "code.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.IsPermissive(),
    )
    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)
}