https://github.com/yylego/kratos-custom-auth
Custom token authentication middleware with self-defined validation functions
https://github.com/yylego/kratos-custom-auth
authentication kratos middleware token-validation
Last synced: 1 day ago
JSON representation
Custom token authentication middleware with self-defined validation functions
- Host: GitHub
- URL: https://github.com/yylego/kratos-custom-auth
- Owner: yylego
- License: mit
- Created: 2026-03-12T12:18:53.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-06-28T06:35:33.000Z (11 days ago)
- Last Synced: 2026-06-28T08:14:14.180Z (11 days ago)
- Topics: authentication, kratos, middleware, token-validation
- Language: Go
- Size: 14.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/yylego/kratos-custom-auth/actions/workflows/release.yml?query=branch%3Amain)
[](https://pkg.go.dev/github.com/yylego/kratos-custom-auth)
[](https://coveralls.io/github/yylego/kratos-custom-auth?branch=main)
[](https://go.dev/)
[](https://github.com/yylego/kratos-custom-auth/releases)
[](https://goreportcard.com/report/github.com/yylego/kratos-custom-auth)
# kratos-custom-auth
Custom token authentication middleware with self-defined validation functions.
---
## CHINESE README
[δΈζθ―΄ζ](README.zh.md)
## Main Features
π― **Custom Validation**: Authenticate with self-defined token check functions
π **Context Injection**: Auto-inject authenticated data into request context
π‘οΈ **Route Scope Filtering**: Selective authentication based on route scope
π‘ **APM Tracing**: Pluggable span hook integration via `authkratos.SpanHook`
βοΈ **Configurable Fields**: Custom request field name and debug mode
## Installation
```bash
go get github.com/yylego/kratos-custom-auth
```
## Usage
```go
import "github.com/yylego/kratos-custom-auth/customkratosauth"
// Define custom token check function
checkFunc := func(ctx context.Context, token string) (context.Context, *errors.Error) {
// validate token and inject account info into context
return ctx, nil
}
// Create config and middleware
cfg := customkratosauth.NewConfig(routeScope, checkFunc)
mw := customkratosauth.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
[](https://starchart.cc/yylego/kratos-custom-auth)