master
Evan Chen 2022-01-09 05:54:07 +08:00
parent 1737eec0b6
commit c1348da5bd
1 changed files with 4 additions and 4 deletions

View File

@ -78,7 +78,7 @@ func (srv Auth) SetToken(c *gin.Context, tok string) {
c.Header("Authorization", "Bearer "+tok)
if srv.CookieMode {
http.SetCookie(c.Writer, &http.Cookie{
Name: viper.GetString("name") + "_bearer",
Name: viper.GetString("auth.name") + "_bearer",
MaxAge: int(srv.TokenExpire),
Value: tok,
SameSite: srv.CookieSameSite,
@ -102,7 +102,7 @@ func (srv Auth) SetClaims(c *gin.Context, claims *Claims) error {
func (srv Auth) GetToken(c *gin.Context) (tok string, err error) {
tok = strings.TrimPrefix(c.Request.Header.Get("Authorization"), "Bearer ")
if tok == "" && srv.CookieMode {
tok, err = c.Cookie(viper.GetString("name") + "_bearer")
tok, err = c.Cookie(viper.GetString("auth.name") + "_bearer")
}
if err != nil {
err = nil
@ -129,7 +129,7 @@ func (srv Auth) ClearToken(c *gin.Context) {
c.Writer.Header().Del("Authorization")
if srv.CookieMode {
http.SetCookie(c.Writer, &http.Cookie{
Name: viper.GetString("name") + "_bearer",
Name: viper.GetString("auth.name") + "_bearer",
MaxAge: -1,
Value: "",
SameSite: srv.CookieSameSite,
@ -146,7 +146,7 @@ func (srv Auth) NewToken(claims Claims) (tok string, err error) {
} else if claims.ExpiresAt < 0 {
claims.ExpiresAt = 0
}
claims.Issuer = viper.GetString("name")
claims.Issuer = viper.GetString("auth.name")
claims.Id = xid.New().String()
claims.Endpoint = viper.GetString("domain")
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)