11 Star 11 Fork 0

Gitee 极速下载/goa

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/goadesign/goa
克隆/下载
security.go 3.08 KB
一键复制 编辑 原始数据 按行查看 历史
Raphaël Simon 提交于 2016-05-24 10:52 . Simplify security setup. (#502)
package goa
import "golang.org/x/net/context"
// Location is the enum defining where the value of key based security schemes should be read:
// either a HTTP request header or a URL querystring value
type Location string
// LocHeader indicates the secret value should be loaded from the request headers.
const LocHeader Location = "header"
// LocQuery indicates the secret value should be loaded from the request URL querystring.
const LocQuery Location = "query"
// ContextRequiredScopes extracts the security scopes from the given context.
// This should be used in auth handlers to validate that the required scopes are present in the
// JWT or OAuth2 token.
func ContextRequiredScopes(ctx context.Context) []string {
if s := ctx.Value(securityScopesKey); s != nil {
return s.([]string)
}
return nil
}
// WithRequiredScopes builds a context containing the given required scopes.
func WithRequiredScopes(ctx context.Context, scopes []string) context.Context {
return context.WithValue(ctx, securityScopesKey, scopes)
}
// OAuth2Security represents the `oauth2` security scheme. It is instantiated by the generated code
// accordingly to the use of the different `*Security()` DSL functions and `Security()` in the
// design.
type OAuth2Security struct {
// Description of the security scheme
Description string
// Flow defines the OAuth2 flow type. See http://swagger.io/specification/#securitySchemeObject
Flow string
// TokenURL defines the OAuth2 tokenUrl. See http://swagger.io/specification/#securitySchemeObject
TokenURL string
// AuthorizationURL defines the OAuth2 authorizationUrl. See http://swagger.io/specification/#securitySchemeObject
AuthorizationURL string
// Scopes defines a list of scopes for the security scheme, along with their description.
Scopes map[string]string
}
// BasicAuthSecurity represents the `Basic` security scheme, which consists of a simple login/pass,
// accessible through Request.BasicAuth().
type BasicAuthSecurity struct {
// Description of the security scheme
Description string
}
// APIKeySecurity represents the `apiKey` security scheme. It handles a key that can be in the
// headers or in the query parameters, and does authentication based on that. The Name field
// represents the key of either the query string parameter or the header, depending on the In field.
type APIKeySecurity struct {
// Description of the security scheme
Description string
// In represents where to check for some data, `query` or `header`
In Location
// Name is the name of the `header` or `query` parameter to check for data.
Name string
}
// JWTSecurity represents an api key based scheme, with support for scopes and a token URL.
type JWTSecurity struct {
// Description of the security scheme
Description string
// In represents where to check for the JWT, `query` or `header`
In Location
// Name is the name of the `header` or `query` parameter to check for data.
Name string
// TokenURL defines the URL where you'd get the JWT tokens.
TokenURL string
// Scopes defines a list of scopes for the security scheme, along with their description.
Scopes map[string]string
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/goa.git
git@gitee.com:mirrors/goa.git
mirrors
goa
goa
v1.1.0

搜索帮助