github.com/wangyougui/gf/v2@v2.6.5/net/goai/goai_security.go (about)

     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/wangyougui/gf.
     6  
     7  package goai
     8  
     9  import (
    10  	"github.com/wangyougui/gf/v2/internal/json"
    11  )
    12  
    13  type SecurityScheme struct {
    14  	Type             string      `json:"type,omitempty"`
    15  	Description      string      `json:"description,omitempty"`
    16  	Name             string      `json:"name,omitempty"`
    17  	In               string      `json:"in,omitempty"`
    18  	Scheme           string      `json:"scheme,omitempty"`
    19  	BearerFormat     string      `json:"bearerFormat,omitempty"`
    20  	Flows            *OAuthFlows `json:"flows,omitempty"`
    21  	OpenIdConnectUrl string      `json:"openIdConnectUrl,omitempty"`
    22  }
    23  
    24  type SecuritySchemes map[string]SecuritySchemeRef
    25  
    26  type SecuritySchemeRef struct {
    27  	Ref   string
    28  	Value *SecurityScheme
    29  }
    30  
    31  type SecurityRequirements []SecurityRequirement
    32  
    33  type SecurityRequirement map[string][]string
    34  
    35  type OAuthFlows struct {
    36  	Implicit          *OAuthFlow `json:"implicit,omitempty"`
    37  	Password          *OAuthFlow `json:"password,omitempty"`
    38  	ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty"`
    39  	AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty"`
    40  }
    41  
    42  type OAuthFlow struct {
    43  	AuthorizationURL string            `json:"authorizationUrl,omitempty"`
    44  	TokenURL         string            `json:"tokenUrl,omitempty"`
    45  	RefreshURL       string            `json:"refreshUrl,omitempty"`
    46  	Scopes           map[string]string `json:"scopes"`
    47  }
    48  
    49  func (r SecuritySchemeRef) MarshalJSON() ([]byte, error) {
    50  	if r.Ref != "" {
    51  		return formatRefToBytes(r.Ref), nil
    52  	}
    53  	return json.Marshal(r.Value)
    54  }