mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 03:46:00 +08:00
fix: login/precheck api in non-ee variant (#3516)
* fix: login/precheck api in non-ee variant * fix: add return statement * fix: make skip config empty --------- Co-authored-by: Palash Gupta <palashgdev@gmail.com> Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
This commit is contained in:
parent
96adc7f61c
commit
7209ac0007
@ -107,7 +107,7 @@ func (ah *APIHandler) registerUser(w http.ResponseWriter, r *http.Request) {
|
|||||||
RespondError(w, model.InternalError(basemodel.ErrSignupFailed{}), nil)
|
RespondError(w, model.InternalError(basemodel.ErrSignupFailed{}), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
precheckResp := &model.PrecheckResponse{
|
precheckResp := &basemodel.PrecheckResponse{
|
||||||
SSO: false,
|
SSO: false,
|
||||||
IsUser: false,
|
IsUser: false,
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ type ModelDao interface {
|
|||||||
DB() *sqlx.DB
|
DB() *sqlx.DB
|
||||||
|
|
||||||
// auth methods
|
// auth methods
|
||||||
PrecheckLogin(ctx context.Context, email, sourceUrl string) (*model.PrecheckResponse, basemodel.BaseApiError)
|
|
||||||
CanUsePassword(ctx context.Context, email string) (bool, basemodel.BaseApiError)
|
CanUsePassword(ctx context.Context, email string) (bool, basemodel.BaseApiError)
|
||||||
PrepareSsoRedirect(ctx context.Context, redirectUri, email string) (redirectURL string, apierr basemodel.BaseApiError)
|
PrepareSsoRedirect(ctx context.Context, redirectUri, email string) (redirectURL string, apierr basemodel.BaseApiError)
|
||||||
GetDomainFromSsoResponse(ctx context.Context, relayState *url.URL) (*model.OrgDomain, error)
|
GetDomainFromSsoResponse(ctx context.Context, relayState *url.URL) (*model.OrgDomain, error)
|
||||||
|
@ -120,10 +120,10 @@ func (m *modelDao) CanUsePassword(ctx context.Context, email string) (bool, base
|
|||||||
|
|
||||||
// PrecheckLogin is called when the login or signup page is loaded
|
// PrecheckLogin is called when the login or signup page is loaded
|
||||||
// to check sso login is to be prompted
|
// to check sso login is to be prompted
|
||||||
func (m *modelDao) PrecheckLogin(ctx context.Context, email, sourceUrl string) (*model.PrecheckResponse, basemodel.BaseApiError) {
|
func (m *modelDao) PrecheckLogin(ctx context.Context, email, sourceUrl string) (*basemodel.PrecheckResponse, basemodel.BaseApiError) {
|
||||||
|
|
||||||
// assume user is valid unless proven otherwise
|
// assume user is valid unless proven otherwise
|
||||||
resp := &model.PrecheckResponse{IsUser: true, CanSelfRegister: false}
|
resp := &basemodel.PrecheckResponse{IsUser: true, CanSelfRegister: false}
|
||||||
|
|
||||||
// check if email is a valid user
|
// check if email is a valid user
|
||||||
userPayload, baseApiErr := m.GetUserByEmail(ctx, email)
|
userPayload, baseApiErr := m.GetUserByEmail(ctx, email)
|
||||||
|
@ -4,18 +4,9 @@ import (
|
|||||||
basemodel "go.signoz.io/signoz/pkg/query-service/model"
|
basemodel "go.signoz.io/signoz/pkg/query-service/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PrecheckResponse contains login precheck response
|
|
||||||
type PrecheckResponse struct {
|
|
||||||
SSO bool `json:"sso"`
|
|
||||||
SsoUrl string `json:"ssoUrl"`
|
|
||||||
CanSelfRegister bool `json:"canSelfRegister"`
|
|
||||||
IsUser bool `json:"isUser"`
|
|
||||||
SsoError string `json:"ssoError"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GettableInvitation overrides base object and adds precheck into
|
// GettableInvitation overrides base object and adds precheck into
|
||||||
// response
|
// response
|
||||||
type GettableInvitation struct {
|
type GettableInvitation struct {
|
||||||
*basemodel.InvitationResponseObject
|
*basemodel.InvitationResponseObject
|
||||||
Precheck *PrecheckResponse `json:"precheck"`
|
Precheck *basemodel.PrecheckResponse `json:"precheck"`
|
||||||
}
|
}
|
||||||
|
@ -387,6 +387,7 @@ func (aH *APIHandler) RegisterRoutes(router *mux.Router, am *AuthMiddleware) {
|
|||||||
|
|
||||||
router.HandleFunc("/api/v1/register", am.OpenAccess(aH.registerUser)).Methods(http.MethodPost)
|
router.HandleFunc("/api/v1/register", am.OpenAccess(aH.registerUser)).Methods(http.MethodPost)
|
||||||
router.HandleFunc("/api/v1/login", am.OpenAccess(aH.loginUser)).Methods(http.MethodPost)
|
router.HandleFunc("/api/v1/login", am.OpenAccess(aH.loginUser)).Methods(http.MethodPost)
|
||||||
|
router.HandleFunc("/api/v1/loginPrecheck", am.OpenAccess(aH.precheckLogin)).Methods(http.MethodGet)
|
||||||
|
|
||||||
router.HandleFunc("/api/v1/user", am.AdminAccess(aH.listUsers)).Methods(http.MethodGet)
|
router.HandleFunc("/api/v1/user", am.AdminAccess(aH.listUsers)).Methods(http.MethodGet)
|
||||||
router.HandleFunc("/api/v1/user/{id}", am.SelfAccess(aH.getUser)).Methods(http.MethodGet)
|
router.HandleFunc("/api/v1/user/{id}", am.SelfAccess(aH.getUser)).Methods(http.MethodGet)
|
||||||
@ -1863,6 +1864,20 @@ func (aH *APIHandler) registerUser(w http.ResponseWriter, r *http.Request) {
|
|||||||
aH.Respond(w, nil)
|
aH.Respond(w, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (aH *APIHandler) precheckLogin(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
email := r.URL.Query().Get("email")
|
||||||
|
sourceUrl := r.URL.Query().Get("ref")
|
||||||
|
|
||||||
|
resp, apierr := aH.appDao.PrecheckLogin(context.Background(), email, sourceUrl)
|
||||||
|
if apierr != nil {
|
||||||
|
RespondError(w, apierr, resp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
aH.Respond(w, resp)
|
||||||
|
}
|
||||||
|
|
||||||
func (aH *APIHandler) loginUser(w http.ResponseWriter, r *http.Request) {
|
func (aH *APIHandler) loginUser(w http.ResponseWriter, r *http.Request) {
|
||||||
req, err := parseLoginRequest(r)
|
req, err := parseLoginRequest(r)
|
||||||
if aH.HandleError(w, err, http.StatusBadRequest) {
|
if aH.HandleError(w, err, http.StatusBadRequest) {
|
||||||
|
@ -119,7 +119,7 @@ func NewServer(serverOptions *ServerOptions) (*Server, error) {
|
|||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("Storage type: %s is not supported in query service", storage)
|
return nil, fmt.Errorf("Storage type: %s is not supported in query service", storage)
|
||||||
}
|
}
|
||||||
var skipConfig *model.SkipConfig
|
skipConfig := &model.SkipConfig{}
|
||||||
if serverOptions.SkipTopLvlOpsPath != "" {
|
if serverOptions.SkipTopLvlOpsPath != "" {
|
||||||
// read skip config
|
// read skip config
|
||||||
skipConfig, err = model.ReadSkipConfig(serverOptions.SkipTopLvlOpsPath)
|
skipConfig, err = model.ReadSkipConfig(serverOptions.SkipTopLvlOpsPath)
|
||||||
|
@ -34,6 +34,8 @@ type Queries interface {
|
|||||||
GetUsersByGroup(ctx context.Context, groupId string) ([]model.UserPayload, *model.ApiError)
|
GetUsersByGroup(ctx context.Context, groupId string) ([]model.UserPayload, *model.ApiError)
|
||||||
|
|
||||||
GetApdexSettings(ctx context.Context, services []string) ([]model.ApdexSettings, *model.ApiError)
|
GetApdexSettings(ctx context.Context, services []string) ([]model.ApdexSettings, *model.ApiError)
|
||||||
|
|
||||||
|
PrecheckLogin(ctx context.Context, email, sourceUrl string) (*model.PrecheckResponse, model.BaseApiError)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mutations interface {
|
type Mutations interface {
|
||||||
|
@ -597,3 +597,20 @@ func (mds *ModelDaoSqlite) UpdateUserFlags(ctx context.Context, userId string, f
|
|||||||
|
|
||||||
return flags, nil
|
return flags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mds *ModelDaoSqlite) PrecheckLogin(ctx context.Context, email, sourceUrl string) (*model.PrecheckResponse, model.BaseApiError) {
|
||||||
|
// assume user is valid unless proven otherwise and assign default values for rest of the fields
|
||||||
|
resp := &model.PrecheckResponse{IsUser: true, CanSelfRegister: false, SSO: false, SsoUrl: "", SsoError: ""}
|
||||||
|
|
||||||
|
// check if email is a valid user
|
||||||
|
userPayload, baseApiErr := mds.GetUserByEmail(ctx, email)
|
||||||
|
if baseApiErr != nil {
|
||||||
|
return resp, baseApiErr
|
||||||
|
}
|
||||||
|
|
||||||
|
if userPayload == nil {
|
||||||
|
resp.IsUser = false
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
@ -32,6 +32,15 @@ type LoginRequest struct {
|
|||||||
RefreshToken string `json:"refreshToken"`
|
RefreshToken string `json:"refreshToken"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PrecheckResponse contains login precheck response
|
||||||
|
type PrecheckResponse struct {
|
||||||
|
SSO bool `json:"sso"`
|
||||||
|
SsoUrl string `json:"ssoUrl"`
|
||||||
|
CanSelfRegister bool `json:"canSelfRegister"`
|
||||||
|
IsUser bool `json:"isUser"`
|
||||||
|
SsoError string `json:"ssoError"`
|
||||||
|
}
|
||||||
|
|
||||||
type UserJwtObject struct {
|
type UserJwtObject struct {
|
||||||
AccessJwt string `json:"accessJwt"`
|
AccessJwt string `json:"accessJwt"`
|
||||||
AccessJwtExpiry int64 `json:"accessJwtExpiry"`
|
AccessJwtExpiry int64 `json:"accessJwtExpiry"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user