mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-23 04:10:28 +00:00
NOISSUE - Fix publisher id on message published by user (#3312)
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
This commit is contained in:
+10
-10
@@ -230,7 +230,7 @@ func (h *handler) authAccess(ctx context.Context, username, password, domainID,
|
||||
clientType = policies.ClientType
|
||||
}
|
||||
|
||||
id, err := h.authenticate(ctx, clientType, token, domainID)
|
||||
id, subject, err := h.authenticate(ctx, clientType, token, domainID)
|
||||
if err != nil {
|
||||
return "", mgate.NewHTTPProxyError(http.StatusUnauthorized, errors.Wrap(svcerr.ErrAuthentication, err))
|
||||
}
|
||||
@@ -242,7 +242,7 @@ func (h *handler) authAccess(ctx context.Context, username, password, domainID,
|
||||
|
||||
ar := &grpcChannelsV1.AuthzReq{
|
||||
Type: uint32(msgType),
|
||||
ClientId: id,
|
||||
ClientId: subject,
|
||||
ClientType: clientType,
|
||||
ChannelId: chanID,
|
||||
DomainId: domainID,
|
||||
@@ -258,29 +258,29 @@ func (h *handler) authAccess(ctx context.Context, username, password, domainID,
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (h *handler) authenticate(ctx context.Context, authType, token, domainID string) (string, error) {
|
||||
func (h *handler) authenticate(ctx context.Context, authType, token, domainID string) (string, string, error) {
|
||||
switch authType {
|
||||
case policies.UserType:
|
||||
authnSession, err := h.authn.Authenticate(ctx, token)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", "", err
|
||||
}
|
||||
if authnSession.Role == smqauthn.AdminRole {
|
||||
return authnSession.UserID, nil
|
||||
return authnSession.UserID, authnSession.UserID, nil
|
||||
}
|
||||
return policies.EncodeDomainUserID(domainID, authnSession.UserID), nil
|
||||
return authnSession.UserID, policies.EncodeDomainUserID(domainID, authnSession.UserID), nil
|
||||
case policies.ClientType:
|
||||
authnRes, err := h.clients.Authenticate(ctx, &grpcClientsV1.AuthnReq{Token: token})
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", "", err
|
||||
}
|
||||
if !authnRes.Authenticated {
|
||||
return "", svcerr.ErrAuthentication
|
||||
return "", "", svcerr.ErrAuthentication
|
||||
}
|
||||
|
||||
return authnRes.GetId(), nil
|
||||
return authnRes.GetId(), authnRes.GetId(), nil
|
||||
default:
|
||||
return "", errInvalidClientType
|
||||
return "", "", errInvalidClientType
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user