Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func SetAuthInfoHeader(r *http.Request, info *AuthInfo) error {
return errors.Wrapf(errors.InvalidArgument, "failed to generate user info: %s", err)
}
val := base64.RawURLEncoding.EncodeToString(b)
r.Header.Set(httpClientAuthContext, val)
r.Header.Set(HttpClientAuthContext, val)
return nil
}

// gets Auth Info Header available in the Http Request
func GetAuthInfoHeader(r *http.Request) (*AuthInfo, error) {
val := r.Header.Get(httpClientAuthContext)
val := r.Header.Get(HttpClientAuthContext)
if val == "" {
return nil, errors.Wrapf(errors.NotFound, "Auth info not available in the http request")
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func extractHeader(ctx context.Context, header string) (string, error) {

// Processes the headers available in context, to validate that the authentication is already performed
func ProcessAuthInfo(ctx context.Context) (context.Context, error) {
val, err := extractHeader(ctx, httpClientAuthContext)
val, err := extractHeader(ctx, GrpcClientAuthContext)
if err != nil {
return ctx, errors.Wrapf(errors.Unauthorized, "failed to extract auth info header: %s", err)
}
Expand Down Expand Up @@ -118,5 +118,5 @@ func GetAuthInfoFromContext(ctx context.Context) (*AuthInfo, error) {

// delete the Auth info header from the given HTTP request
func DeleteAuthInfoHeader(r *http.Request) {
r.Header.Del(httpClientAuthContext)
r.Header.Del(HttpClientAuthContext)
}
4 changes: 2 additions & 2 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func Test_ErrorValidations(t *testing.T) {
SessionID: "abc",
}
SetAuthInfoHeader(r, info)
fmt.Printf("Got - Encoded Auth Info: %s\n", r.Header[httpClientAuthContext][0])
if r.Header[httpClientAuthContext][0] != "eyJyZWFsbSI6InJvb3QiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJhZG1pbiIsImVtYWlsIjoiYWRtaW5AZXhhbXBsZS5jb20iLCJuYW1lIjoiVGVzdCBBZG1pbiIsInNpZCI6ImFiYyJ9" {
fmt.Printf("Got - Encoded Auth Info: %s\n", r.Header[HttpClientAuthContext][0])
if r.Header[HttpClientAuthContext][0] != "eyJyZWFsbSI6InJvb3QiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJhZG1pbiIsImVtYWlsIjoiYWRtaW5AZXhhbXBsZS5jb20iLCJuYW1lIjoiVGVzdCBBZG1pbiIsInNpZCI6ImFiYyJ9" {
t.Errorf("failed to set the auth info in the header, found invalid value in header")
}
found, err := GetAuthInfoHeader(r)
Expand Down
5 changes: 4 additions & 1 deletion auth/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ const (
// This is usually Added by Auth Gateway, if present it
// indicates that authentication is successfully performed
// by Auth Gateway.
httpClientAuthContext = "Auth-Info"
HttpClientAuthContext = "Auth-Info"

// grpc gateway will typically move the header to lowercase
GrpcClientAuthContext = "auth-info"
)