mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
update all basicauth code reference
This commit is contained in:
parent
afa1d89a23
commit
ba30ef4de1
|
@ -5,8 +5,6 @@ package middleware
|
||||||
import "github.com/kataras/iris/v12/middleware/basicauth"
|
import "github.com/kataras/iris/v12/middleware/basicauth"
|
||||||
|
|
||||||
// BasicAuth middleware sample.
|
// BasicAuth middleware sample.
|
||||||
var BasicAuth = basicauth.New(basicauth.Config{
|
var BasicAuth = basicauth.Default(map[string]string{
|
||||||
Users: map[string]string{
|
|
||||||
"admin": "password",
|
"admin": "password",
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -74,10 +74,8 @@ func main() {
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
auth := basicauth.New(basicauth.Config{
|
auth := basicauth.Default(map[string]string{
|
||||||
Users: map[string]string{
|
|
||||||
"myusername": "mypassword",
|
"myusername": "mypassword",
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
filesRouter.Delete("/{file:path}", auth, deleteFile)
|
filesRouter.Delete("/{file:path}", auth, deleteFile)
|
||||||
|
|
|
@ -5,8 +5,6 @@ package middleware
|
||||||
import "github.com/kataras/iris/v12/middleware/basicauth"
|
import "github.com/kataras/iris/v12/middleware/basicauth"
|
||||||
|
|
||||||
// BasicAuth middleware sample.
|
// BasicAuth middleware sample.
|
||||||
var BasicAuth = basicauth.New(basicauth.Config{
|
var BasicAuth = basicauth.Default(map[string]string{
|
||||||
Users: map[string]string{
|
|
||||||
"admin": "password",
|
"admin": "password",
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,8 +5,6 @@ package middleware
|
||||||
import "github.com/kataras/iris/v12/middleware/basicauth"
|
import "github.com/kataras/iris/v12/middleware/basicauth"
|
||||||
|
|
||||||
// BasicAuth middleware sample.
|
// BasicAuth middleware sample.
|
||||||
var BasicAuth = basicauth.New(basicauth.Config{
|
var BasicAuth = basicauth.Default(map[string]string{
|
||||||
Users: map[string]string{
|
|
||||||
"admin": "password",
|
"admin": "password",
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,11 +8,11 @@ import (
|
||||||
func newApp() *iris.Application {
|
func newApp() *iris.Application {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
|
|
||||||
authConfig := basicauth.Config{
|
opts := basicauth.Options{
|
||||||
Users: map[string]string{"myusername": "mypassword"},
|
Allow: basicauth.AllowUsers(map[string]string{"myusername": "mypassword"}),
|
||||||
}
|
}
|
||||||
|
|
||||||
authentication := basicauth.New(authConfig)
|
authentication := basicauth.New(opts) // or just: basicauth.Default(map...)
|
||||||
|
|
||||||
app.Get("/", func(ctx iris.Context) { ctx.Redirect("/admin") })
|
app.Get("/", func(ctx iris.Context) { ctx.Redirect("/admin") })
|
||||||
|
|
||||||
|
@ -36,7 +36,9 @@ func h(ctx iris.Context) {
|
||||||
username, password, _ := ctx.Request().BasicAuth()
|
username, password, _ := ctx.Request().BasicAuth()
|
||||||
// third parameter it will be always true because the middleware
|
// third parameter it will be always true because the middleware
|
||||||
// makes sure for that, otherwise this handler will not be executed.
|
// makes sure for that, otherwise this handler will not be executed.
|
||||||
|
// OR:
|
||||||
|
// ctx.User().GetUsername()
|
||||||
|
// ctx.User().GetPassword()
|
||||||
ctx.Writef("%s %s:%s", ctx.Path(), username, password)
|
ctx.Writef("%s %s:%s", ctx.Path(), username, password)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user