Skip to content

Releases: XenitAB/go-oidc-middleware

v0.0.14

02 Oct 13:45
32ca0fa
Compare
Choose a tag to compare

Changes

  • Add error forwarding in the gin middleware (#69)

v0.0.13

26 Sep 19:47
540a78a
Compare
Choose a tag to compare

Changes

  • Refactor examples (#62)
  • make benchmarks smaller (#63)
  • Update dependencies (#64 & #67)

v0.0.12

19 Sep 19:35
dc4cb6b
Compare
Choose a tag to compare

Changes

Bump Go from 1.16 to 1.17

v0.0.11

24 Aug 20:18
97bcd2d
Compare
Choose a tag to compare

Changes

This PR adds the ability to manipulate a token string after it has been extracted from a header using options.WithTokenStringPostExtractionFn.

Example:

oidcHandler := oidcgin.New(
	options.WithIssuer(cfg.Issuer),
	options.WithFallbackSignatureAlgorithm(cfg.FallbackSignatureAlgorithm),
	options.WithRequiredClaims(map[string]interface{}{
		"cid": cfg.ClientID,
	}),
	options.WithTokenString(
		options.WithTokenStringHeaderName("Authorization"),
		options.WithTokenStringTokenPrefix("Bearer "),
	),
	options.WithTokenString(
		options.WithTokenStringHeaderName("Sec-WebSocket-Protocol"),
		options.WithTokenStringTokenPrefix("base64url.bearer.authorization.k8s.io."),
		options.WithTokenStringListSeparator(","),
		options.WithTokenStringPostExtractionFn(func(s string) (string, error) {
			bytes, err := base64.RawStdEncoding.DecodeString(s)
			if err != nil {
				return "", err
			}

			return string(bytes), nil
		}),
	),
)

v0.0.10

23 Aug 19:52
c7b454a
Compare
Choose a tag to compare

Breaking change

Token string options have been changed to make it easier to configure extraction of multiple headers.

Example:

oidcHandler := oidcgin.New(
	options.WithIssuer(cfg.Issuer),
	options.WithFallbackSignatureAlgorithm(cfg.FallbackSignatureAlgorithm),
	options.WithRequiredClaims(map[string]interface{}{
		"cid": cfg.ClientID,
	}),
	options.WithTokenString(
		options.WithTokenStringHeaderName("Authorization"),
		options.WithTokenStringTokenPrefix("Bearer "),
	),
	options.WithTokenString(
		options.WithTokenStringHeaderName("Sec-WebSocket-Protocol"),
		options.WithTokenStringTokenPrefix("base64url.bearer.authorization.k8s.io."),
		options.WithTokenStringListSeparator(","),
	),
)

v0.0.9

15 Aug 22:04
5ee94d7
Compare
Choose a tag to compare

Added middleware for fiber.

Import

"github.com/xenitab/go-oidc-middleware/oidcfiber"

Middleware

oidcHandler := oidcfiber.New(
	options.WithIssuer(cfg.Issuer),
	options.WithRequiredTokenType("JWT"),
	options.WithRequiredAudience(cfg.Audience),
	options.WithFallbackSignatureAlgorithm(cfg.FallbackSignatureAlgorithm),
	options.WithRequiredClaims(map[string]interface{}{
		"tid": cfg.TenantID,
	}),
)

Handler

func newClaimsHandler() fiber.Handler {
	return func(c *fiber.Ctx) error {
		claims, ok := c.Locals("claims").(map[string]interface{})
		if !ok {
			return c.SendStatus(fiber.StatusUnauthorized)
		}

		return c.JSON(claims)
	}
}

v0.0.8

14 Aug 21:34
e40d171
Compare
Choose a tag to compare

Changes:

  • Move defaults to options package (#32)
  • Change echojwt from using jwt.Token to map[string]interface{} (#33)

Breaking change:

oidcechojwt now returns a map[string]interface{} instead of jwt.Token.

Previously, you had to use the following:

func newClaimsHandler(c echo.Context) error {
	token, ok := c.Get("user").(jwt.Token)
	if !ok {
		return echo.NewHTTPError(http.StatusUnauthorized, "invalid token")
	}

	claims, err := token.AsMap(c.Request().Context())
	if err != nil {
		return echo.NewHTTPError(http.StatusUnauthorized, "invalid token")
	}

	return c.JSON(http.StatusOK, claims)
}

Now you you instead get the claims directly:

func newClaimsHandler(c echo.Context) error {
	claims, ok := c.Get("user").(map[string]interface{})
	if !ok {
		return echo.NewHTTPError(http.StatusUnauthorized, "invalid token")
	}

	return c.JSON(http.StatusOK, claims)
}

v0.0.7

13 Aug 22:27
bd219ba
Compare
Choose a tag to compare

Changes:

  • Bump github.com/lestrrat-go/jwx from 1.2.4 to 1.2.5 (#14)
  • Generalize tests (#27)
  • Make token string options configurable (#28)
  • add tests and docs for chi (#29)

v0.0.6

11 Aug 21:50
bcecc3f
Compare
Choose a tag to compare

BREAKING CHANGE:

The library has moved from using a struct as options to using functional options.

Now the "github.com/xenitab/go-oidc-middleware/options" package needs to be imported and used like this:

oidcHandler := oidchttp.New(h,
	options.WithIssuer(cfg.Issuer),
	options.WithRequiredTokenType("JWT"),
	options.WithRequiredAudience(cfg.Audience),
	options.WithFallbackSignatureAlgorithm(cfg.FallbackSignatureAlgorithm),
	options.WithRequiredClaims(map[string]interface{}{
		"tid": cfg.TenantID,
	}),
)

v0.0.5

10 Aug 20:41
e108504
Compare
Choose a tag to compare
add gin support (#19)

* add gin support

* update readme

* make all