1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-27 14:57:05 +00:00

Simplify the basicauth middleware

Former-commit-id: 8d184a434c992a884c5565bc22767ef295a1575a
This commit is contained in:
kataras
2017-06-10 15:28:09 +03:00
parent 6ab00aa02f
commit 5fa9789c35
9 changed files with 136 additions and 88 deletions

View File

@@ -13,9 +13,6 @@ import (
const (
// DefaultBasicAuthRealm is "Authorization Required"
DefaultBasicAuthRealm = "Authorization Required"
// DefaultBasicAuthContextKey is the "auth"
// this key is used to do context.Set("user", theUsernameFromBasicAuth)
DefaultBasicAuthContextKey = "user"
)
// DefaultExpireTime zero time
@@ -27,18 +24,16 @@ type Config struct {
Users map[string]string
// Realm http://tools.ietf.org/html/rfc2617#section-1.2. Default is "Authorization Required"
Realm string
// ContextKey the key for ctx.GetString(...). Default is 'user'
ContextKey string
// Expires expiration duration, default is 0 never expires
Expires time.Duration
}
// DefaultConfig returns the default configs for the BasicAuth middleware
func DefaultConfig() Config {
return Config{make(map[string]string), DefaultBasicAuthRealm, DefaultBasicAuthContextKey, 0}
return Config{make(map[string]string), DefaultBasicAuthRealm, 0}
}
// User returns the user from context key same as 'ctx.GetString("user")' but cannot be used by the developer, this is only here in order to understand how you can get the authenticated username
func (c Config) User(ctx context.Context) string {
return ctx.Values().GetString(c.ContextKey)
// User returns the user from context key same as ctx.Request().BasicAuth().
func (c Config) User(ctx context.Context) (string, string, bool) {
return ctx.Request().BasicAuth()
}