multiple kratos clients for session validation and identity creation (#114)

* multiple kratos clients for session validation and identity creation

* fixed review comments

* switching few logs to debug
This commit is contained in:
Nirav Parikh
2022-04-21 11:52:20 +05:30
committed by GitHub
parent faf5e92ed6
commit a9cd4e842e
4 changed files with 22 additions and 8 deletions

View File

@@ -106,12 +106,14 @@ func (ac authContext) NewAuthUnaryInterceptor(opt Option) grpc.UnaryServerInterc
}
s := res.GetStatus()
_log.Debug("user authentication status ", s)
switch s {
case commonv3.RequestStatus_RequestAllowed:
sd := res.SessionData
sd.ClientIp = ip
sd.ClientHost = host
sd.ClientUa = ua
_log.Debug("session data ", sd)
ctx := context.WithValue(ctx, common.SessionDataKey, sd)
return handler(ctx, req)
case commonv3.RequestStatus_RequestMethodOrURLNotAllowed:

View File

@@ -84,7 +84,7 @@ func (ac *authContext) authenticate(ctx context.Context, httpreq *http.Request,
res.Reason = "no or invalid credentials"
return false, nil
} else {
return false, nil
return false, err
}
}
if session.GetActive() {

View File

@@ -466,7 +466,7 @@ func (s *userService) GetUserInfo(ctx context.Context, user *userv3.User) (*user
if s.dev {
username = user.GetMetadata().GetName()
if len(username) == 0 {
fmt.Println("Unable to fetch username. Don't use DEV mode when using from UI.")
_log.Warn("Unable to fetch username. Don't use DEV mode when using from UI.")
return &userv3.UserInfo{}, fmt.Errorf("username should be provided")
}
} else {
@@ -476,6 +476,7 @@ func (s *userService) GetUserInfo(ctx context.Context, user *userv3.User) (*user
}
username = sd.Username
}
_log.Info("username ", username)
entity, err := dao.GetByTraits(ctx, s.db, username, &models.KratosIdentities{})
if err != nil {