docker fixes
This commit is contained in:
+2
-2
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ 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;
|
||||||
@@ -44,9 +43,6 @@ export default function ConsentPage() {
|
|||||||
setError(t("invalidSession"));
|
setError(t("invalidSession"));
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
window.location.href = session?.redirect_uri || "/";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -35,8 +35,12 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (redirectTo) {
|
if (redirectTo) {
|
||||||
|
if (redirectTo.startsWith("http")) {
|
||||||
|
window.location.href = redirectTo;
|
||||||
|
} else {
|
||||||
router.push(redirectTo);
|
router.push(redirectTo);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, [redirectTo, router]);
|
}, [redirectTo, router]);
|
||||||
|
|
||||||
const onSubmit: SubmitHandler<FormData> = async (data) => {
|
const onSubmit: SubmitHandler<FormData> = async (data) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user