input.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package mcclient
  15. const (
  16. AuthSourceWeb = "web"
  17. AuthSourceAPI = "api"
  18. AuthSourceCli = "cli"
  19. AuthSourceSrv = "srv"
  20. AuthSourceOperator = "operator"
  21. )
  22. type SAuthContext struct {
  23. // 认证来源类型, 可能的值有:
  24. //
  25. // | source | 说明 |
  26. // |----------|---------------------------|
  27. // | web | 通过web控制台认证 |
  28. // | api | api调用认证 |
  29. // | cli | climc客户端认证 |
  30. // | srv | 作为服务认证 |
  31. // | operator | 作为onecloud-operator认证 |
  32. //
  33. Source string `json:"source,omitempty"`
  34. // 认证来源IP
  35. Ip string `json:"ip,omitempty"`
  36. }
  37. type SAuthenticationInputV2 struct {
  38. // keystone v2 认证接口认证信息
  39. // required:true
  40. Auth struct {
  41. // 如果使用用户名/密码认证,则需要设置passwordCredentials
  42. PasswordCredentials struct {
  43. // 用户名
  44. Username string `json:"username,omitempty"`
  45. // 用户密码
  46. Password string `json:"password,omitempty"`
  47. } `json:"passwordCredentials,omitempty"`
  48. // 指定认证用户的所属项目名称,该字段和tenantId二选一,或者不设置。
  49. // 如果不提供tenantName和tenantId,则用户认证成功后,获得一个unscoped token
  50. // 此时,如果用户需要访问具体项目的资源,还是需要用unscoped token进行认证,获得指定项目的token
  51. // required:false
  52. TenantName string `json:"tenantName,omitempty"`
  53. // 指定认证用户的所属项目ID,该字段和tenantName二选一,或者不设置。
  54. // required:false
  55. TenantId string `json:"tenantId,omitempty"`
  56. // 如果使用token认证,则需要设置token.Id
  57. Token struct {
  58. // token的字符串
  59. Id string `json:"id,omitempty"`
  60. } `json:"token,omitempty"`
  61. // 认证上下文
  62. // required:false
  63. Context SAuthContext `json:"context,omitempty"`
  64. } `json:"auth,omitempty"`
  65. }
  66. type SAuthenticationIdentity struct {
  67. // ID of identity provider, optional
  68. // required:false
  69. Id string `json:"id,omitempty"`
  70. // 认证方式列表,支持认证方式如下:
  71. //
  72. // | method | 说明 |
  73. // |----------|--------------------------------------------------------------------|
  74. // | password | 用户名密码认证 |
  75. // | token | token认证,已经通过其他方式获得token之后,可以用旧的token认证获得新的token |
  76. // | aksk | Access Key/Secret key认证 |
  77. // | cas | 通过SSO统一认证平台CAS认证 |
  78. // | saml | 作为SAML 2.0 SP通过IDP认证 |
  79. // | oidc | 作为OpenID Connect/OAuth2 Client认证 |
  80. // | oauth2 | OAuth2认证 |
  81. // | verify | 手机短信或邮箱认证 |
  82. //
  83. Methods []string `json:"methods,omitempty"`
  84. // 当认证方式为password时,通过该字段提供密码认证信息
  85. Password struct {
  86. User struct {
  87. // 用户ID
  88. Id string `json:"id,omitempty"`
  89. // 用户名称
  90. Name string `json:"name,omitempty"`
  91. // 密码
  92. Password string `json:"password,omitempty"`
  93. // 用户所属域的信息
  94. Domain struct {
  95. // 域ID
  96. Id string `json:"id,omitempty"`
  97. // 域名称
  98. Name string `json:"name,omitempty"`
  99. }
  100. } `json:"user,omitempty"`
  101. } `json:"password,omitempty"`
  102. // 当认证方式为token时,通过该字段提供token认证信息
  103. Token struct {
  104. // token
  105. Id string `json:"id,omitempty"`
  106. } `json:"token,omitempty"`
  107. // 当认证方式为aksk时,通过该字段提供客户端AK/SK信息
  108. // 为了兼容不同版本的AK/SK认证方式,使用编码后的字符串传递该信息
  109. AccessKeyRequest string `json:"access_key_secret,omitempty"`
  110. // 当认证方式为cas时,通过该字段提供CAS认证的ID
  111. // required:false
  112. CASTicket struct {
  113. Id string `json:"id,omitempty"`
  114. Service string `json:"service,omitempty"`
  115. } `json:"cas_ticket,omitempty"`
  116. // 当认证方式为saml时,通过该字段提供SAML认证的Response信息
  117. SAMLAuth struct {
  118. Response string `json:"response,omitempty"`
  119. } `json:"saml_auth,omitempty"`
  120. OIDCAuth struct {
  121. Code string `json:"code,omitempty"`
  122. RedirectUri string `json:"redirect_uri,omitempty"`
  123. } `json:"oidc_auth,omitempty"`
  124. OAuth2 struct {
  125. Code string `json:"code,omitempty"`
  126. } `json:"oauth2,omitempty"`
  127. Verify struct {
  128. Uid string `json:"uid,omitempty"`
  129. VerifyCode string `json:"verify_code,omitempty"`
  130. ContactType string `json:"contact_type,omitempty"`
  131. } `json:"mobile,omitempty"`
  132. // 当认证方式为assume时,通过该字段提供目标用户信息
  133. Assume struct {
  134. User struct {
  135. // 用户ID
  136. Id string `json:"id,omitempty"`
  137. // 用户名称
  138. Name string `json:"name,omitempty"`
  139. // 用户所属域的信息
  140. Domain struct {
  141. // 域ID
  142. Id string `json:"id,omitempty"`
  143. // 域名称
  144. Name string `json:"name,omitempty"`
  145. } `json:"domain,omitempty"`
  146. } `json:"user,omitempty"`
  147. } `json:"assume,omitempty"`
  148. }
  149. type SAuthenticationInputV3 struct {
  150. // keystone v3 认证接口认证信息
  151. // required:true
  152. Auth struct {
  153. // 认证信息
  154. // required:true
  155. Identity SAuthenticationIdentity `json:"identity,omitempty"`
  156. // 指定认证范围, 该字段可选。如果未指定scope,则用户认证成功后获得一个unscoped token,
  157. // 当用户需要访问指定项目的资源时,需要通过该unscope token进行认证,获得该项目scope的token
  158. // 目前只支持Project scope的token
  159. // required:false
  160. Scope struct {
  161. // 指定token的scope为指定的项目
  162. // required:false
  163. Project struct {
  164. // 指定项目的ID,由于ID全局唯一,因此指定ID后不需要指定项目所在的域(Domain),ID和Name只需要指定其中一个
  165. // required:false
  166. Id string `json:"id,omitempty"`
  167. // 指定项目的Name,指定Name时,需要指定项目所在的域(domain)
  168. // required:false
  169. Name string `json:"name,omitempty"`
  170. // 指定项目所在的域(domain)
  171. // required:false
  172. Domain struct {
  173. // 指定项目所在域的ID,ID和Name只需要指定其中一个
  174. // required:false
  175. Id string `json:"id,omitempty"`
  176. // 指定项目所在域的Name
  177. // required:false
  178. Name string `json:"name,omitempty"`
  179. } `json:"domain,omitempty"`
  180. } `json:"project,omitempty"`
  181. // 指定token的scope为指定的域
  182. // required:false
  183. Domain struct {
  184. // 指定domain的ID,ID和Name只需要指定其中一个
  185. // required:false
  186. Id string `json:"id,omitempty"`
  187. // 指定Domain的Name
  188. // required:false
  189. Name string `json:"name,omitempty"`
  190. } `json:"domain,omitempty"`
  191. } `json:"scope,omitempty"`
  192. // 认证上下文
  193. // required:false
  194. Context SAuthContext `json:"context,omitempty"`
  195. } `json:"auth,omitempty"`
  196. }