{"id":36494931,"url":"https://github.com/rou-technology/openauth-go","last_synced_at":"2026-01-12T02:00:10.425Z","repository":{"id":267519993,"uuid":"901502185","full_name":"ROU-Technology/openauth-go","owner":"ROU-Technology","description":"Go server-side SDK for [OpenAuth](https://github.com/openauthjs/openauth), providing token verification and management capabilities for OpenAuth-issued tokens.","archived":false,"fork":false,"pushed_at":"2024-12-19T09:12:57.000Z","size":89,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-12-19T10:26:12.506Z","etag":null,"topics":["go","golang","oauth","oauth2","openauth"],"latest_commit_sha":null,"homepage":"https://github.com/openauthjs/openauth","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ROU-Technology.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-10T19:22:34.000Z","updated_at":"2024-12-19T09:12:29.000Z","dependencies_parsed_at":"2024-12-10T20:35:21.656Z","dependency_job_id":"49c44339-bc3c-4f2e-9bbb-970b75e9fc76","html_url":"https://github.com/ROU-Technology/openauth-go","commit_stats":null,"previous_names":["rou-technology/openauth-go"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ROU-Technology/openauth-go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ROU-Technology%2Fopenauth-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ROU-Technology%2Fopenauth-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ROU-Technology%2Fopenauth-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ROU-Technology%2Fopenauth-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ROU-Technology","download_url":"https://codeload.github.com/ROU-Technology/openauth-go/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ROU-Technology%2Fopenauth-go/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28331499,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"online","status_checked_at":"2026-01-12T02:00:08.677Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","oauth","oauth2","openauth"],"created_at":"2026-01-12T02:00:07.380Z","updated_at":"2026-01-12T02:00:10.400Z","avatar_url":"https://github.com/ROU-Technology.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenAuth Go SDK\n\nGo server-side SDK for [OpenAuth](https://github.com/openauthjs/openauth), providing token verification and management capabilities for OpenAuth-issued tokens.\n\n## Features\n\n- 🔑 Verify OpenAuth-issued JWT tokens\n- 📦 Efficient caching of JWKS and issuer metadata\n- 🔄 Automatic token refresh support\n- 🔒 Thread-safe implementation\n\n## Installation\n\n```bash\ngo get github.com/ROU-Technology/openauth-go\n```\n\n## Quick Start\n\n### Basic Usage\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \"github.com/ROU-Technology/openauth-go\"\n)\n\nfunc main() {\n    // Initialize the client with your OpenAuth issuer URL\n    client := openauth.NewClient(\"your-client-id\", \"https://your-openauth-server.com\")\n\n    // Define subject validation schema\n    subjects := openauth.SubjectSchema{\n        \"user\": func(props interface{}) error {\n            // Type assert to map\n            properties, ok := props.(map[string]interface{})\n            if !ok {\n                return fmt.Errorf(\"expected map[string]interface{}, got %T\", props)\n            }\n\n            // Check if email exists\n            email, ok := properties[\"email\"].(string)\n            if !ok {\n                return fmt.Errorf(\"email is required and must be a string\")\n            }\n\n            // Validate email format\n            emailRegex := regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$`)\n            if !emailRegex.MatchString(email) {\n                return fmt.Errorf(\"invalid email format\")\n            }\n\n            return nil\n        },\n    }\n\n    // Verify an OpenAuth-issued access token\n    subject, err := client.Verify(subjects, accessToken, nil)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    // Access the validated user properties\n    properties := subject.Properties.(map[string]interface{})\n    email := properties[\"email\"].(string)\n    fmt.Printf(\"Verified user with email: %s\\n\", email)\n}\n```\n\n### HTTP Server Example\n\nHere's an example of implementing a token verification server:\n\n```go\npackage main\n\nimport (\n    \"encoding/json\"\n    \"fmt\"\n    \"log\"\n    \"net/http\"\n    \"regexp\"\n    \"strings\"\n\n    \"github.com/ROU-Technology/openauth-go\"\n)\n\nvar client *openauth.Client\nvar subjects openauth.SubjectSchema\n\nfunc init() {\n    // Initialize the OpenAuth client\n    client = openauth.NewClient(\"my-client\", \"https://auth.myserver.com\")\n\n    // Define subject validation schema\n    subjects = openauth.SubjectSchema{\n        \"user\": func(props interface{}) error {\n            properties, ok := props.(map[string]interface{})\n            if !ok {\n                return fmt.Errorf(\"expected map[string]interface{}, got %T\", props)\n            }\n\n            email, ok := properties[\"email\"].(string)\n            if !ok {\n                return fmt.Errorf(\"email is required and must be a string\")\n            }\n\n            emailRegex := regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$`)\n            if !emailRegex.MatchString(email) {\n                return fmt.Errorf(\"invalid email format\")\n            }\n\n            return nil\n        },\n    }\n}\n\nfunc verifyHandler(w http.ResponseWriter, r *http.Request) {\n    if r.Method != http.MethodPost {\n        http.Error(w, \"Method not allowed\", http.StatusMethodNotAllowed)\n        return\n    }\n\n    // Get token from Authorization header\n    authHeader := r.Header.Get(\"Authorization\")\n    if !strings.HasPrefix(authHeader, \"Bearer \") {\n        http.Error(w, \"Invalid Authorization header\", http.StatusUnauthorized)\n        return\n    }\n    token := strings.TrimPrefix(authHeader, \"Bearer \")\n\n    // Get refresh token if present\n    var options *openauth.VerifyOptions\n    if refreshToken := r.Header.Get(\"X-Refresh-Token\"); refreshToken != \"\" {\n        options = \u0026openauth.VerifyOptions{\n            RefreshToken: refreshToken,\n        }\n    }\n\n    // Verify the token\n    subject, err := client.Verify(subjects, token, options)\n    if err != nil {\n        http.Error(w, err.Error(), http.StatusUnauthorized)\n        return\n    }\n\n    // Return the verified subject\n    w.Header().Set(\"Content-Type\", \"application/json\")\n    json.NewEncoder(w).Encode(subject)\n}\n\nfunc main() {\n    http.HandleFunc(\"/verify\", verifyHandler)\n    log.Fatal(http.ListenAndServe(\":8080\", nil))\n}\n```\n\n### Using the HTTP Server\n\n```bash\n# Verify a token\ncurl -X POST http://localhost:8080/verify \\\n  -H \"Authorization: Bearer your_access_token\"\n\n# Verify with refresh token\ncurl -X POST http://localhost:8080/verify \\\n  -H \"Authorization: Bearer your_access_token\" \\\n  -H \"X-Refresh-Token: your_refresh_token\"\n```\n\nExample response:\n\n```json\n{\n  \"type\": \"user\",\n  \"properties\": {\n    \"email\": \"user@example.com\"\n  },\n  \"tokens\": {\n    \"access\": \"new_access_token\",\n    \"refresh\": \"new_refresh_token\"\n  }\n}\n```\n\n- Check the examples folder for more examples and usage scenarios. [Full Example](https://github.com/ROU-Technology/openauth-go/tree/main/example)\n\n## Features in Detail\n\n### JWKS Caching\n\nThe SDK automatically caches the OpenAuth server's JWKS (JSON Web Key Set) to minimize HTTP requests. The cache is thread-safe and uses `sync.Map` for efficient concurrent access.\n\n### Issuer Metadata Caching\n\nOpenAuth server configuration is cached to reduce latency and improve performance.\n\n### Token Verification\n\nTokens are verified locally using the JWKS from your OpenAuth server, checking:\n\n- Token signature\n- Token expiration\n- Issuer claim\n- Token mode (\"access\")\n- Custom subject validation\n\n## Related Projects\n\n- [OpenAuth](https://github.com/openauthjs/openauth) - The core OpenAuth server implementation\n- [OpenAuth JS SDK](https://github.com/openauthjs/openauth) - JavaScript SDK for OpenAuth\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frou-technology%2Fopenauth-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frou-technology%2Fopenauth-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frou-technology%2Fopenauth-go/lists"}