This package enables filtering using IC service in go-restful apps.
import "github.com/AccelByte/go-restful-plugins/v4/pkg/auth/ic"This filter depends on IC client passed through the constructor.
Create Filter:
filter := ic.NewFilter(icClient)The default Auth() filter only validates if the JWT access token is valid.
ws := new(restful.WebService)
ws.Filter(filter.Auth())However, it can be expanded through FilterOption parameters. There are several built-in expansions in this package ready for use.
ws.Filter(service.AuthFilter.Auth(
auth.WithValidUser(),
auth.WithPermission(&ic.Permission{
Resource: "ADMIN:ORG:{organizationId}:PROJ:{projectId}:Info",
Action: ic.ActionUpdate,
})),
).Auth() filter will inject the parsed IC SDK's JWT claims to restful.Request.attribute. To retrieve it, use:
claims := ic.RetrieveJWTClaims(request)Note
Retrieved claims can be nil if the request not filtered using Auth()
ws := new(restful.WebService)
ws.Filter(filter.Auth())ws := new(restful.WebService)
ws.Route(ws.GET("/user/{id}").
Filter(filter.Auth()).
To(func(request *restful.Request, response *restful.Response) {
}))