github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/meeting/v1/auth/requests.go (about)

     1  package auth
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  )
     6  
     7  type AuthOpts struct {
     8  	// User account (HUAWEI CLOUD meeting account).
     9  	//   Example: zhangsan@huawei
    10  	// Please apply for a business account in advance. For the specific application method, please refer to the
    11  	// development process. Account has a minimum of 1 character and a maximum of 255 characters.
    12  	Account string `json:"account" required:"true"`
    13  	// Login client type.
    14  	//   72: API call type.
    15  	ClientType int `json:"clientType" required:"true"`
    16  	// Verification code information, which is used in the verification code scenario to carry the verification code
    17  	// information returned by the server.
    18  	HA2 string `json:"HA2,omitempty"`
    19  	// Whether to generate Token, the default value is 0.
    20  	//   0: Generate token for login authentication.
    21  	//   1: do not generate token.
    22  	CreateTokenType *int `json:"createTokenType,omitempty"`
    23  }
    24  
    25  // GetToken is a method to to generate a token.
    26  func GetToken(c *golangsdk.ServiceClient, opts AuthOpts, authorization string) (*AuthResp, error) {
    27  	b, err := golangsdk.BuildRequestBody(opts, "")
    28  	if err != nil {
    29  		return nil, err
    30  	}
    31  
    32  	var r AuthResp
    33  	_, err = c.Post(rootURL(c), b, &r, &golangsdk.RequestOpts{
    34  		MoreHeaders: map[string]string{
    35  			"Content-Type":  "application/json;charset=UTF-8",
    36  			"Authorization": authorization,
    37  		},
    38  	})
    39  	return &r, err
    40  }
    41  
    42  type ValidateOpts struct {
    43  	// Verification code information, which is used in the verification code scenario to carry the verification code
    44  	// information returned by the server.
    45  	Token string `json:"token" required:"true"`
    46  	// User account (HUAWEI CLOUD meeting account).
    47  	//   Example: zhangsan@huawei
    48  	// Please apply for a business account in advance. For the specific application method, please refer to the
    49  	// development process. Account has a minimum of 1 character and a maximum of 255 characters.
    50  	NeedGenNewToken bool `json:"needGenNewToken" required:"true"`
    51  	// Login client type.
    52  	//   72: API call type.
    53  	NeedAccountInfo bool `json:"needAccountInfo,omitempty"`
    54  }
    55  
    56  // ValidateToken is a method to check whether token is available using given parameters.
    57  func ValidateToken(c *golangsdk.ServiceClient, opts ValidateOpts) (*AuthResp, error) {
    58  	b, err := golangsdk.BuildRequestBody(opts, "")
    59  	if err != nil {
    60  		return nil, err
    61  	}
    62  	var r AuthResp
    63  	_, err = c.Post(validateURL(c), b, &r, &golangsdk.RequestOpts{
    64  		MoreHeaders: map[string]string{
    65  			"Content-Type": "application/json;charset=UTF-8",
    66  		},
    67  	})
    68  	return &r, err
    69  }