diff --git a/data.go b/data.go index 1460e1b..501b9bd 100644 --- a/data.go +++ b/data.go @@ -544,6 +544,18 @@ func (s *SessionManager) Deadline(ctx context.Context) time.Time { return sd.deadline } +// Token returns the session token. Please note that this will return the +// empty string "" if it is called before the session has been committed to +// the store. +func (s *SessionManager) Token(ctx context.Context) string { + sd := s.getSessionDataFromContext(ctx) + + sd.mu.Lock() + defer sd.mu.Unlock() + + return sd.token +} + func (s *SessionManager) addSessionDataToContext(ctx context.Context, sd *sessionData) context.Context { return context.WithValue(ctx, s.contextKey, sd) }