An open API service indexing awesome lists of open source software.

https://github.com/yylego/kratos-static-auth

Static token authentication middleware with pre-configured username-token mapping
https://github.com/yylego/kratos-static-auth

authentication kratos middleware token-mapping

Last synced: about 15 hours ago
JSON representation

Static token authentication middleware with pre-configured username-token mapping

Awesome Lists containing this project

README

          

[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/yylego/kratos-static-auth/release.yml?branch=main&label=BUILD)](https://github.com/yylego/kratos-static-auth/actions/workflows/release.yml?query=branch%3Amain)
[![GoDoc](https://pkg.go.dev/badge/github.com/yylego/kratos-static-auth)](https://pkg.go.dev/github.com/yylego/kratos-static-auth)
[![Coverage Status](https://img.shields.io/coveralls/github/yylego/kratos-static-auth/main.svg)](https://coveralls.io/github/yylego/kratos-static-auth?branch=main)
[![Supported Go Versions](https://img.shields.io/badge/Go-1.25+-lightgrey.svg)](https://go.dev/)
[![GitHub Release](https://img.shields.io/github/release/yylego/kratos-static-auth.svg)](https://github.com/yylego/kratos-static-auth/releases)
[![Go Report Card](https://goreportcard.com/badge/github.com/yylego/kratos-static-auth)](https://goreportcard.com/report/github.com/yylego/kratos-static-auth)

# kratos-static-auth

Static token authentication middleware with pre-configured username-token mapping.

---

## CHINESE README

[δΈ­ζ–‡θ―΄ζ˜Ž](README.zh.md)

## Main Features

πŸ—ΊοΈ **Token Mapping**: Pre-configured username-to-token map based authentication
πŸ”‘ **Multiple Formats**: Supports simple tokens, Bearer tokens, and Base64 Basic Auth
πŸ‘€ **Username Injection**: Auto-injects authenticated username into request context
πŸ“‘ **APM Tracing**: Pluggable span hook integration via `authkratos.SpanHook`
βš™οΈ **Route Scope**: Selective authentication based on route scope configuration

## Installation

```bash
go get github.com/yylego/kratos-static-auth
```

## Usage

```go
import "github.com/yylego/kratos-static-auth/statickratosauth"

tokens := map[string]string{"admin": "secret-token-123"}
cfg := statickratosauth.NewConfig(routeScope, tokens).
WithSimpleEnable().
WithBearerEnable().
WithBase64Enable()
mw := statickratosauth.NewMiddleware(cfg, logger)
```

---

## πŸ“„ License

MIT License - see [LICENSE](LICENSE).

---

## πŸ’¬ Contact & Feedback

Contributions are welcome! Report bugs, suggest features, and contribute code:

- πŸ› **Mistake reports?** Open an issue on GitHub with reproduction steps
- πŸ’‘ **Fresh ideas?** Create an issue to discuss
- πŸ“– **Documentation confusing?** Report it so we can improve
- πŸš€ **Need new features?** Share the use cases to help us understand requirements
- ⚑ **Performance issue?** Help us optimize through reporting slow operations
- πŸ”§ **Configuration problem?** Ask questions about complex setups
- πŸ“’ **Follow project progress?** Watch the repo to get new releases and features
- 🌟 **Success stories?** Share how this package improved the workflow
- πŸ’¬ **Feedback?** We welcome suggestions and comments

---

## πŸ”§ Development

New code contributions, follow this process:

1. **Fork**: Fork the repo on GitHub (using the webpage UI).
2. **Clone**: Clone the forked project (`git clone https://github.com/yourname/repo-name.git`).
3. **Navigate**: Navigate to the cloned project (`cd repo-name`)
4. **Branch**: Create a feature branch (`git checkout -b feature/xxx`).
5. **Code**: Implement the changes with comprehensive tests
6. **Testing**: (Golang project) Ensure tests pass (`go test ./...`) and follow Go code style conventions
7. **Documentation**: Update documentation to support client-facing changes
8. **Stage**: Stage changes (`git add .`)
9. **Commit**: Commit changes (`git commit -m "Add feature xxx"`) ensuring backward compatible code
10. **Push**: Push to the branch (`git push origin feature/xxx`).
11. **PR**: Open a merge request on GitHub (on the GitHub webpage) with detailed description.

Please ensure tests pass and include relevant documentation updates.

---

## 🌟 Support

Welcome to contribute to this project via submitting merge requests and reporting issues.

**Project Support:**

- ⭐ **Give GitHub stars** if this project helps you
- 🀝 **Share with teammates** and (golang) programming friends
- πŸ“ **Write tech blogs** about development tools and workflows - we provide content writing support
- 🌟 **Join the ecosystem** - committed to supporting open source and the (golang) development scene

**Have Fun Coding with this package!** πŸŽ‰πŸŽ‰πŸŽ‰

---

## GitHub Stars

[![Stargazers](https://starchart.cc/yylego/kratos-static-auth.svg?variant=adaptive)](https://starchart.cc/yylego/kratos-static-auth)