goai_security.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package goai
  7. import (
  8. "github.com/gogf/gf/v2/internal/json"
  9. )
  10. type SecurityScheme struct {
  11. Type string `json:"type,omitempty"`
  12. Description string `json:"description,omitempty"`
  13. Name string `json:"name,omitempty"`
  14. In string `json:"in,omitempty"`
  15. Scheme string `json:"scheme,omitempty"`
  16. BearerFormat string `json:"bearerFormat,omitempty"`
  17. Flows *OAuthFlows `json:"flows,omitempty"`
  18. OpenIdConnectUrl string `json:"openIdConnectUrl,omitempty"`
  19. }
  20. type SecuritySchemes map[string]SecuritySchemeRef
  21. type SecuritySchemeRef struct {
  22. Ref string
  23. Value *SecurityScheme
  24. }
  25. type SecurityRequirements []SecurityRequirement
  26. type SecurityRequirement map[string][]string
  27. type OAuthFlows struct {
  28. Implicit *OAuthFlow `json:"implicit,omitempty"`
  29. Password *OAuthFlow `json:"password,omitempty"`
  30. ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty"`
  31. AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty"`
  32. }
  33. type OAuthFlow struct {
  34. AuthorizationURL string `json:"authorizationUrl,omitempty"`
  35. TokenURL string `json:"tokenUrl,omitempty"`
  36. RefreshURL string `json:"refreshUrl,omitempty"`
  37. Scopes map[string]string `json:"scopes"`
  38. }
  39. func (r SecuritySchemeRef) MarshalJSON() ([]byte, error) {
  40. if r.Ref != "" {
  41. return formatRefToBytes(r.Ref), nil
  42. }
  43. return json.Marshal(r.Value)
  44. }