23
vendor/github.com/go-openapi/runtime/security/authenticator.go
generated
vendored
23
vendor/github.com/go-openapi/runtime/security/authenticator.go
generated
vendored
@@ -20,6 +20,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
)
|
||||
|
||||
@@ -75,6 +76,7 @@ type secCtxKey uint8
|
||||
|
||||
const (
|
||||
failedBasicAuth secCtxKey = iota
|
||||
oauth2SchemeName
|
||||
)
|
||||
|
||||
func FailedBasicAuth(r *http.Request) string {
|
||||
@@ -89,12 +91,24 @@ func FailedBasicAuthCtx(ctx context.Context) string {
|
||||
return v
|
||||
}
|
||||
|
||||
func OAuth2SchemeName(r *http.Request) string {
|
||||
return OAuth2SchemeNameCtx(r.Context())
|
||||
}
|
||||
|
||||
func OAuth2SchemeNameCtx(ctx context.Context) string {
|
||||
v, ok := ctx.Value(oauth2SchemeName).(string)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// BasicAuth creates a basic auth authenticator with the provided authentication function
|
||||
func BasicAuth(authenticate UserPassAuthentication) runtime.Authenticator {
|
||||
return BasicAuthRealm(DefaultRealmName, authenticate)
|
||||
}
|
||||
|
||||
// BasicAuthBasicAuthRealm creates a basic auth authenticator with the provided authentication function and realm name
|
||||
// BasicAuthRealm creates a basic auth authenticator with the provided authentication function and realm name
|
||||
func BasicAuthRealm(realm string, authenticate UserPassAuthentication) runtime.Authenticator {
|
||||
if realm == "" {
|
||||
realm = DefaultRealmName
|
||||
@@ -118,7 +132,7 @@ func BasicAuthCtx(authenticate UserPassAuthenticationCtx) runtime.Authenticator
|
||||
return BasicAuthRealmCtx(DefaultRealmName, authenticate)
|
||||
}
|
||||
|
||||
// BasicAuthCtx creates a basic auth authenticator with the provided authentication function and realm name with support for context.Context
|
||||
// BasicAuthRealmCtx creates a basic auth authenticator with the provided authentication function and realm name with support for context.Context
|
||||
func BasicAuthRealmCtx(realm string, authenticate UserPassAuthenticationCtx) runtime.Authenticator {
|
||||
if realm == "" {
|
||||
realm = DefaultRealmName
|
||||
@@ -224,6 +238,8 @@ func BearerAuth(name string, authenticate ScopedTokenAuthentication) runtime.Aut
|
||||
return false, nil, nil
|
||||
}
|
||||
|
||||
rctx := context.WithValue(r.Request.Context(), oauth2SchemeName, name)
|
||||
*r.Request = *r.Request.WithContext(rctx)
|
||||
p, err := authenticate(token, r.RequiredScopes)
|
||||
return true, p, err
|
||||
})
|
||||
@@ -252,7 +268,8 @@ func BearerAuthCtx(name string, authenticate ScopedTokenAuthenticationCtx) runti
|
||||
return false, nil, nil
|
||||
}
|
||||
|
||||
ctx, p, err := authenticate(r.Request.Context(), token, r.RequiredScopes)
|
||||
rctx := context.WithValue(r.Request.Context(), oauth2SchemeName, name)
|
||||
ctx, p, err := authenticate(rctx, token, r.RequiredScopes)
|
||||
*r.Request = *r.Request.WithContext(ctx)
|
||||
return true, p, err
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user