update all basicauth code reference

This commit is contained in:
Gerasimos (Makis) Maropoulos 2020-11-25 04:54:20 +02:00
parent afa1d89a23
commit ba30ef4de1
No known key found for this signature in database
GPG Key ID: 5DBE766BD26A54E7
5 changed files with 14 additions and 20 deletions

View File

@ -5,8 +5,6 @@ package middleware
import "github.com/kataras/iris/v12/middleware/basicauth"
// BasicAuth middleware sample.
var BasicAuth = basicauth.New(basicauth.Config{
Users: map[string]string{
"admin": "password",
},
var BasicAuth = basicauth.Default(map[string]string{
"admin": "password",
})

View File

@ -74,10 +74,8 @@ func main() {
}),
})
auth := basicauth.New(basicauth.Config{
Users: map[string]string{
"myusername": "mypassword",
},
auth := basicauth.Default(map[string]string{
"myusername": "mypassword",
})
filesRouter.Delete("/{file:path}", auth, deleteFile)

View File

@ -5,8 +5,6 @@ package middleware
import "github.com/kataras/iris/v12/middleware/basicauth"
// BasicAuth middleware sample.
var BasicAuth = basicauth.New(basicauth.Config{
Users: map[string]string{
"admin": "password",
},
var BasicAuth = basicauth.Default(map[string]string{
"admin": "password",
})

View File

@ -5,8 +5,6 @@ package middleware
import "github.com/kataras/iris/v12/middleware/basicauth"
// BasicAuth middleware sample.
var BasicAuth = basicauth.New(basicauth.Config{
Users: map[string]string{
"admin": "password",
},
var BasicAuth = basicauth.Default(map[string]string{
"admin": "password",
})

View File

@ -8,11 +8,11 @@ import (
func newApp() *iris.Application {
app := iris.New()
authConfig := basicauth.Config{
Users: map[string]string{"myusername": "mypassword"},
opts := basicauth.Options{
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") })
@ -36,7 +36,9 @@ func h(ctx iris.Context) {
username, password, _ := ctx.Request().BasicAuth()
// third parameter it will be always true because the middleware
// 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)
}