Categorygithub.com/LdDl/grpc-jwt
modulepackage
0.4.0
Repository: https://github.com/lddl/grpc-jwt.git
Documentation: pkg.go.dev

# README

GoDoc Build Status Sourcegraph Go Report Card GitHub tag

grpc-jwt - JWT recipe for gRPC-based server

preamble: almost all code for JWT stuff was taken from appleyboy's repository

Table of Contents

Usage

If you are planning to use private/public keys, you should generate it first. There is example of generting RS512 keys below:

ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS512.key
openssl rsa -in jwtRS512.key -pubout -outform PEM -out jwtRS512.key.pub

If you want to re-build *.pb.go files

protoc -I . ./*.proto --go_out=./ --go-grpc_out=./ --go-grpc_opt=paths=source_relative --experimental_allow_proto3_optional

Server example

Whole example for server-side is here

How to run server-side:

go run .

Client example

Whole example for client-side is here

How to run client-side:

go run .

Support

If you have troubles or questions please open an issue. PRs are welcome!

Dependencies

  • github.com/golang-jwt/jwt - License is MIT
  • gRPC and protobuf for doing "'client-server'" application - grpc. License is Apache-2.0

License

You can check it here

# Packages

No description provided by the author

# Functions

ExtractClaimsFromToken help to extract the JWT claims from token.
No description provided by the author
NewJWTInterceptor Creates new instance of JWTInterceptor jwtOptions - pointer to object of type JWTgRPC methods - what methods do you want to intercept for JWT validation (optional).
No description provided by the author
No description provided by the author

# Variables

ErrEmptyAuthHeader can be thrown if authing with a HTTP header, the Auth header needs to be set.
ErrEmptyCookieToken can be thrown if authing with a cookie, the token cookie is empty.
ErrEmptyParamToken can be thrown if authing with parameter in path, the parameter in path is empty.
ErrEmptyQueryToken can be thrown if authing with URL Query, the query token variable is empty.
ErrExpiredToken indicates JWT token has expired.
ErrFailedAuthentication indicates authentication failed, could be faulty username or password.
ErrFailedTokenCreation indicates JWT Token failed to create, reason unknown.
ErrForbidden when HTTP status 403 is given.
ErrInvalidAuthHeader indicates auth header is invalid, could for example have the wrong Realm name.
ErrInvalidPrivKey indicates that the given private key is invalid.
ErrInvalidPubKey indicates the the given public key is invalid.
ErrInvalidSigningAlgorithm indicates signing algorithm is invalid, needs to be HS256, HS384, HS512, RS256, RS384 or RS512.
ErrMissingAuthenticatorFunc indicates Authenticator is required.
ErrMissingExpField missing exp field in token.
ErrMissingLoginValues indicates a user tried to authenticate without username or password.
ErrMissingSecretKey indicates Secret key is required.
ErrNoPrivKeyFile indicates that the given private key is unreadable.
ErrNoPubKeyFile indicates that the given public key is unreadable.
ErrWrongFormatOfExp field must be float64 format.

# Structs

JWTgRPC Hold jwt-engine methods.
JWTInterceptor Interceptor for JWT validation.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author