go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/auth/deprecated/session.go (about)

     1  // Copyright 2015 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package deprecated
    16  
    17  import (
    18  	"context"
    19  	"time"
    20  
    21  	"go.chromium.org/luci/server/auth"
    22  )
    23  
    24  // SessionStore keeps user sessions in some permanent storage. SessionStore is
    25  // used by some authentication methods (e.g. openid.AuthMethod).
    26  type SessionStore interface {
    27  	// OpenSession create a new session for a user with given expiration time.
    28  	// It returns unique session ID.
    29  	OpenSession(ctx context.Context, userID string, u *auth.User, exp time.Time) (string, error)
    30  
    31  	// CloseSession closes a session given its ID. Does nothing if session is
    32  	// already closed or doesn't exist. Returns only transient errors.
    33  	CloseSession(ctx context.Context, sessionID string) error
    34  
    35  	// GetSession returns existing non-expired session given its ID. Returns nil
    36  	// if session doesn't exist, closed or expired. Returns only transient errors.
    37  	GetSession(ctx context.Context, sessionID string) (*Session, error)
    38  }
    39  
    40  // Session is returned by SessionStore.GetSession(...).
    41  type Session struct {
    42  	SessionID string    // same as `sessionID` passed to GetSession()
    43  	UserID    string    // authentication provider specific user id
    44  	User      auth.User // user profile, including identity string
    45  	Exp       time.Time // when the session expires
    46  }