middleware
middleware
Section titled “middleware”Package tammiddleware is included as part of the github.com/trimble-oss/tam-sdk-go/tammiddleware module and can be imported as follows:
import "github.com/trimble-oss/tam-sdk-go/tammiddleware"Package tammiddleware provides a handler to use with the Gin Web Framework for authorization using Trimble Access Management.
Example
Section titled “Example”// Initialize the TAM SDKtam, err := tamsdk.New(tamsdk.DevelopmentEnvironment, os.Getenv("CLIENT_ID"), os.Getenv("CLIENT_SECRET"), os.Getenv("APPLIANCE_URL"))if err != nil { // Handle error from sdk.New...}
// Get the TAM middleware using the SDK instance and a package namespacetamMiddleware, err := tammiddleware.Middleware(tam, "org.policies", "allow")if err != nil { // Handle error from tammiddleware.Middleware...}
// Set up gin to use TAM middlewarer := gin.Default()r.Use(tamMiddleware)func Middleware
Section titled “func Middleware”func Middleware(tamSdk tamsdk.SDK, packageNamespace string, rule string) (gin.HandlerFunc, error)Middleware returns a gin.HandlerFunc that can be used in the middleware chain for authorization.
This middleware aborts the request with a 403 status code if the rule for the registered policy does not return true or if any errors are encountered while processing the decision output. Any errors are added to the gin.Context’s error list.
The input for decision evaluation includes the method, path, and authorization header (if any) of the active request.
| Input Parameter | Type | Description |
|---|---|---|
tamSdk |
tamsdk.SDK |
An instance of the TAM SDK that the middleware uses to evaluate authorization decisions. |
packageNamespace |
string |
The policy package namespace to use for decisions. |
rule |
string |
The policy rule to use for decisions. |