basic

command
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package main demonstrates the basic usage of api-security-sdk: JWT authentication with HMAC signing and RBAC authorisation.

Run:

go run ./examples/basic

Then:

# Get a token for "bob" (editor role)
TOKEN=$(curl -s 'http://localhost:8080/login?user=bob' | tr -d '"{}' | cut -d: -f2)

# Read posts (allowed — editor inherits viewer's read permission)
curl -H "Authorization: Bearer $TOKEN" http://localhost:8080/posts

# Get a token for "carol" (viewer role) and try to create
TOKEN=$(curl -s 'http://localhost:8080/login?user=carol' | tr -d '"{}' | cut -d: -f2)
curl -X POST -H "Authorization: Bearer $TOKEN" http://localhost:8080/posts  # → 403

Jump to

Keyboard shortcuts

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