@@ -25,12 +25,6 @@ type AuthResponse struct {
2525 UserName string `json:"user_name"`
2626}
2727
28- // AuthClient abstracts the external authentication call so it can be mocked in tests.
29- // Validate returns all MappingRequests built from the auth response array.
30- type AuthClient interface {
31- Validate (ctx context.Context , extension , secret , homeserverHost string ) ([]* models.MappingRequest , bool , error )
32- }
33-
3428// HTTPAuthClient is the default AuthClient implementation that calls the external HTTP endpoint.
3529type HTTPAuthClient struct {
3630 url string
@@ -61,16 +55,9 @@ type cachedAuth struct {
6155// 2. Extracts nethvoice_cti.chat claim from JWT
6256// 3. If claim exists, GET /api/chat?users to retrieve user mappings
6357// homeserverHost is used to build full Matrix IDs when the returned user_name is a localpart.
64- func (h * HTTPAuthClient ) Validate (ctx context.Context , extension , secret , homeserverHost string ) ([]* models.MappingRequest , bool , error ) {
65- // Extract user part from "user@domain" format
66- username := extension
67- if idx := strings .Index (extension , "@" ); idx > 0 {
68- username = extension [:idx ]
69- logger .Debug ().Str ("original_extension" , extension ).Str ("extracted_username" , username ).Msg ("authclient: extracted username from extension" )
70- }
71-
58+ func (h * HTTPAuthClient ) Validate (ctx context.Context , username , password , homeserverHost string ) ([]* models.MappingRequest , bool , error ) {
7259 // Check cache
73- key := extension + "|" + secret + "|" + homeserverHost
60+ key := username + "|" + password + "|" + homeserverHost
7461 logger .Debug ().Str ("key" , key ).Str ("username" , username ).Msg ("authclient: validate called" )
7562 if h .cacheTTL > 0 {
7663 h .mu .RLock ()
@@ -89,7 +76,7 @@ func (h *HTTPAuthClient) Validate(ctx context.Context, extension, secret, homese
8976 loginURL := strings .TrimRight (h .url , "/" ) + "/api/login"
9077 loginReq := models.LoginRequest {
9178 Username : username ,
92- Password : secret ,
79+ Password : password ,
9380 }
9481 body , _ := json .Marshal (loginReq )
9582 req , err := http .NewRequestWithContext (ctx , "POST" , loginURL , bytes .NewReader (body ))
0 commit comments