mirror of
https://github.com/paralus/paralus.git
synced 2026-05-09 01:46:57 +00:00
* 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
21 lines
454 B
Go
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
|
|
}
|