credential

package
v0.5.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2026 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyTransform

func ApplyTransform(value any, transform string) any

ApplyTransform applies a named transformation to a value.

Example (Lowercase)
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/credential"
)

func main() {
	result := credential.ApplyTransform("HELLO WORLD", "lowercase")
	fmt.Println(result)
}
Output:
hello world
Example (NoTransform)
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/credential"
)

func main() {
	result := credential.ApplyTransform("unchanged", "")
	fmt.Println(result)
}
Output:
unchanged
Example (NonString)
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/credential"
)

func main() {
	result := credential.ApplyTransform(42, "lowercase")
	fmt.Println(result)
}
Output:
42
Example (Trim)
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/credential"
)

func main() {
	result := credential.ApplyTransform("  padded string  ", "trim")
	fmt.Println(result)
}
Output:
padded string
Example (Uppercase)
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/credential"
)

func main() {
	result := credential.ApplyTransform("hello world", "uppercase")
	fmt.Println(result)
}
Output:
HELLO WORLD

func GetNestedValue

func GetNestedValue(doc map[string]any, path string) (any, bool)

GetNestedValue retrieves a value from a map using dot-notation path.

Example
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/credential"
)

func main() {
	doc := map[string]any{
		"identity": map[string]any{
			"given_name":  "Alice",
			"family_name": "Smith",
		},
		"vct": "pid",
	}

	name, ok := credential.GetNestedValue(doc, "identity.given_name")
	fmt.Println("value:", name, "found:", ok)

	vct, ok := credential.GetNestedValue(doc, "vct")
	fmt.Println("value:", vct, "found:", ok)

	_, ok = credential.GetNestedValue(doc, "missing.path")
	fmt.Println("missing found:", ok)
}
Output:
value: Alice found: true
value: pid found: true
missing found: false
Example (EmptyPath)
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/credential"
)

func main() {
	doc := map[string]any{"key": "value"}
	_, ok := credential.GetNestedValue(doc, "")
	fmt.Println("found:", ok)
}
Output:
found: false

func SetNestedValue

func SetNestedValue(doc map[string]any, path string, value any) error

SetNestedValue sets a value in a map using dot-notation path. Example: "identity.family_name" creates map[identity][family_name] = value

Example
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/credential"
)

func main() {
	doc := make(map[string]any)

	_ = credential.SetNestedValue(doc, "identity.given_name", "Alice")
	_ = credential.SetNestedValue(doc, "identity.family_name", "Smith")
	_ = credential.SetNestedValue(doc, "vct", "pid")

	fmt.Println("given_name:", doc["identity"].(map[string]any)["given_name"])
	fmt.Println("family_name:", doc["identity"].(map[string]any)["family_name"])
	fmt.Println("vct:", doc["vct"])
}
Output:
given_name: Alice
family_name: Smith
vct: pid
Example (EmptyPath)
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/credential"
)

func main() {
	doc := make(map[string]any)
	err := credential.SetNestedValue(doc, "", "value")
	fmt.Println("error:", err)
}
Output:
error: empty path

Types

type ClaimTransformer

type ClaimTransformer struct {
	// contains filtered or unexported fields
}

ClaimTransformer transforms external attributes/claims into credential document structures. Protocol-agnostic — works for SAML OIDs, OIDC claim names, or any other attribute source.

func NewClaimTransformer

func NewClaimTransformer(mappings map[string]model.CredentialMapping) *ClaimTransformer

NewClaimTransformer creates a new claim transformer from credential mappings.

Example
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/credential"
)

func main() {
	transformer := credential.NewClaimTransformer(nil)
	fmt.Printf("%T\n", transformer)
}
Output:
*credential.ClaimTransformer

func (*ClaimTransformer) GetMapping

func (t *ClaimTransformer) GetMapping(credentialType string) (*model.CredentialMapping, error)

GetMapping returns the credential mapping for a credential type.

func (*ClaimTransformer) TransformClaims

func (t *ClaimTransformer) TransformClaims(
	credentialType string,
	attributes map[string]any,
) (map[string]any, error)

TransformClaims converts external attributes (keyed by protocol-specific identifiers) to a generic document structure using the configured mappings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL