mirror of
https://github.com/kataras/iris.git
synced 2025-12-27 14:57:05 +00:00
rename the sso to auth package
This commit is contained in:
@@ -51,7 +51,7 @@ func (s *userService) GetByID(id int64) (datamodels.User, bool) {
|
||||
})
|
||||
}
|
||||
|
||||
// GetByUsernameAndPassword returns a user based on its username and passowrd,
|
||||
// GetByUsernameAndPassword returns a user based on its username and password,
|
||||
// used for authentication.
|
||||
func (s *userService) GetByUsernameAndPassword(username, userPassword string) (datamodels.User, bool) {
|
||||
if username == "" || userPassword == "" {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
Headers: # required.
|
||||
- "Authorization"
|
||||
- "X-Authorization"
|
||||
Cookie: # optional.
|
||||
Name: "iris_sso"
|
||||
Name: "iris_auth_cookie"
|
||||
Hash: "D*G-KaPdSgUkXp2s5v8y/B?E(H+MbQeThWmYq3t6w9z$C&F)J@NcRfUjXn2r4u7x" # length of 64 characters (512-bit).
|
||||
Block: "VkYp3s6v9y$B&E)H@McQfTjWmZq4t7w!" # length of 32 characters (256-bit).
|
||||
Keys:
|
||||
- ID: IRIS_SSO_ACCESS # required.
|
||||
- ID: IRIS_AUTH_ACCESS # required.
|
||||
Alg: EdDSA
|
||||
MaxAge: 2h # 2 hours lifetime for access tokens.
|
||||
Private: |+
|
||||
@@ -14,7 +17,7 @@ Keys:
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MCowBQYDK2VwAyEAzpgjKSr9E032DX+foiOxq1QDsbzjLxagTN+yVpGWZB4=
|
||||
-----END PUBLIC KEY-----
|
||||
- ID: IRIS_SSO_REFRESH # optional. Good practise to have it though.
|
||||
- ID: IRIS_AUTH_REFRESH # optional. Good practise to have it though.
|
||||
Alg: EdDSA
|
||||
# 1 month lifetime for refresh tokens,
|
||||
# after that period the user has to signin again.
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/auth"
|
||||
"github.com/kataras/iris/v12/mvc"
|
||||
"github.com/kataras/iris/v12/sso"
|
||||
"github.com/kataras/iris/v12/websocket"
|
||||
)
|
||||
|
||||
@@ -29,7 +29,7 @@ func newApp() *iris.Application {
|
||||
LayoutDir("layouts").
|
||||
Layout("main"))
|
||||
|
||||
s := sso.MustLoad[User]("./sso.yml")
|
||||
s := auth.MustLoad[User]("./auth.yml")
|
||||
s.AddProvider(NewProvider())
|
||||
|
||||
app.Get("/signin", renderSigninForm)
|
||||
@@ -63,7 +63,7 @@ func (c *websocketController) Namespace() string {
|
||||
|
||||
func (c *websocketController) OnChat(msg websocket.Message) error {
|
||||
ctx := websocket.GetContext(c.Conn)
|
||||
user := sso.GetUser[User](ctx)
|
||||
user := auth.GetUser[User](ctx)
|
||||
|
||||
msg.Body = []byte(fmt.Sprintf("%s: %s", user.Email, string(msg.Body)))
|
||||
c.Conn.Server().Broadcast(c, msg)
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris/v12/sso"
|
||||
"github.com/kataras/iris/v12/auth"
|
||||
)
|
||||
|
||||
type Provider struct {
|
||||
@@ -49,7 +49,7 @@ func (p *Provider) Signin(ctx context.Context, username, password string) (User,
|
||||
return User{}, fmt.Errorf("user not found")
|
||||
}
|
||||
|
||||
func (p *Provider) ValidateToken(ctx context.Context, standardClaims sso.StandardClaims, u User) error { // fired on VerifyHandler.
|
||||
func (p *Provider) ValidateToken(ctx context.Context, standardClaims auth.StandardClaims, u User) error { // fired on VerifyHandler.
|
||||
// your database and checks of blocked tokens...
|
||||
|
||||
// check for specific token ids.
|
||||
@@ -81,7 +81,7 @@ func (p *Provider) ValidateToken(ctx context.Context, standardClaims sso.Standar
|
||||
return nil // else valid.
|
||||
}
|
||||
|
||||
func (p *Provider) InvalidateToken(ctx context.Context, standardClaims sso.StandardClaims, u User) error { // fired on SignoutHandler.
|
||||
func (p *Provider) InvalidateToken(ctx context.Context, standardClaims auth.StandardClaims, u User) error { // fired on SignoutHandler.
|
||||
// invalidate this specific token.
|
||||
p.mu.Lock()
|
||||
p.invalidated[standardClaims.ID] = struct{}{}
|
||||
Reference in New Issue
Block a user