Skip to content
/ njwt Public

JWT library for Napptive projects

License

Notifications You must be signed in to change notification settings

napptive/njwt

Repository files navigation

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:

     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:

cfg := config.JWTConfig{
   Secret: "mysecret",
   Header: "authorization",
}

var s *grpc.Server
...
s = grpc.NewServer(interceptor.WithServerJWTInterceptor(config))

Badges

Check changes in the Main branch

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.