v9.0.0
This commit is contained in:
38
pkg/cloudapi/user/authenticate.go
Normal file
38
pkg/cloudapi/user/authenticate.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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
|
||||
}
|
||||
Reference in New Issue
Block a user