Logo Lanfrica

National-ID-Program-Ethiopia/fayda-auth-go

Domaine:

digital infrastructure

Type de record:

software
Créateur:
Nat
Hôte:
Proof of Concept of verify fayda 2(esignet) using go language # Fayda Auth Go Library `fayda_auth` is a Go library for integrating with Fayda Esignet OAuth authentication. It simplifies generating authorization URLs, managing sessions with Redis, and authenticating users via token exchange, supporting modern JWK-based client assertions. This library mirrors the functionality of its Python counterpart, `fayda-auth`. --- ## Features - Generate OAuth authorization URLs for Fayda Esignet. - Secure session management using Redis. - Client assertion generation with JWK private keys. - Easy integration with Go applications (e.g., `Gin, net/http` servers). --- ## Installation Install `fayda-auth-go` using `go get`: ```bash go get github.com/ /fayda-auth-go ``` ### Requirements - Go 1.20 or higher - A running Redis server --- ## Quick Start Here’s a basic example to get started: ```go package main import ( "log" fayda "github.com/ /fayda-auth-go/fayda_auth" ) func main() { // Initialize host configs hostConfigs := []fayda.HostConfig{ {Origin: "localhost", RedirectURI: "localhost"}, } // Initialize Redis client redisClient := fayda.NewRedisClient() // Configure FaydaAuth auth, err := fayda.NewFaydaAuth(hostConfigs, redisClient, ".env") if err != nil { log.Fatalf("Failed to initialize FaydaAuth: %v", err) } // Generate authorization URL result, err := auth.Authorize("localhost", "") if err != nil { log.Fatalf("Authorize failed: %v", err) } log.Printf("Authorize result: %+v", result) // Authenticate with real data (replace with actual values) authResult, err := auth.Authenticate( result["data"].(map[string]string)["session_id"], " ", result["data"].(map[string]string)["state"], ) if err != nil { log.Fatalf("Authenticate failed: %v", err) } log.Printf("Authenticate result: %+v", authResult) } ``` --- ## Configuration Create a `.env` file in your project root with the following variables: ```plaintext REDIS_HOST=REDIS-HOST REDIS_PORT=REDIS-PORT FAYDA_OAUTH_CLIENT_ID=your_c …