Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v13] Refactor NewWebSessionRequest into lib/auth #40002

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/types/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ func (r *NewWebSessionRequest) CheckAndSetDefaults() error {

// NewWebSessionRequest defines a request to create a new user
// web session
// TODO (Joerger): Remove this and replace it with lib/auth.NewWebSessionRequest
// once /e is no longer dependent on this.
type NewWebSessionRequest struct {
// User specifies the user this session is bound to
User string
Expand Down
6 changes: 3 additions & 3 deletions lib/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3417,7 +3417,7 @@ func (a *Server) ExtendWebSession(ctx context.Context, req WebSessionReq, identi
}

sessionTTL := utils.ToTTL(a.clock, expiresAt)
sess, err := a.NewWebSession(ctx, types.NewWebSessionRequest{
sess, err := a.NewWebSession(ctx, NewWebSessionRequest{
User: req.User,
LoginIP: identity.LoginIP,
Roles: roles,
Expand Down Expand Up @@ -3509,7 +3509,7 @@ func (a *Server) CreateWebSession(ctx context.Context, user string) (types.WebSe
if err != nil {
return nil, trace.Wrap(err)
}
session, err := a.CreateWebSessionFromReq(ctx, types.NewWebSessionRequest{
session, err := a.CreateWebSessionFromReq(ctx, NewWebSessionRequest{
User: user,
Roles: u.GetRoles(),
Traits: u.GetTraits(),
Expand Down Expand Up @@ -4071,7 +4071,7 @@ func (a *Server) GetTokens(ctx context.Context, opts ...services.MarshalOption)
}

// NewWebSession creates and returns a new web session for the specified request
func (a *Server) NewWebSession(ctx context.Context, req types.NewWebSessionRequest) (types.WebSession, error) {
func (a *Server) NewWebSession(ctx context.Context, req NewWebSessionRequest) (types.WebSession, error) {
userState, err := a.GetUserOrLoginState(ctx, req.User)
if err != nil {
return nil, trace.Wrap(err)
Expand Down
2 changes: 1 addition & 1 deletion lib/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2257,7 +2257,7 @@ func TestNewWebSession(t *testing.T) {
require.NoError(t, err)

// Create a new web session.
req := types.NewWebSessionRequest{
req := NewWebSessionRequest{
User: user.GetName(),
Roles: user.GetRoles(),
Traits: user.GetTraits(),
Expand Down
2 changes: 1 addition & 1 deletion lib/auth/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ func (a *Server) validateGithubAuthCallback(ctx context.Context, diagCtx *SSODia

// If the request is coming from a browser, create a web session.
if req.CreateWebSession {
session, err := a.CreateWebSessionFromReq(ctx, types.NewWebSessionRequest{
session, err := a.CreateWebSessionFromReq(ctx, NewWebSessionRequest{
User: userState.GetName(),
Roles: userState.GetRoles(),
Traits: userState.GetTraits(),
Expand Down
2 changes: 1 addition & 1 deletion lib/auth/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ func (a *Server) emitNoLocalAuthEvent(username string) {
func (a *Server) createUserWebSession(ctx context.Context, user services.UserState, loginIP string) (types.WebSession, error) {
// It's safe to extract the roles and traits directly from services.User as this method
// is only used for local accounts.
return a.CreateWebSessionFromReq(ctx, types.NewWebSessionRequest{
return a.CreateWebSessionFromReq(ctx, NewWebSessionRequest{
User: user.GetName(),
LoginIP: loginIP,
Roles: user.GetRoles(),
Expand Down
6 changes: 5 additions & 1 deletion lib/auth/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ import (
"github.com/gravitational/teleport/lib/utils"
)

// TODO (Joerger): Replace this alias with the definition of types.NewWebSessionRequest
// once /e is no longer dependent on types.NewWebSessionRequest.
type NewWebSessionRequest = types.NewWebSessionRequest

// CreateAppSession creates and inserts a services.WebSession into the
// backend with the identity of the caller used to generate the certificate.
// The certificate is used for all access requests, which is where access
Expand Down Expand Up @@ -249,7 +253,7 @@ func (a *Server) generateAppToken(ctx context.Context, username string, roles []
return token, nil
}

func (a *Server) CreateWebSessionFromReq(ctx context.Context, req types.NewWebSessionRequest) (types.WebSession, error) {
func (a *Server) CreateWebSessionFromReq(ctx context.Context, req NewWebSessionRequest) (types.WebSession, error) {
session, err := a.NewWebSession(ctx, req)
if err != nil {
return nil, trace.Wrap(err)
Expand Down
Loading