docker fixes
This commit is contained in:
@@ -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