Created
June 5, 2021 09:29
-
-
Save vladfr/4c4053f0ed32cfdfc0bc742e555fad94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (a *IDPConfig) AuthUnaryInterceptor(authFunc AuthFunc) grpc.UnaryServerInterceptor { | |
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { | |
meta, ok := metadata.FromIncomingContext(ctx) | |
// [...] | |
token, err := a.validateToken(ctx, rawToken) | |
if err != nil { | |
return nil, status.Errorf(codes.Unauthenticated, "invalid auth token: %v", err) | |
} | |
// put stuff in the ctx for use in the override methods | |
userMeta, err := NewUserAccessMetadataFromToken(token) | |
if err != nil { | |
return nil, err | |
} | |
// call the given authFunc, or overrides, if the server implements ServiceAuthFuncOverride | |
newCtx := NewContext(ctx, userMeta) | |
var errF error | |
if overrideSrv, ok := info.Server.(ServiceAuthFuncOverride); ok { | |
// THIS IS WHERE I FAIL: | |
authFunc = overrideSrv.AuthFuncOverride(newCtx, info.FullMethod) | |
} | |
if authFunc != nil { | |
newCtx, errF = authFunc(newCtx) | |
} | |
if errF != nil { | |
return nil, errF | |
} | |
return handler(newCtx, req) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment