mirror of
https://github.com/kataras/iris.git
synced 2026-01-04 02:37:14 +00:00
more features and fix database/mysql:jwt example
This commit is contained in:
30
_examples/auth/basicauth/users_file_bcrypt/main.go
Normal file
30
_examples/auth/basicauth/users_file_bcrypt/main.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/middleware/basicauth"
|
||||
)
|
||||
|
||||
func main() {
|
||||
auth := basicauth.Load("users.yml", basicauth.BCRYPT)
|
||||
/* Same as:
|
||||
opts := basicauth.Options{
|
||||
Realm: basicauth.DefaultRealm,
|
||||
Allow: basicauth.AllowUsersFile("users.yml", basicauth.BCRYPT),
|
||||
}
|
||||
|
||||
auth := basicauth.New(opts)
|
||||
*/
|
||||
|
||||
app := iris.New()
|
||||
app.Use(auth)
|
||||
app.Get("/", index)
|
||||
// kataras:kataras_pass
|
||||
// makis:makis_pass
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
func index(ctx iris.Context) {
|
||||
user := ctx.User()
|
||||
ctx.JSON(user)
|
||||
}
|
||||
12
_examples/auth/basicauth/users_file_bcrypt/users.yml
Normal file
12
_examples/auth/basicauth/users_file_bcrypt/users.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
# The file cannot be modified during the serve time.
|
||||
# To support real-time users changes please use the Options.Allow instead,
|
||||
# (see the database example for that).
|
||||
#
|
||||
# Again, the username and password (or capitalized) fields are required,
|
||||
# the rest are optional, depending on your application needs.
|
||||
- username: kataras
|
||||
password: $2a$10$Irg8k8HWkDlvL0YDBKLCYee6j6zzIFTplJcvZYKA.B8/clHPZn2Ey # encrypted of kataras_pass
|
||||
age: 27
|
||||
role: admin
|
||||
- username: makis
|
||||
password: $2a$10$3GXzp3J5GhHThGisbpvpZuftbmzPivDMo94XPnkTnDe7254x7sJ3O # encrypted of makis_pass
|
||||
Reference in New Issue
Block a user