Skip to content

Commit

Permalink
fix: catch when hydra consent registration fails
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilHanlon committed Mar 28, 2024
1 parent a751a3c commit dc1a443
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion obsidian/impl/v1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ package obsidianimplv1

import (
"context"

"github.com/gogo/status"
client "github.com/ory/hydra-client-go/v2"
"peridot.resf.org/utils"
Expand All @@ -43,6 +44,7 @@ import (
const (
authError = "auth_error"
noUser = "no_user"
badConsent = "bad_consent"
)

func (s *Server) ProcessLoginRequest(challenge string) (*obsidianpb.SessionStatusResponse, error) {
Expand Down Expand Up @@ -104,7 +106,6 @@ func (s *Server) AcceptConsentRequest(ctx context.Context, challenge string, con
consent, _, err := s.hydra.OAuth2API.AcceptOAuth2ConsentRequest(ctx).
ConsentChallenge(challenge).
AcceptOAuth2ConsentRequest(client.AcceptOAuth2ConsentRequest{
Context: ctx,
Remember: utils.Pointer[bool](true),
GrantScope: consentReq.RequestedScope,
GrantAccessTokenAudience: consentReq.RequestedAccessTokenAudience,
Expand All @@ -121,6 +122,11 @@ func (s *Server) AcceptConsentRequest(ctx context.Context, challenge string, con
},
}).Execute()

if err != nil {
s.log.Error(err)
return nil, status.Error(codes.Internal, badConsent)
}

return &obsidianpb.SessionStatusResponse{
Valid: true,
RedirectUrl: consent.RedirectTo,
Expand Down

0 comments on commit dc1a443

Please sign in to comment.