Skip to content

Latest commit

 

History

History
70 lines (49 loc) · 1.43 KB

File metadata and controls

70 lines (49 loc) · 1.43 KB

IC Auth Filter

This package enables filtering using IC service in go-restful apps.

Usage

Importing

import "github.com/AccelByte/go-restful-plugins/v4/pkg/auth/ic"

Create filter

This filter depends on IC client passed through the constructor.

Create Filter:

filter := ic.NewFilter(icClient)

Constructing filter

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,
    })),
).

Reading JWT Claims

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()

Filter all endpoints

ws := new(restful.WebService)
ws.Filter(filter.Auth())

Filter specific endpoint

ws := new(restful.WebService)
ws.Route(ws.GET("/user/{id}").
    Filter(filter.Auth()).
    To(func(request *restful.Request, response *restful.Response) {
}))