docker fixes

This commit is contained in:
Ivan Rezchikov
2026-07-17 13:13:42 +03:00
parent 6cdd095b4a
commit 1b2629b5eb
5 changed files with 50 additions and 22 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
services: services:
kotosoft_id_backend: kotosoft_id_backend:
image: localhost:5000/kotosoft_id_backend:latest image: 172.17.0.1:5000/kotosoft_id_backend:latest
restart: unless-stopped restart: unless-stopped
environment: environment:
SERVER_ADDR: ":8080" SERVER_ADDR: ":8080"
@@ -26,7 +26,7 @@ services:
- eu_net - eu_net
kotosoft_id_frontend: kotosoft_id_frontend:
image: localhost:5000/kotosoft_id_frontend:latest image: 172.17.0.1:5000/kotosoft_id_frontend:latest
restart: unless-stopped restart: unless-stopped
environment: environment:
PUBLIC_URL: ${FRONTEND_URL} PUBLIC_URL: ${FRONTEND_URL}
@@ -58,11 +58,7 @@ func (h *OAuthHandler) SessionLogin(c *gin.Context) {
redirectURL, err := h.svc.SessionLogin(c.Request.Context(), input.Session, input.Email, input.Password) redirectURL, err := h.svc.SessionLogin(c.Request.Context(), input.Session, input.Email, input.Password)
if err != nil { if err != nil {
if err == services.ErrInvalidGrant { oauthErrorJSON(c, err)
oauthErrorJSON(c, services.ErrInvalidGrant)
} else {
oauthErrorJSON(c, services.ErrAccessDenied)
}
return return
} }
@@ -91,7 +87,7 @@ func (h *OAuthHandler) SessionAttach(c *gin.Context) {
redirectURL, err := h.svc.SessionAttach(c.Request.Context(), input.Session, accessToken) redirectURL, err := h.svc.SessionAttach(c.Request.Context(), input.Session, accessToken)
if err != nil { if err != nil {
oauthErrorJSON(c, services.ErrAccessDenied) oauthErrorJSON(c, err)
return return
} }
@@ -114,7 +110,12 @@ func (h *OAuthHandler) SessionApprove(c *gin.Context) {
} }
if !input.Allow { if !input.Allow {
oauthErrorJSON(c, services.ErrAccessDenied) redirectURL, err := h.svc.SessionDeny(c.Request.Context(), input.Session)
if err != nil {
oauthErrorJSON(c, err)
return
}
c.JSON(http.StatusOK, gin.H{"redirect_url": redirectURL})
return return
} }
+30 -3
View File
@@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"net/url" "net/url"
"strings" "strings"
"time" "time"
@@ -156,10 +157,14 @@ func (s *Service) SessionAttach(ctx context.Context, sessionToken, accessToken s
} }
func (s *Service) SessionApprove(ctx context.Context, token string) (string, error) { func (s *Service) SessionApprove(ctx context.Context, token string) (string, error) {
sess, err := s.GetOAuthSession(ctx, token) data, err := s.redis.GetDel(ctx, oauthSessionPrefix+token).Bytes()
if err != nil { if err != nil {
return "", ErrInvalidGrant return "", ErrInvalidGrant
} }
var sess OAuthSession
if err := json.Unmarshal(data, &sess); err != nil {
return "", ErrInvalidGrant
}
if sess.UserID == uuid.Nil { if sess.UserID == uuid.Nil {
return "", ErrInvalidGrant return "", ErrInvalidGrant
} }
@@ -174,8 +179,9 @@ func (s *Service) SessionApprove(ctx context.Context, token string) (string, err
return "", err return "", err
} }
_ = s.redis.Del(ctx, oauthSessionPrefix+token) if err := s.oauth.RecordUserConsent(ctx, sess.UserID, client.ID, sess.Scopes); err != nil {
_ = s.oauth.RecordUserConsent(ctx, sess.UserID, client.ID, sess.Scopes) log.Printf("oauth: failed to record consent for user %s client %s: %v", sess.UserID, client.ClientID, err)
}
redirectURL, _ := url.Parse(sess.RedirectURI) redirectURL, _ := url.Parse(sess.RedirectURI)
q := redirectURL.Query() q := redirectURL.Query()
@@ -188,6 +194,27 @@ func (s *Service) SessionApprove(ctx context.Context, token string) (string, err
return redirectURL.String(), nil return redirectURL.String(), nil
} }
func (s *Service) SessionDeny(ctx context.Context, token string) (string, error) {
data, err := s.redis.GetDel(ctx, oauthSessionPrefix+token).Bytes()
if err != nil {
return "", ErrInvalidGrant
}
var sess OAuthSession
if err := json.Unmarshal(data, &sess); err != nil {
return "", ErrInvalidGrant
}
redirectURL, _ := url.Parse(sess.RedirectURI)
q := redirectURL.Query()
q.Set("error", "access_denied")
if sess.State != "" {
q.Set("state", sess.State)
}
redirectURL.RawQuery = q.Encode()
return redirectURL.String(), nil
}
func (s *Service) ExchangeCode(ctx context.Context, auth ClientAuth, code, redirectURI, codeVerifier string) (*TokenPair, error) { func (s *Service) ExchangeCode(ctx context.Context, auth ClientAuth, code, redirectURI, codeVerifier string) (*TokenPair, error) {
if auth.ClientID == "" || code == "" || redirectURI == "" || codeVerifier == "" { if auth.ClientID == "" || code == "" || redirectURI == "" || codeVerifier == "" {
return nil, ErrInvalidRequest return nil, ErrInvalidRequest
+5 -9
View File
@@ -36,16 +36,12 @@ export default function ConsentPage() {
const handleDecision = async (allow: boolean) => { const handleDecision = async (allow: boolean) => {
setIsSubmitting(true); setIsSubmitting(true);
if (allow) { const result = await Approve(sessionToken, allow);
const result = await Approve(sessionToken, allow); if (result) {
if (result) { window.location.href = result;
window.location.href = result;
} else {
setError(t("invalidSession"));
setIsSubmitting(false);
}
} else { } else {
window.location.href = session?.redirect_uri || "/"; setError(t("invalidSession"));
setIsSubmitting(false);
} }
}; };
+5 -1
View File
@@ -35,7 +35,11 @@ export default function LoginPage() {
useEffect(() => { useEffect(() => {
if (redirectTo) { if (redirectTo) {
router.push(redirectTo); if (redirectTo.startsWith("http")) {
window.location.href = redirectTo;
} else {
router.push(redirectTo);
}
} }
}, [redirectTo, router]); }, [redirectTo, router]);