Skip to content

Commit acb3361

Browse files
committed
fix: do not create openid session on device auth request
1 parent d0e5c71 commit acb3361

File tree

2 files changed

+3
-36
lines changed

2 files changed

+3
-36
lines changed

handler/openid/flow_device_auth.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ type OpenIDConnectDeviceHandler struct {
2525
}
2626

2727
func (c *OpenIDConnectDeviceHandler) HandleDeviceEndpointRequest(ctx context.Context, dar fosite.DeviceRequester, resp fosite.DeviceResponder) error {
28+
// We don't want to create the openid session on this call, because we don't know if the user
29+
// will actually complete the flow and give consent. The implementer MUST call the CreateOpenIDConnectSession
30+
// methods when the user logs in to instantiate the session.
2831
if !(dar.GetRequestedScopes().Has("openid")) {
2932
return nil
3033
}
@@ -37,14 +40,5 @@ func (c *OpenIDConnectDeviceHandler) HandleDeviceEndpointRequest(ctx context.Con
3740
return errorsx.WithStack(fosite.ErrMisconfiguration.WithDebug("The device code has not been issued yet, indicating a broken code configuration."))
3841
}
3942

40-
signature, err := c.DeviceCodeStrategy.DeviceCodeSignature(ctx, resp.GetDeviceCode())
41-
if err != nil {
42-
return err
43-
}
44-
45-
if err := c.OpenIDConnectRequestStorage.CreateOpenIDConnectSession(ctx, signature, dar.Sanitize(oidcParameters)); err != nil {
46-
return errorsx.WithStack(fosite.ErrServerError.WithWrap(err).WithDebug(err.Error()))
47-
}
48-
4943
return nil
5044
}

handler/openid/flow_device_auth_test.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
"github.com/ory/fosite/internal"
13-
"github.com/pkg/errors"
1413
gomock "go.uber.org/mock/gomock"
1514

1615
"github.com/stretchr/testify/require"
@@ -101,26 +100,6 @@ func TestDeviceAuth_HandleDeviceEndpointRequest(t *testing.T) {
101100
authresp: &fosite.DeviceResponse{},
102101
expectErr: fosite.ErrMisconfiguration,
103102
},
104-
{
105-
description: "should fail because cannot create session",
106-
authreq: &fosite.DeviceRequest{
107-
Request: fosite.Request{
108-
RequestedScope: fosite.Arguments{"openid", "email"},
109-
Client: client,
110-
Session: session,
111-
},
112-
},
113-
authresp: &fosite.DeviceResponse{
114-
DeviceCode: "device_code",
115-
},
116-
setup: func(authreq *fosite.DeviceRequest) {
117-
store.
118-
EXPECT().
119-
CreateOpenIDConnectSession(gomock.Any(), gomock.Any(), gomock.Eq(authreq.Sanitize(oidcParameters))).
120-
Return(errors.New(""))
121-
},
122-
expectErr: fosite.ErrServerError,
123-
},
124103
{
125104
description: "should pass",
126105
authreq: &fosite.DeviceRequest{
@@ -133,12 +112,6 @@ func TestDeviceAuth_HandleDeviceEndpointRequest(t *testing.T) {
133112
authresp: &fosite.DeviceResponse{
134113
DeviceCode: "device_code",
135114
},
136-
setup: func(authreq *fosite.DeviceRequest) {
137-
store.
138-
EXPECT().
139-
CreateOpenIDConnectSession(gomock.Any(), gomock.Any(), gomock.Eq(authreq.Sanitize(oidcParameters))).
140-
Return(nil)
141-
},
142115
},
143116
}
144117

0 commit comments

Comments
 (0)