[MM-27623] Add new session prop for oauth (#15221)
* Add new session prop for oauth * Make it isOAuthUser to differentiate better * Fix up caps * Fix tests * Add tests for IsOAuthUser
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a540dcdf9c
Коммит
101c6c7c01
@@ -461,7 +461,7 @@ type AppIface interface {
|
||||
DoEmojisPermissionsMigration()
|
||||
DoGuestRolesCreationMigration()
|
||||
DoLocalRequest(rawURL string, body []byte) (*http.Response, *model.AppError)
|
||||
DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId string, isMobile, isOAuth, isSaml bool) *model.AppError
|
||||
DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId string, isMobile, isOAuthUser, isSaml bool) *model.AppError
|
||||
DoPostAction(postId, actionId, userId, selectedOption string) (string, *model.AppError)
|
||||
DoPostActionWithCookie(postId, actionId, userId, selectedOption string, cookie *model.PostActionCookie) (string, *model.AppError)
|
||||
DoUploadFile(now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, *model.AppError)
|
||||
|
||||
@@ -111,7 +111,7 @@ func (a *App) GetUserForLogin(id, loginId string) (*model.User, *model.AppError)
|
||||
return nil, model.NewAppError("GetUserForLogin", "store.sql_user.get_for_login.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId string, isMobile, isOAuth, isSaml bool) *model.AppError {
|
||||
func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId string, isMobile, isOAuthUser, isSaml bool) *model.AppError {
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
var rejectionReason string
|
||||
pluginContext := a.PluginContext()
|
||||
@@ -125,9 +125,10 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
|
||||
}
|
||||
}
|
||||
|
||||
session := &model.Session{UserId: user.Id, Roles: user.GetRawRoles(), DeviceId: deviceId, IsOAuth: isOAuth, Props: map[string]string{
|
||||
session := &model.Session{UserId: user.Id, Roles: user.GetRawRoles(), DeviceId: deviceId, IsOAuth: false, Props: map[string]string{
|
||||
model.USER_AUTH_SERVICE_IS_MOBILE: strconv.FormatBool(isMobile),
|
||||
model.USER_AUTH_SERVICE_IS_SAML: strconv.FormatBool(isSaml),
|
||||
model.USER_AUTH_SERVICE_IS_OAUTH: strconv.FormatBool(isOAuthUser),
|
||||
}}
|
||||
session.GenerateCSRF()
|
||||
|
||||
@@ -141,7 +142,7 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
|
||||
}
|
||||
} else if isMobile {
|
||||
a.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthMobileInDays)
|
||||
} else if isOAuth || isSaml {
|
||||
} else if isOAuthUser || isSaml {
|
||||
a.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthSSOInDays)
|
||||
} else {
|
||||
a.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthWebInDays)
|
||||
|
||||
@@ -3111,7 +3111,7 @@ func (a *OpenTracingAppLayer) DoLocalRequest(rawURL string, body []byte) (*http.
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId string, isMobile bool, isOAuth bool, isSaml bool) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId string, isMobile bool, isOAuthUser bool, isSaml bool) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DoLogin")
|
||||
|
||||
@@ -3123,7 +3123,7 @@ func (a *OpenTracingAppLayer) DoLogin(w http.ResponseWriter, r *http.Request, us
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.DoLogin(w, r, user, deviceId, isMobile, isOAuth, isSaml)
|
||||
resultVar0 := a.app.DoLogin(w, r, user, deviceId, isMobile, isOAuthUser, isSaml)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
|
||||
@@ -237,8 +237,10 @@ func TestApp_GetSessionLengthInMillis(t *testing.T) {
|
||||
|
||||
t.Run("get session length SSO", func(t *testing.T) {
|
||||
session := &model.Session{
|
||||
UserId: model.NewId(),
|
||||
IsOAuth: true,
|
||||
UserId: model.NewId(),
|
||||
Props: map[string]string{
|
||||
model.USER_AUTH_SERVICE_IS_OAUTH: "true",
|
||||
},
|
||||
}
|
||||
session, err := th.App.CreateSession(session)
|
||||
require.Nil(t, err)
|
||||
|
||||
Ссылка в новой задаче
Block a user