Quick Start Guide
Step 1: Install the SDK
Go
Bash
go get github.com/melvinodsa/go-iam-sdk/golang
Step 2: Initialize the SDK
Go
Go
package main
import (
"context"
"log"
goiam "github.com/melvinodsa/go-iam-sdk/golang"
)
func main() {
service := goiam.NewService(
"https://your-go-iam-server.com",
"your-client-id",
"your-client-secret"
)
// Ready to use!
}
Step 3: Implement Authentication
Server-Side Authentication
Go
ctx := context.Background()
token, err := service.Verify(ctx, "auth-code")
if err != nil {
log.Fatalf("Failed to verify: %v", err)
}
fmt.Println("Access Token:", token)
Step 4: Fetch User Information
Go
user, err := service.Me(ctx, token)
if err != nil {
log.Fatalf("Failed to fetch user: %v", err)
}
fmt.Printf("User: %+v\n", user)
Advanced Features
Resource Management
Go
resource := &golang.Resource{
ID: "resource-id",
Name: "User Dashboard",
Description: "Main user dashboard resource",
Tags: []string{"dashboard", "user"},
}
err = service.CreateResource(ctx, resource)
if err != nil {
log.Fatalf("Failed to create resource: %v", err)
}
Environment Configuration
Bash
# .env file
GO_IAM_BASE_URL=https://your-go-iam-server.com
GO_IAM_CLIENT_ID=your-client-id
GO_IAM_CLIENT_SECRET=your-client-secret
Usage in Code
Go
import "os"
service := goiam.NewService(
os.Getenv("GO_IAM_BASE_URL"),
os.Getenv("GO_IAM_CLIENT_ID"),
os.Getenv("GO_IAM_CLIENT_SECRET"),
)
User object
Go
type User struct {
Id string `json:"id"`
ProjectId string `json:"project_id"`
Name string `json:"name"`
Email string `json:"email"`
Phone string `json:"phone"`
Enabled bool `json:"enabled"`
ProfilePic string `json:"profile_pic"`
Expiry *time.Time `json:"expiry"`
Roles map[string]UserRole `json:"roles"`
Resources map[string]UserResource `json:"resources"`
Policies map[string]UserPolicy `json:"policies"`
CreatedAt *time.Time `json:"created_at"`
CreatedBy string `json:"created_by"`
UpdatedAt *time.Time `json:"updated_at"`
UpdatedBy string `json:"updated_by"`
}
type UserPolicy struct {
Name string `json:"name"`
Mapping UserPolicyMapping `json:"mapping,omitempty"`
}
type UserPolicyMapping struct {
Arguments map[string]UserPolicyMappingValue `json:"arguments,omitempty"`
}
type UserPolicyMappingValue struct {
Static string `json:"static,omitempty"`
}
type UserRole struct {
Id string `json:"id"`
Name string `json:"name"`
}
type UserResource struct {
RoleIds map[string]bool `bson:"role_ids"`
PolicyIds map[string]bool `bson:"policy_ids"`
Key string `json:"key"`
Name string `json:"name"`
}