feat: ci/cd
This commit is contained in:
@@ -96,12 +96,12 @@ func (s *Service) saveSession(ctx context.Context, token string, sess *OAuthSess
|
||||
func (s *Service) SessionLogin(ctx context.Context, token, email, password string) (string, error) {
|
||||
sess, err := s.GetOAuthSession(ctx, token)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", ErrInvalidGrant
|
||||
}
|
||||
|
||||
user, err := s.users.GetUserByEmail(ctx, email)
|
||||
if err != nil || bcryptCompare(user.PasswordHash, password) != nil {
|
||||
return "", models.ErrUnauthorized
|
||||
return "", ErrAccessDenied
|
||||
}
|
||||
|
||||
sess.UserID = user.ID
|
||||
@@ -114,12 +114,7 @@ func (s *Service) SessionLogin(ctx context.Context, token, email, password strin
|
||||
return "", ErrInvalidClient
|
||||
}
|
||||
|
||||
if client.Trusted {
|
||||
return s.SessionApprove(ctx, token)
|
||||
}
|
||||
|
||||
hasUserConsents := s.HasUserConsent(ctx, sess.UserID, client.ID, sess.Scopes)
|
||||
if hasUserConsents {
|
||||
if client.Trusted || s.HasUserConsent(ctx, sess.UserID, client.ID, sess.Scopes) {
|
||||
return s.SessionApprove(ctx, token)
|
||||
}
|
||||
|
||||
@@ -129,12 +124,12 @@ func (s *Service) SessionLogin(ctx context.Context, token, email, password strin
|
||||
func (s *Service) SessionAttach(ctx context.Context, sessionToken, accessToken string) (string, error) {
|
||||
info, err := s.ValidateAccessToken(ctx, accessToken)
|
||||
if err != nil {
|
||||
return "", models.ErrUnauthorized
|
||||
return "", ErrAccessDenied
|
||||
}
|
||||
|
||||
sess, err := s.GetOAuthSession(ctx, sessionToken)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", ErrInvalidGrant
|
||||
}
|
||||
|
||||
sess.UserID = info.UserID
|
||||
@@ -146,12 +141,8 @@ func (s *Service) SessionAttach(ctx context.Context, sessionToken, accessToken s
|
||||
if err != nil {
|
||||
return "", ErrInvalidClient
|
||||
}
|
||||
if client.Trusted {
|
||||
return s.SessionApprove(ctx, sessionToken)
|
||||
}
|
||||
|
||||
hasUserConsents := s.HasUserConsent(ctx, sess.UserID, client.ID, sess.Scopes)
|
||||
if hasUserConsents {
|
||||
if client.Trusted || s.HasUserConsent(ctx, sess.UserID, client.ID, sess.Scopes) {
|
||||
return s.SessionApprove(ctx, sessionToken)
|
||||
}
|
||||
|
||||
@@ -161,7 +152,7 @@ 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)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", ErrInvalidGrant
|
||||
}
|
||||
if sess.UserID == uuid.Nil {
|
||||
return "", ErrInvalidGrant
|
||||
@@ -178,7 +169,7 @@ func (s *Service) SessionApprove(ctx context.Context, token string) (string, err
|
||||
}
|
||||
|
||||
_ = s.redis.Del(ctx, oauthSessionPrefix+token)
|
||||
s.oauth.RecordUserConsent(ctx, sess.UserID, client.ID, sess.Scopes)
|
||||
_ = s.oauth.RecordUserConsent(ctx, sess.UserID, client.ID, sess.Scopes)
|
||||
|
||||
redirectURL, _ := url.Parse(sess.RedirectURI)
|
||||
q := redirectURL.Query()
|
||||
@@ -221,7 +212,7 @@ func (s *Service) ExchangeCode(ctx context.Context, auth ClientAuth, code, redir
|
||||
return nil, models.ErrInternal
|
||||
}
|
||||
|
||||
s.oauth.UpdateConsentLastUsed(ctx, row.UserID, client.ID)
|
||||
_ = s.oauth.UpdateConsentLastUsed(ctx, row.UserID, client.ID)
|
||||
|
||||
return s.issuePair(ctx, user, client.ID, scopesFromJSON(row.Scopes))
|
||||
}
|
||||
@@ -241,22 +232,22 @@ func (s *Service) ExchangeRefreshToken(ctx context.Context, auth ClientAuth, raw
|
||||
return nil, ErrInvalidGrant
|
||||
}
|
||||
|
||||
scopes := scopesFromJSON(row.Scopes)
|
||||
if !ScopesAllowed(client.Scopes, scopes) {
|
||||
return nil, ErrInvalidGrant
|
||||
}
|
||||
|
||||
if err := s.oauth.DeleteRefreshTokenByID(ctx, row.ID); err != nil {
|
||||
return nil, models.ErrInternal
|
||||
}
|
||||
|
||||
s.oauth.UpdateConsentLastUsed(ctx, row.UserID, client.ID)
|
||||
_ = s.oauth.UpdateConsentLastUsed(ctx, row.UserID, client.ID)
|
||||
|
||||
user, err := s.users.GetUserByID(ctx, row.UserID)
|
||||
if err != nil {
|
||||
return nil, models.ErrInternal
|
||||
}
|
||||
|
||||
scopes := scopesFromJSON(row.Scopes)
|
||||
if !ScopesAllowed(client.Scopes, scopes) {
|
||||
return nil, ErrInvalidGrant
|
||||
}
|
||||
|
||||
return s.issuePair(ctx, user, client.ID, scopes)
|
||||
}
|
||||
|
||||
@@ -275,13 +266,7 @@ func (s *Service) RevokeToken(ctx context.Context, auth ClientAuth, rawToken str
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) createAuthCode(
|
||||
ctx context.Context,
|
||||
userID, clientID uuid.UUID,
|
||||
redirectURI string,
|
||||
scopes []string,
|
||||
codeChallenge string,
|
||||
) (string, error) {
|
||||
func (s *Service) createAuthCode(ctx context.Context, userID, clientID uuid.UUID, redirectURI string, scopes []string, codeChallenge string) (string, error) {
|
||||
rawCode, err := newOpaqueToken(32)
|
||||
if err != nil {
|
||||
return "", models.ErrInternal
|
||||
@@ -330,6 +315,7 @@ func (s *Service) issuePair(ctx context.Context, user *models.User, clientID uui
|
||||
Scopes: scopes,
|
||||
ClientID: clientID,
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(accessData)
|
||||
if err := s.redis.Set(ctx, accessTokenPrefix+accessToken, data, s.tokens.AccessTTL).Err(); err != nil {
|
||||
return nil, models.ErrInternal
|
||||
|
||||
Reference in New Issue
Block a user