mirror of
https://github.com/fleetdm/fleet
synced 2026-05-06 06:48:54 +00:00
For #27281 This PR adds `/api/{version}/fleet/scim/details` endpoint, along with some frontend fixes. # Checklist for submitter - [x] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [x] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [x] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [x] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [x] Added/updated automated tests - [x] A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it) - [x] Manual QA for all new/changed functionality
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/service/contract"
|
|
)
|
|
|
|
// Login attempts to login to the current Fleet instance. If login is successful,
|
|
// an auth token is returned.
|
|
func (c *Client) Login(email, password string) (string, error) {
|
|
params := contract.LoginRequest{
|
|
Email: email,
|
|
Password: password,
|
|
}
|
|
|
|
response, err := c.Do("POST", "/api/latest/fleet/login", "", params)
|
|
if err != nil {
|
|
return "", fmt.Errorf("POST /api/latest/fleet/login: %w", err)
|
|
}
|
|
defer response.Body.Close()
|
|
|
|
if response.StatusCode == http.StatusNotFound {
|
|
return "", notSetupErr{}
|
|
}
|
|
if response.StatusCode != http.StatusOK {
|
|
return "", fmt.Errorf(
|
|
"login received status %d %s",
|
|
response.StatusCode,
|
|
extractServerErrorText(response.Body),
|
|
)
|
|
}
|
|
|
|
var responseBody loginResponse
|
|
err = json.NewDecoder(response.Body).Decode(&responseBody)
|
|
if err != nil {
|
|
return "", fmt.Errorf("decode login response: %w", err)
|
|
}
|
|
|
|
if responseBody.Err != nil {
|
|
return "", fmt.Errorf("login: %s", responseBody.Err)
|
|
}
|
|
|
|
return responseBody.Token, nil
|
|
}
|
|
|
|
// Logout attempts to logout to the current Fleet instance.
|
|
func (c *Client) Logout() error {
|
|
verb, path := "POST", "/api/latest/fleet/logout"
|
|
var responseBody logoutResponse
|
|
return c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
}
|