Go IAM SDK
September 19, 2025 ยท View on GitHub
The Go IAM SDK is a comprehensive multi-language library for integrating with the Go IAM server. It provides methods for authentication, user management, and resource creation across multiple programming languages and frameworks.
Available SDKs:
- Go - Server-side applications
- TypeScript - Node.js and browser applications
- Python - Python applications with async support
- Rust - High-performance applications
- React - Frontend React applications with Context, hooks, and components
โ Admin UI: go-iam-ui
๐ณ Docker Setup: go-iam-docker
๐ Backend: go-iam
๐ฆ SDK: go-iam-sdk
๐ Examples: go-iam-examples
Installation
Go
go get github.com/melvinodsa/go-iam-sdk/golang
TypeScript
npm install @goiam/typescript
# or
pnpm add @goiam/typescript
# or
yarn add @goiam/typescript
Python
pip install goiam-python
# or
poetry add goiam-python
# or
pipenv install goiam-python
Rust
Add to your Cargo.toml:
[dependencies]
goiam = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
React
npm install @goiam/react
# or
pnpm add @goiam/react
# or
yarn add @goiam/react
Usage
Go
Initialize the Service
import (
"context"
goiam "github.com/melvinodsa/go-iam-sdk/golang"
)
func main() {
service := goiam.NewService("https://go-iam.example.com", "your-client-id", "your-secret")
// Use the service instance for API calls
}
Verify Authentication Code
ctx := context.Background()
token, err := service.Verify(ctx, "auth-code")
if err != nil {
log.Fatalf("Failed to verify code: %v", err)
}
fmt.Println("Access Token:", token)
Fetch Current User Information
user, err := service.Me(ctx, token)
if err != nil {
log.Fatalf("Failed to fetch user information: %v", err)
}
fmt.Printf("User: %+v\n", user)
Create a Resource
resource := &golang.Resource{
ID: "resource-id",
Name: "Resource Name",
Description: "Resource Description",
Tags: []string{"tag1", "tag2"},
}
err = service.CreateResource(ctx, resource)
if err != nil {
log.Fatalf("Failed to create resource: %v", err)
}
fmt.Println("Resource created successfully")
TypeScript
Initialize the SDK
import { GoIamSdk } from "@goiam/typescript";
const sdk = new GoIamSdk(
"https://go-iam.example.com",
"your-client-id",
"your-secret"
);
Verify Authentication Code
const token = await sdk.verify("auth-code");
console.log("Access Token:", token);
Fetch Current User Information
const user = await sdk.me(token);
console.log("User:", user);
Create a Resource
const resource = {
id: "resource-id",
name: "Resource Name",
description: "Resource Description",
key: "resource-key",
enabled: true,
projectId: "project-id",
createdBy: "creator",
updatedBy: "updater",
};
await sdk.createResource(resource, token);
console.log("Resource created successfully");
Python
Initialize the SDK
from goiam import new_service
service = new_service(
base_url="https://go-iam.example.com",
client_id="your-client-id",
secret="your-secret"
)
Verify Authentication Code
try:
token = service.verify("auth-code")
print(f"Access Token: {token}")
except Exception as error:
print(f"Failed to verify code: {error}")
Fetch Current User Information
try:
user = service.me(token)
print(f"User: {user.name} ({user.email})")
except Exception as error:
print(f"Failed to fetch user information: {error}")
Create a Resource
from goiam import Resource
resource = Resource(
id="resource-id",
name="Resource Name",
description="Resource Description",
key="resource-key",
enabled=True,
project_id="project-id",
created_by="creator",
updated_by="updater"
)
try:
service.create_resource(resource, token)
print("Resource created successfully")
except Exception as error:
print(f"Failed to create resource: {error}")
Rust
Initialize the SDK
use goiam::{new_service, Service};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let service = new_service(
"https://go-iam.example.com".to_string(),
"your-client-id".to_string(),
"your-secret".to_string(),
);
// SDK usage here...
Ok(())
}
Verify Authentication Code
match service.verify("auth-code").await {
Ok(token) => println!("Access Token: {}", token),
Err(error) => eprintln!("Failed to verify code: {}", error),
}
Fetch Current User Information
match service.me(&token).await {
Ok(user) => println!("User: {} ({})", user.name, user.email),
Err(error) => eprintln!("Failed to fetch user information: {}", error),
}
Create a Resource
use goiam::Resource;
let resource = Resource::new("resource-id".to_string(), "Resource Name".to_string());
match service.create_resource(&resource, &token).await {
Ok(_) => println!("Resource created successfully"),
Err(error) => eprintln!("Failed to create resource: {}", error),
}
React
Setup Provider
import React from "react";
import { GoIamProvider, createGoIamConfig } from "@goiam/react";
const config = createGoIamConfig({
baseUrl: "https://go-iam.example.com",
clientId: "your-client-id",
redirectUrl: "https://your-app.com/callback",
});
function App() {
return (
<GoIamProvider config={config}>
<YourApp />
</GoIamProvider>
);
}
Authentication Hook
import { useGoIam } from "@goiam/react";
function LoginButton() {
const { isAuthenticated, user, login, logout, isLoading } = useGoIam();
if (isLoading) return <div>Loading...</div>;
if (isAuthenticated) {
return (
<div>
<p>Welcome, {user?.name || user?.email}!</p>
<button onClick={logout}>Logout</button>
</div>
);
}
return <button onClick={login}>Login</button>;
}
Protect Routes
import { AuthGuard } from "@goiam/react";
function ProtectedRoute() {
return (
<AuthGuard requiredRoles={["admin"]} redirectToLogin={true}>
<AdminDashboard />
</AuthGuard>
);
}
Repository Structure
This repository contains multiple SDK implementations for different languages and frameworks:
go-iam-sdk/
โโโ golang/ # Go SDK - Server-side applications
โโโ typescript/ # TypeScript SDK - Node.js and browser
โโโ python/ # Python SDK - Python applications
โโโ rust/ # Rust SDK - High-performance applications
โโโ react/ # React SDK - React applications with hooks and components
SDK Documentation
Each SDK has its own comprehensive documentation:
- Go SDK - Server-side Go applications
- TypeScript SDK - Node.js and browser JavaScript/TypeScript
- Python SDK - Python applications with asyncio support
- Rust SDK - High-performance Rust applications
- React SDK - React applications with Context, hooks, and components
- Reddit Community - Reddit community for discussions
Features by SDK
| Feature | Go | TypeScript | Python | Rust | React |
|---|---|---|---|---|---|
| Authentication | โ | โ | โ | โ | โ |
| User Management | โ | โ | โ | โ | โ |
| Resource Management | โ | โ | โ | โ | N/A |
| Context Provider | N/A | N/A | N/A | N/A | โ |
| Auth Guards | N/A | N/A | N/A | N/A | โ |
| Role-based Access | โ | โ | โ | โ | โ |
| TypeScript Support | N/A | โ | N/A | N/A | โ |
| Async/Await | N/A | โ | โ | โ | โ |
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Make your changes in the appropriate SDK directory
- Add tests for your changes
- Ensure all tests pass (
make testin the SDK directory) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.