You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
decort-golang-sdk/pkg/cloudapi/user/authenticate.go

39 lines
1.0 KiB

package user
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AuthenticateRequest struct to authenticate user.
type AuthenticateRequest struct {
// Username
// Required: true
Username string `url:"username" json:"username" validate:"required"`
// Password
// Required: true
Password string `url:"password" json:"password" validate:"required"`
}
// Authenticate evaluates the provided username and password and returns a session key.
// The session key can be used for doing api requests. E.g this is the authkey parameter in every actor request.
// A session key is only vallid for a limited time.
func (u User) Authenticate(ctx context.Context, req AuthenticateRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/user/authenticate"
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}