docker fixes
This commit is contained in:
@@ -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)
|
||||
if err != nil {
|
||||
if err == services.ErrInvalidGrant {
|
||||
oauthErrorJSON(c, services.ErrInvalidGrant)
|
||||
} else {
|
||||
oauthErrorJSON(c, services.ErrAccessDenied)
|
||||
}
|
||||
oauthErrorJSON(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -91,7 +87,7 @@ func (h *OAuthHandler) SessionAttach(c *gin.Context) {
|
||||
|
||||
redirectURL, err := h.svc.SessionAttach(c.Request.Context(), input.Session, accessToken)
|
||||
if err != nil {
|
||||
oauthErrorJSON(c, services.ErrAccessDenied)
|
||||
oauthErrorJSON(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -114,7 +110,12 @@ func (h *OAuthHandler) SessionApprove(c *gin.Context) {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"strings"
|
||||
"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) {
|
||||
sess, err := s.GetOAuthSession(ctx, token)
|
||||
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
|
||||
}
|
||||
if sess.UserID == uuid.Nil {
|
||||
return "", ErrInvalidGrant
|
||||
}
|
||||
@@ -174,8 +179,9 @@ func (s *Service) SessionApprove(ctx context.Context, token string) (string, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
_ = s.redis.Del(ctx, oauthSessionPrefix+token)
|
||||
_ = s.oauth.RecordUserConsent(ctx, sess.UserID, client.ID, sess.Scopes)
|
||||
if err := s.oauth.RecordUserConsent(ctx, sess.UserID, client.ID, sess.Scopes); err != nil {
|
||||
log.Printf("oauth: failed to record consent for user %s client %s: %v", sess.UserID, client.ClientID, err)
|
||||
}
|
||||
|
||||
redirectURL, _ := url.Parse(sess.RedirectURI)
|
||||
q := redirectURL.Query()
|
||||
@@ -188,6 +194,27 @@ func (s *Service) SessionApprove(ctx context.Context, token string) (string, err
|
||||
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) {
|
||||
if auth.ClientID == "" || code == "" || redirectURI == "" || codeVerifier == "" {
|
||||
return nil, ErrInvalidRequest
|
||||
|
||||
Reference in New Issue
Block a user