https://github.com/napptive/njwt
JWT library for Napptive projects
https://github.com/napptive/njwt
grpc-interceptor interceptors jwt jwt-authentication jwt-middleware library
Last synced: 6 months ago
JSON representation
JWT library for Napptive projects
- Host: GitHub
- URL: https://github.com/napptive/njwt
- Owner: napptive
- License: apache-2.0
- Created: 2020-12-11T19:16:20.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-01-19T10:59:58.000Z (over 2 years ago)
- Last Synced: 2024-01-19T12:10:46.112Z (over 2 years ago)
- Topics: grpc-interceptor, interceptors, jwt, jwt-authentication, jwt-middleware, library
- Language: Go
- Homepage:
- Size: 245 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: contributing.md
- License: LICENSE
- Code of conduct: code-of-conduct.md
Awesome Lists containing this project
README
# NJWT
JWT library for the Napptive projects
The purpose of this project is to provide a simple JWT library to handle the authentication tokens of the Napptive platform.
## Usage
To create new tokens:
```go
pc := NewAuthxClaim("userID", "username")
claim := NewClaim("tt", time.Hour, pc)
secret := "secret"
token, err := tokenMgr.Generate(claim, secret)
recoveredClaim, err := tokenMgr.Recover(*token, secret, &AuthxClaim{})
recoveredPC, ok := recClaim.PersonalClaim.(*AuthxClaim)
```
#### JWT Interceptor
To create an interceptor that validates incoming gRPC calls with a JWT on an authorization header in the context:
```go
cfg := config.JWTConfig{
Secret: "mysecret",
Header: "authorization",
}
var s *grpc.Server
...
s = grpc.NewServer(interceptor.WithServerJWTInterceptor(config))
```
## Badges

## License
Copyright 2023 Napptive
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.