Реализация на 4
This commit is contained in:
+5
-4
@@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package jwtprovider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/google/uuid"
|
||||
|
||||
"gitea.privcloud.tech/mtusi2026/internal/dto"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/role"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/types/role"
|
||||
)
|
||||
|
||||
var _ Claims = (*jwtClaims)(nil)
|
||||
@@ -110,14 +110,15 @@ func (p *provider) parseClaimsFromProtectedJWT(token *dto.Token) (*jwtClaims, er
|
||||
token.Payload,
|
||||
claims,
|
||||
p.readKeyFunc,
|
||||
jwt.WithValidMethods([]string{jwt.SigningMethodRS256.Alg()}),
|
||||
jwt.WithExpirationRequired(),
|
||||
jwt.WithIssuedAt(),
|
||||
)
|
||||
if err != nil {
|
||||
slog.Error("failed to parse token with claims", "error", err)
|
||||
return nil, ErrInvalidToken
|
||||
}
|
||||
|
||||
// todo ADD VALIDATION
|
||||
|
||||
if !parsed.Valid {
|
||||
slog.Error("failed to parse token: provided invalid token", "valid", parsed.Valid)
|
||||
return nil, ErrInvalidToken
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package jwtprovider
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package jwtprovider
|
||||
|
||||
import (
|
||||
"errors"
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package jwtprovider
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/google/uuid"
|
||||
|
||||
"gitea.privcloud.tech/mtusi2026/internal/dto"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/role"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/types/role"
|
||||
)
|
||||
|
||||
type Provider interface {
|
||||
+8
-8
@@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package jwtprovider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -18,13 +18,13 @@ type manager struct {
|
||||
|
||||
func NewCookieManager(cfg *config.Config, provider Provider) Cookie {
|
||||
m := &manager{
|
||||
enabled: cfg.Cookies.Enabled,
|
||||
cookieFabric: newCookieBuilder(
|
||||
cfg.Cookies.Domain,
|
||||
cfg.Cookies.Path,
|
||||
cfg.Cookies.Secure,
|
||||
cfg.Cookies.SameSite,
|
||||
),
|
||||
//enabled: cfg.Cookies.Enabled,
|
||||
//cookieFabric: newCookieBuilder(
|
||||
// cfg.Cookies.Domain,
|
||||
// cfg.Cookies.Path,
|
||||
// cfg.Cookies.Secure,
|
||||
// cfg.Cookies.SameSite,
|
||||
//),
|
||||
prv: provider,
|
||||
}
|
||||
|
||||
+6
-8
@@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package jwtprovider
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
|
||||
"gitea.privcloud.tech/mtusi2026/internal/config"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/dto"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/environment"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/role"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/types/environment"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/types/role"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -76,7 +76,7 @@ func (p *provider) ParseVerified(t *dto.Token) (*dto.UserDataInToken, error) {
|
||||
if t == nil {
|
||||
return nil, ErrTokenIsMissing
|
||||
}
|
||||
claims, err := p.parseFunc(t)
|
||||
claims, err := p.parseClaimsFromProtectedJWT(t)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse token: %w", err)
|
||||
}
|
||||
@@ -173,10 +173,8 @@ func (p *provider) ValidateUserDataInToken(u *dto.UserDataInToken) error {
|
||||
}
|
||||
|
||||
func (p *provider) readKeyFunc(token *jwt.Token) (interface{}, error) {
|
||||
switch token.Method.(type) {
|
||||
case *jwt.SigningMethodRSA:
|
||||
return p.publicKey, nil
|
||||
default:
|
||||
if token.Method != jwt.SigningMethodRS256 {
|
||||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
return p.publicKey, nil
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package jwtprovider
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
Reference in New Issue
Block a user