Skip to content

middleware


title: “Package middleware” description: “Package middleware” lead: "" date: 2023-06-12T13:46:25-06:00 lastmod: 2023-06-12T13:46:25-06:00 draft: false images: [] menu: docs: parent: “go-api” weight: 335 toc: true

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

// Initialize the TAM SDK
tam, 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 namespace
tamMiddleware, err := tammiddleware.Middleware(tam, "org.policies", "allow")
if err != nil {
// Handle error from tammiddleware.Middleware...
}
// Set up gin to use TAM middleware
r := gin.Default()
r.Use(tamMiddleware)

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 ParameterTypeDescription
tamSdktamsdk.SDKAn instance of the TAM SDK that the middleware uses to evaluate authorization decisions.
packageNamespacestringThe policy package namespace to use for decisions.
rulestringThe policy rule to use for decisions.