Files
paralus/pkg/auth/v3/session.go
akshay196-rafay 274cfe7c4f Improve Auth module (#36)
* Expose NewSessionContext function

When auth middleware or interceptor is being mocked by other service
then they can take help of `session.NewSessionContext` to store mocked
session data to request context.

* Initialize _log in auth at creating

* Allow excluding URLs in Auth middleware
2022-03-07 16:40:03 +05:30

21 lines
454 B
Go

package authv3
import (
"context"
commonv3 "github.com/RafaySystems/rcloud-base/proto/types/commonpb/v3"
)
type contextKey struct{}
var sessionDataKey contextKey
func NewSessionContext(ctx context.Context, s *commonv3.SessionData) context.Context {
return context.WithValue(ctx, sessionDataKey, s)
}
func GetSession(ctx context.Context) (*commonv3.SessionData, bool) {
s, ok := ctx.Value(sessionDataKey).(*commonv3.SessionData)
return s, ok
}