Files
paralus/components/common/pkg/gateway/annotator.go
akshay196-rafay a2f03c60da Authentication interceptor (#14)
Changes in this PR include
- Authenticate gRPC requests
- Initial file structure for authentication and authorization service
- Use Auth middleware and interceptor service in usermgmt component
- Authenticate HTTP request based on Kratos API token
- Add Auth middleware to adminsrv component
- Name the Grpc metadata fields
- Maintain session data after authentication
- Removed http middleware as it is not necessary
- Exclude rpc methods from authentication
- Handle error in auth interceptor
- Revert to with cancel context
- Log authentication failed requests and New function in authv3
- Initiate authContext struct in authv3 package using new public
- function NewAuthContext.
2022-02-23 11:18:49 +05:30

41 lines
1.1 KiB
Go

package gateway
import (
"context"
"net/http"
"google.golang.org/grpc/metadata"
)
// Rafay Gateway annotations
const (
GatewayRequest = "x-gateway-request"
GatewayURL = "x-gateway-url"
GatewaySessionCookie = "ory_kratos_session"
GatewayAPIKey = "X-Session-Token"
GatewayMethod = "x-gateway-method"
UserAgent = "x-gateway-user-agent"
Host = "x-gateway-host"
RemoteAddr = "x-gateway-remote-addr"
)
// rafayGatewayAnnotator adds rafay gateway specific annotations
var rafayGatewayAnnotator = func(ctx context.Context, r *http.Request) metadata.MD {
return metadata.New(map[string]string{
GatewayRequest: "true",
GatewayURL: r.URL.EscapedPath(),
// GatewaySessionCookie: func() string {
// sid, err := r.Cookie(GatewaySessionCookie)
// if err != nil {
// return ""
// }
// return sid.Value
// }(),
GatewayAPIKey: r.Header.Get(GatewayAPIKey),
GatewayMethod: r.Method,
// UserAgent: r.UserAgent(),
// Host: r.Host,
// RemoteAddr: r.RemoteAddr,
})
}