initial commit
This commit is contained in:
46
gen/go/service.pb.spartanauth.go
Normal file
46
gen/go/service.pb.spartanauth.go
Normal file
@ -0,0 +1,46 @@
|
||||
package pb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var publicMethodMaps = map[string]bool{
|
||||
// each method that is public will be added here
|
||||
}
|
||||
|
||||
func NewSpartanAuthClient() {
|
||||
|
||||
}
|
||||
|
||||
// Implements UnaryServerInterceptor for authentication
|
||||
func SpartanAuthPeachUnaryServerInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
|
||||
// we will have a function that checks the token and a switch statement that checks if the method is public or not
|
||||
|
||||
if ok := publicMethodMaps[info.FullMethod]; ok {
|
||||
return handler(ctx, req)
|
||||
}
|
||||
|
||||
// check the token
|
||||
// if the token is valid, return handler(ctx, req)
|
||||
// if the token is missing or invalid, return an unauthenticated error
|
||||
if token, ok := ctx.Value("token").(string); ok {
|
||||
if ok, err := IntrospectToken(ctx, token); ok {
|
||||
return handler(ctx, req)
|
||||
} else {
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "error introspecting token: %v", err)
|
||||
}
|
||||
return nil, status.Errorf(codes.Unauthenticated, "invalid token")
|
||||
}
|
||||
}
|
||||
|
||||
return nil, status.Errorf(codes.Unauthenticated, "missing or invalid token")
|
||||
}
|
||||
|
||||
func IntrospectToken(ctx context.Context, token string) (bool, error) {
|
||||
// this function will call the introspection endpoint with the token and return the result
|
||||
return false, nil
|
||||
}
|
Reference in New Issue
Block a user