Реализация на 4

This commit is contained in:
Grbisba
2026-11-05 14:24:40 +03:00
parent 20f2f00a60
commit 8d44c74535
85 changed files with 3601 additions and 1109 deletions
@@ -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,4 +1,4 @@
package provider
package jwtprovider
import (
"net/http"
@@ -1,4 +1,4 @@
package provider
package jwtprovider
import (
"errors"
@@ -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 {
@@ -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,
}
@@ -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,4 +1,4 @@
package provider
package jwtprovider
import (
"crypto/rsa"