// GetSession returns existing non-expired session given its ID. Returns nil
// if session doesn't exist, closed or expired. Returns only transient errors.
177973
func (s *SessionStore) GetSession(c context.Context, sessionID string) (*auth.Session, error) {
	c = defaultNS(c)
	ent, err := s.fetchSession(c, sessionID)
	if ent == nil {
		return nil, err
	}
	return &auth.Session{
		SessionID: sessionID,
		UserID:    ent.Parent.StringID()[len(s.Prefix)+1:],
		User: auth.User{
			Identity:  identity.Identity(ent.Profile.Identity),
			Superuser: ent.Profile.Superuser,
			Email:     ent.Profile.Email,
			Name:      ent.Profile.Name,
			Picture:   ent.Profile.Picture,
		},
		Exp: ent.Expiration,
	}, nil
}
386646
func (s *server) GetSessions(namespace string) ([]Session, error) {
	prefix := activePrefix(namespace)

	result, err := s.bk.GetRange(context.TODO(), prefix, backend.RangeEnd(prefix), MaxSessionSliceLength)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	out := make(Sessions, 0, len(result.Items))

	for i := range result.Items {
		var session Session
		if err := json.Unmarshal(result.Items[i].Value, &session); err != nil {
			return nil, trace.Wrap(err)
		}
		out = append(out, session)
	}
	sort.Stable(out)
	return out, nil
}
270288
func (s *Session) GetInt(ctx context.Context, key string) int {
	val := s.Get(ctx, key)
	i, ok := val.(int)
	if !ok {
		return 0
	}
	return i
}
189720
func (s *Session) GetString(ctx context.Context, key string) string {
	val := s.Get(ctx, key)
	str, ok := val.(string)
	if !ok {
		return ""
	}
	return str
}
722691
func (c *Connector) GetSessionData(ctx context.Context) (*SessionData, error) {
	s := pitaya.GetSessionFromCtx(ctx)
	res := &SessionData{
		Data: s.GetData(),
	}
	return res, nil
}
150936
func GetSessionByUID(uid string) *Session {
	// TODO: Block this operation in backend servers
	if val, ok := sessionsByUID.Load(uid); ok {
		return val.(*Session)
	}
	return nil
}
755496
func (s Session) Get(key string) (newValue interface{}, err error) {
	// First check to see if it is in the session
	if v, found := s[key]; found {
		return v, nil
	}
	return s.GetInto(key, nil, false)
}
802224
func (s *Session) GetInt(key string) int {
	r, _ := s.Get(key).(int)
	return r
}
110850
func (c *Client) FindSession(ctx context.Context, key string) (*platform.Session, error) {
	op := getOp(platform.OpFindSession)
	var sess *platform.Session
	err := c.db.View(func(tx *bolt.Tx) error {
		s, err := c.findSession(ctx, tx, key)
		if err != nil {
			return err
		}

		sess = s
		return nil
	})

	if err != nil {
		return nil, &platform.Error{
			Err: err,
			Op:  op,
		}
	}

	if err := sess.Expired(); err != nil {
		// todo(leodido) > do we want to return session also if expired?
		return sess, &platform.Error{
			Err: err,
			Op:  op,
		}
	}
	return sess, nil
}
616214
func (m *Manager) Get(r *http.Request, name string) (*Session, error) {
	s := Session{
		Name:     name,
		Domain:   m.config.Domain,
		Path:     m.config.Path,
		HTTPOnly: m.config.HTTPOnly,
		MaxAge:   m.config.MaxAge,
		Secure:   m.isSecure(r),
		SameSite: m.config.SameSite,
		Rolling:  m.config.Rolling,
	}

	// get session id from cookie
	cookie, err := r.Cookie(name)
	if err == nil && len(cookie.Value) > 0 {
		var rawID string

		// verify signature
		if len(m.config.Keys) > 0 {
			parts := strings.Split(cookie.Value, ".")
			rawID = parts[0]

			if len(parts) != 2 || !verify(rawID, parts[1], m.config.Keys) {
				goto invalidSignature
			}
		} else {
			rawID = cookie.Value
		}

		hashedID := m.hashID(rawID)

		// get session data from store
		s.data, err = m.config.Store.Get(hashedID, makeStoreOption(m, &s))
		if err == nil {
			s.rawID = rawID
			s.id = hashedID
		} else if err != ErrNotFound {
			return nil, err
		}

		// DO NOT set session id to cookie value if not found in store
		// to prevent session fixation attack
	}
invalidSignature:

	if len(s.id) == 0 {
		s.rawID = m.config.GenerateID()
		s.id = m.hashID(s.rawID)
		s.isNew = true
	}

	return &s, nil
}
792761
func (d *driver) getAuthSession() (session *napping.Session, err error) {
	e := ApiError{}

	s := napping.Session{
		Userinfo: d.creds,
		Client:   d.httpClient,
	}

	url := d.url + loginUri

	resp, err := s.Get(url, nil, nil, &e)

	if err != nil {
		return
	}

	token := resp.HttpResponse().Header.Get("X-SDS-AUTH-TOKEN")

	h := http.Header{}

	h.Set("X-SDS-AUTH-TOKEN", token)

	session = &napping.Session{
		Client: d.httpClient,
		Header: &h,
	}

	return
}
614193
func (m *Module) getSessionFromRequest(req *http.Request) (*UserSession, error) {
	cookie, err := req.Cookie(m.CookieName)
	if err == http.ErrNoCookie {
		return nil, nil
	} else if err != nil {
		m.Logger.Error(errors.Wrap(err))
		return nil, nil
	}

	obj, err := jose.ParseEncrypted(cookie.Value)
	if err != nil {
		m.Logger.Error(errors.Wrap(err))
		return nil, nil
	}

	b, err := obj.Decrypt(m.decryptionKey)
	session := &UserSession{}
	if err = json.Unmarshal(b, session); err != nil {
		m.Logger.Error(errors.Wrap(err))
		return nil, nil
	}
	if m.RevocationStore.IsRevoked(session.SessionID) {
		return nil, nil
	}

	return session, nil
}
1228167
func (s *memcacheStore) Get(id string) Session {
	s.mux.RLock()
	defer s.mux.RUnlock()

	// First check our "cache"
	if sess := s.sessions[id]; sess != nil {
		return sess
	}

	// Next check in Memcache
	var err error
	var sess *sessionImpl

	for i := 0; i < s.retries; i++ {
		var sess_ sessionImpl
		_, err = s.codec.Get(s.ctx, s.keyPrefix+id, &sess_)
		if err == memcache.ErrCacheMiss {
			break // It's not in the Memcache (e.g. invalid sess id or was removed from Memcache by AppEngine)
		}
		if err == nil {
			sess = &sess_
			break
		}
		// Service error? Retry..
	}

	if sess == nil {
		if err != nil && err != memcache.ErrCacheMiss {
			log.Errorf(s.ctx, "Failed to get session from memcache, id: %s, error: %v", id, err)
		}

		// Ok, we didn't get it from Memcache (either was not there or Memcache service is unavailable).
		// Now it's time to check in the Datastore.
		key := datastore.NewKey(s.ctx, s.dsEntityName, id, 0, nil)
		for i := 0; i < s.retries; i++ {
			e := SessEntity{}
			err = datastore.Get(s.ctx, key, &e)
			if err == datastore.ErrNoSuchEntity {
				return nil // It's not in the Datastore either
			}
			if err != nil {
				// Service error? Retry..
				continue
			}
			if e.Expires.Before(time.Now()) {
				// Session expired.
				datastore.Delete(s.ctx, key) // Omitting error check...
				return nil
			}
			var sess_ sessionImpl
			if err = s.codec.Unmarshal(e.Value, &sess_); err != nil {
				break // Invalid data in stored session entity...
			}
			sess = &sess_
			break
		}
	}

	if sess == nil {
		log.Errorf(s.ctx, "Failed to get session from datastore, id: %s, error: %v", id, err)
		return nil
	}

	// Yes! We have it!
	// "Actualize" it, but first, Mutex is not marshaled, so create a new one:
	sess.mux = &sync.RWMutex{}
	sess.Access()
	s.sessions[id] = sess
	return sess
}
275705
func (m *mongoStore) Get(r *http.Request, name string) (*gSessions.Session, error) {
	return gSessions.GetRegistry(r).Get(m, name)
}
365777
func (s *server) GetSession(namespace string, id ID) (*Session, error) {
	item, err := s.bk.Get(context.TODO(), activeKey(namespace, string(id)))
	if err != nil {
		if trace.IsNotFound(err) {
			return nil, trace.NotFound("session(%v, %v) is not found", namespace, id)
		}
		return nil, trace.Wrap(err)
	}
	var sess Session
	if err := json.Unmarshal(item.Value, &sess); err != nil {
		return nil, trace.Wrap(err)
	}
	return &sess, nil
}
424456
func Get(ctx context.Context, name string) (*Session, error) {
	m, _ := ctx.Value(scopedManagerKey{}).(*scopedManager)
	if m == nil {
		return nil, ErrNotPassMiddleware
	}

	// try get session from storage first
	// to preserve session data from difference handler
	if s, ok := m.storage[name]; ok {
		return s, nil
	}

	// get session from manager
	s, err := m.Get(name)
	if err != nil {
		return nil, err
	}
	s.m = m

	// save session to storage for later get
	m.storage[name] = s
	return s, nil
}
1366720
func (_class SessionClass) GetRecord(sessionID SessionRef, self SessionRef) (_retval SessionRecord, _err error) {
	_method := "session.get_record"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertSessionRecordToGo(_method + " -> ", _result.Value)
	return
}