Skip to content

Commit

Permalink
remove unused jwt logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Zibbp committed Dec 12, 2024
1 parent 512c7d4 commit 3da9507
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 138 deletions.
44 changes: 0 additions & 44 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/coreos/go-oidc/v3/oidc"
"github.com/golang-jwt/jwt/v4"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
"github.com/zibbp/ganymede/ent"
entUser "github.com/zibbp/ganymede/ent/user"
Expand Down Expand Up @@ -138,47 +135,6 @@ func (s *Service) Login(ctx context.Context, uDto user.User) (*ent.User, error)
return u, nil
}

func (s *Service) Refresh(c echo.Context, refreshToken string) error {

tkn, err := jwt.Parse(refreshToken, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
return []byte(GetJWTRefreshSecret()), nil
})
if err != nil {
if err == jwt.ErrSignatureInvalid {
return fmt.Errorf("invalid refresh token")
}
return fmt.Errorf("error parsing refresh token: %v", err)
}

if claims, ok := tkn.Claims.(jwt.MapClaims); ok && tkn.Valid {
uID := claims["user_id"].(string)
uUUID, err := uuid.Parse(uID)
if err != nil {
return fmt.Errorf("error parsing user id: %v", err)
}
u, err := s.Store.Client.User.Query().Where(entUser.ID(uUUID)).Only(c.Request().Context())
if err != nil {
return fmt.Errorf("error getting user: %v", err)
}

// generate access token
accessToken, exp, err := generateJWTToken(&user.User{ID: u.ID, Username: u.Username, Role: u.Role}, time.Now().Add(1*time.Hour), []byte(GetJWTSecret()))
if err != nil {
return fmt.Errorf("error generating access token: %v", err)
}

// set access token cookie
setTokenCookie(c, accessTokenCookieName, accessToken, exp)

return nil
}

return err
}

func (s *Service) ChangePassword(ctx context.Context, userId uuid.UUID, oldPassword, newPassword string) error {
// sanity check
if oldPassword == newPassword {
Expand Down
87 changes: 0 additions & 87 deletions internal/auth/jwt.go

This file was deleted.

2 changes: 0 additions & 2 deletions internal/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ type EnvApplicationConfig struct {
DB_NAME string `env:"DB_NAME, required"`
DB_SSL string `env:"DB_SSL, default=disable"`
DB_SSL_ROOT_CERT string `env:"DB_SSL_ROOT_CERT, default="`
JWTSecret string `env:"JWT_SECRET, required"`
JWTRefreshSecret string `env:"JWT_REFRESH_SECRET, required"`
FrontendHost string `env:"FRONTEND_HOST, default="`
}

Expand Down
4 changes: 0 additions & 4 deletions internal/config/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,13 @@ func TestGetEnvRequiredConfig(t *testing.T) {
assert.Equal(t, "postgres", env.DB_USER)
assert.Equal(t, "password", env.DB_PASS)
assert.Equal(t, "ganymede", env.DB_NAME)
assert.Equal(t, "secret", env.JWTSecret)
assert.Equal(t, "refresh_secret", env.JWTRefreshSecret)
assert.Equal(t, "localhost", env.FrontendHost)

os.Unsetenv("DB_HOST")
os.Unsetenv("DB_PORT")
os.Unsetenv("DB_USER")
os.Unsetenv("DB_PASS")
os.Unsetenv("DB_NAME")
os.Unsetenv("JWT_SECRET")
os.Unsetenv("JWT_REFRESH_SECRET")
os.Unsetenv("FRONTEND_HOST")
}

Expand Down
1 change: 0 additions & 1 deletion internal/transport/http/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
type AuthService interface {
Register(ctx context.Context, userDto user.User) (*ent.User, error)
Login(ctx context.Context, userDto user.User) (*ent.User, error)
Refresh(c echo.Context, refreshToken string) error
ChangePassword(ctx context.Context, userId uuid.UUID, oldPassword, newPassword string) error
OAuthRedirect(c echo.Context) error
OAuthCallback(c echo.Context) (*ent.User, error)
Expand Down

0 comments on commit 3da9507

Please sign in to comment.