Skip to content

Commit

Permalink
fix: update oauth persister logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nsklikas committed Dec 10, 2024
1 parent a219000 commit 932651b
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions persistence/sql/persister_consent.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,24 +221,21 @@ func (p *Persister) GetConsentRequest(ctx context.Context, challenge string) (_
}

// CreateDeviceUserAuthRequest creates a new flow from a DeviceUserAuthRequest.
func (p *Persister) CreateDeviceUserAuthRequest(ctx context.Context, req *flow.DeviceUserAuthRequest) (*flow.Flow, error) {
func (p *Persister) CreateDeviceUserAuthRequest(ctx context.Context, req *flow.DeviceUserAuthRequest) (_ *flow.Flow, err error) {
ctx, span := p.r.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.CreateDeviceUserAuthRequest")
defer span.End()
defer otelx.End(span, &err)

nid := p.NetworkID(ctx)
if nid == uuid.Nil {
return nil, errorsx.WithStack(x.ErrNotFound)
}
f := flow.NewDeviceFlow(req)
f.NID = nid

return f, nil
}

// GetDeviceUserAuthRequest decodes a challenge into a new DeviceUserAuthRequest.
func (p *Persister) GetDeviceUserAuthRequest(ctx context.Context, challenge string) (*flow.DeviceUserAuthRequest, error) {
func (p *Persister) GetDeviceUserAuthRequest(ctx context.Context, challenge string) (_ *flow.DeviceUserAuthRequest, err error) {
ctx, span := p.r.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.GetDeviceUserAuthRequest")
defer span.End()
defer otelx.End(span, &err)

f, err := flowctx.Decode[flow.Flow](ctx, p.r.FlowCipher(), challenge, flowctx.AsDeviceChallenge)
if err != nil {
Expand All @@ -256,17 +253,17 @@ func (p *Persister) GetDeviceUserAuthRequest(ctx context.Context, challenge stri
}

// HandleDeviceUserAuthRequest uses a HandledDeviceUserAuthRequest to update the flow and returns a DeviceUserAuthRequest.
func (p *Persister) HandleDeviceUserAuthRequest(ctx context.Context, f *flow.Flow, challenge string, r *flow.HandledDeviceUserAuthRequest) (*flow.DeviceUserAuthRequest, error) {
func (p *Persister) HandleDeviceUserAuthRequest(ctx context.Context, f *flow.Flow, challenge string, r *flow.HandledDeviceUserAuthRequest) (_ *flow.DeviceUserAuthRequest, err error) {
ctx, span := p.r.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.HandleDeviceUserAuthRequest")
defer span.End()
defer otelx.End(span, &err)

if f == nil {
return nil, errorsx.WithStack(fosite.ErrInvalidRequest.WithDebug("Flow was nil"))
}
if f.NID != p.NetworkID(ctx) {
return nil, errorsx.WithStack(x.ErrNotFound)
}
err := f.HandleDeviceUserAuthRequest(r)
err = f.HandleDeviceUserAuthRequest(r)
if err != nil {
return nil, err
}
Expand All @@ -275,9 +272,9 @@ func (p *Persister) HandleDeviceUserAuthRequest(ctx context.Context, f *flow.Flo
}

// VerifyAndInvalidateDeviceUserAuthRequest verifies a verifier and invalidates the flow.
func (p *Persister) VerifyAndInvalidateDeviceUserAuthRequest(ctx context.Context, verifier string) (*flow.HandledDeviceUserAuthRequest, error) {
func (p *Persister) VerifyAndInvalidateDeviceUserAuthRequest(ctx context.Context, verifier string) (_ *flow.HandledDeviceUserAuthRequest, err error) {
ctx, span := p.r.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.VerifyAndInvalidateDeviceUserAuthRequest")
defer span.End()
defer otelx.End(span, &err)

f, err := flowctx.Decode[flow.Flow](ctx, p.r.FlowCipher(), verifier, flowctx.AsDeviceVerifier)
if err != nil {
Expand Down

0 comments on commit 932651b

Please sign in to comment.