Skip to content

Commit 469c5e1

Browse files
committed
fix: update oauth persister logic
1 parent ced8b62 commit 469c5e1

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

persistence/sql/persister_consent.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,24 +221,21 @@ func (p *Persister) GetConsentRequest(ctx context.Context, challenge string) (_
221221
}
222222

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

228228
nid := p.NetworkID(ctx)
229-
if nid == uuid.Nil {
230-
return nil, errorsx.WithStack(x.ErrNotFound)
231-
}
232229
f := flow.NewDeviceFlow(req)
233230
f.NID = nid
234231

235232
return f, nil
236233
}
237234

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

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

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

263260
if f == nil {
264261
return nil, errorsx.WithStack(fosite.ErrInvalidRequest.WithDebug("Flow was nil"))
265262
}
266263
if f.NID != p.NetworkID(ctx) {
267264
return nil, errorsx.WithStack(x.ErrNotFound)
268265
}
269-
err := f.HandleDeviceUserAuthRequest(r)
266+
err = f.HandleDeviceUserAuthRequest(r)
270267
if err != nil {
271268
return nil, err
272269
}
@@ -275,9 +272,9 @@ func (p *Persister) HandleDeviceUserAuthRequest(ctx context.Context, f *flow.Flo
275272
}
276273

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

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

0 commit comments

Comments
 (0)