11package rbac
22
33const (
4- requestAuthTokenURI = "/rbac-api/v1/auth/token" // #nosec - this is the uri to get RBAC tokens
4+ requestAuthTokenURI = "/rbac-api/v1/auth/token" // #nosec - this is the uri to g et RBAC tokens
5+ tokenAuthenticateURI = "/rbac-api/v2/auth/token/authenticate" // #nosec - this is the uri to authenticate RBAC tokens
56)
67
78// GetRBACToken returns an auth token given user/password information
@@ -23,6 +24,27 @@ func (c *Client) GetRBACToken(authRequest *RequestKeys) (*Token, error) {
2324 return & payload , nil
2425}
2526
27+ // AuthenticateRBACToken returns a response with the token details or errors otherwise.
28+ func (c * Client ) AuthenticateRBACToken (token string ) (* AuthenticateResponse , error ) {
29+ authenticateRequest := & AuthenticateRequest {Token : token }
30+
31+ payload := AuthenticateResponse {}
32+ r , err := c .resty .R ().
33+ SetResult (& payload ).
34+ SetBody (authenticateRequest ).
35+ Post (tokenAuthenticateURI )
36+ if err != nil {
37+ return nil , FormatError (r , err .Error ())
38+ }
39+ if r .IsError () {
40+ if r .Error () != nil {
41+ return nil , FormatError (r )
42+ }
43+ return nil , FormatError (r )
44+ }
45+ return & payload , nil
46+ }
47+
2648// Token is the returned auth token
2749type Token struct {
2850 Token string `json:"token"`
@@ -37,3 +59,18 @@ type RequestKeys struct {
3759 Client string `json:"client,omitempty"`
3860 Label string `json:"label,omitempty"`
3961}
62+
63+ // AuthenticateRequest will hold the request needed for an authenticate.
64+ type AuthenticateRequest struct {
65+ Token string `json:"token"`
66+ UpdateLastActivity bool `json:"update_last_activity?"`
67+ }
68+
69+ // AuthenticateResponse will hold the response from an authenticate.
70+ type AuthenticateResponse struct {
71+ Description string `json:"description"`
72+ Login string `json:"login"`
73+ RoleIDs []int `json:"role_ids"`
74+ UserID string `json:"user_id"`
75+ DisplayName string `json:"display_name"`
76+ }
0 commit comments