Use Header instead of Cookie
This commit is contained in:
parent
99cf27b649
commit
15ab8a3dac
@ -12,11 +12,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *Handler) verifyLogin(c *gin.Context) (budgeteer.Token, error) {
|
func (h *Handler) verifyLogin(c *gin.Context) (budgeteer.Token, error) {
|
||||||
tokenString, err := c.Cookie(authCookie)
|
tokenString := c.GetHeader("Authorization")
|
||||||
if err != nil {
|
tokenString = tokenString[7:]
|
||||||
return nil, fmt.Errorf("get cookie: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
token, err := h.TokenVerifier.VerifyToken(tokenString)
|
token, err := h.TokenVerifier.VerifyToken(tokenString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.SetCookie(authCookie, "", -1, "", "", false, false)
|
c.SetCookie(authCookie, "", -1, "", "", false, false)
|
||||||
@ -30,7 +27,7 @@ func (h *Handler) verifyLoginWithForbidden(c *gin.Context) {
|
|||||||
token, err := h.verifyLogin(c)
|
token, err := h.verifyLogin(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//c.Header("WWW-Authenticate", "Bearer")
|
//c.Header("WWW-Authenticate", "Bearer")
|
||||||
c.AbortWithStatus(http.StatusForbidden)
|
c.AbortWithError(http.StatusForbidden, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,17 +73,25 @@ func clearLogin(c *gin.Context) {
|
|||||||
c.SetCookie(authCookie, "", -1, "", "", false, true)
|
c.SetCookie(authCookie, "", -1, "", "", false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) loginPost(c *gin.Context) {
|
type loginInformation struct {
|
||||||
username, _ := c.GetPostForm("username")
|
Password string `json:"password"`
|
||||||
password, _ := c.GetPostForm("password")
|
User string `json:"user"`
|
||||||
|
}
|
||||||
|
|
||||||
user, err := h.Service.GetUserByUsername(c.Request.Context(), username)
|
func (h *Handler) loginPost(c *gin.Context) {
|
||||||
|
var login loginInformation
|
||||||
|
err := c.BindJSON(&login)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err := h.Service.GetUserByUsername(c.Request.Context(), login.User)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusUnauthorized, err)
|
c.AbortWithError(http.StatusUnauthorized, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = h.CredentialsVerifier.Verify(password, user.Password); err != nil {
|
if err = h.CredentialsVerifier.Verify(login.Password, user.Password); err != nil {
|
||||||
c.AbortWithError(http.StatusUnauthorized, err)
|
c.AbortWithError(http.StatusUnauthorized, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user