Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RFC 8628 #826

Merged
merged 36 commits into from
Feb 3, 2025
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
da9b16b
fix: fix tests
nsklikas Oct 15, 2024
a2f5611
fix: Use Requester param in WriteAccessError
nsklikas Feb 5, 2024
55b085d
fix: generalize validateAuthorizeAudience method
nsklikas Feb 6, 2024
27fc5e1
feat: add device flow base logic
nsklikas Feb 6, 2024
95c216d
fix: add handler for device authorization req
nsklikas Feb 6, 2024
9dc12f8
fix: add device flow handlers to compose
nsklikas Feb 6, 2024
d7b70dd
fix: update memory storage
nsklikas Feb 6, 2024
09a8abe
chore: update integration tests
nsklikas Feb 7, 2024
9618c06
fix: review comments
nsklikas Feb 9, 2024
282633a
feat: implement the access token handling for device authorization flow
wood-push-melon Mar 15, 2024
044f494
fix: passing the correct authorization request when validating if the…
wood-push-melon Mar 17, 2024
027ada7
feat: error handling for authorization pending in device flow
wood-push-melon Mar 18, 2024
88d7ee4
test: reorganize the testcases
wood-push-melon Mar 18, 2024
8ff61e7
chore: resolve comments
wood-push-melon Mar 19, 2024
f1a3568
fix: fix oauth2 core storage interface and device flow session type a…
wood-push-melon Mar 24, 2024
8a3cdd8
fix: implement rate limiting
nsklikas Mar 28, 2024
21d1726
fix: do not validate request when creating response
nsklikas Mar 28, 2024
cb518cc
fix: add the OIDC handler for device flow (#13)
wood-push-melon Apr 5, 2024
426d5ab
fix: fix the refresh token issue (#14)
wood-push-melon Apr 12, 2024
8951431
fix: use correct grant lifespan to issue tokens
nsklikas Apr 29, 2024
040eb7c
fix: handle the user code generation duplication
wood-push-melon Apr 29, 2024
bc45749
chore: migrate to uber/gomock
nsklikas Sep 12, 2024
57bd545
refactor: revert oauth handler changes
nsklikas Oct 16, 2024
4ae79b3
ci: use hydra from branch
nsklikas Oct 16, 2024
3d5c071
fix: remove rate limiting implementation
nsklikas Oct 16, 2024
54a1ff0
fix: make user code creation configurable
nsklikas Oct 16, 2024
4ca84a3
refactor: simplify handler and test logic
nsklikas Oct 17, 2024
675f6f0
refactor: merge user and device code storage
nsklikas Nov 12, 2024
f7ed555
refactor: enhance deviceRequest struct
nsklikas Nov 15, 2024
5db11b0
fix: do not create openid session on device auth request
nsklikas Nov 18, 2024
846cf99
test: check for id and refresh token
nsklikas Jan 7, 2025
8994571
chore: migrate to uber/gomock
nsklikas Jan 7, 2025
54071fe
fix: delete oidc session when used
nsklikas Jan 7, 2025
ae40a12
fix: remove rate limiting implementation
nsklikas Jan 7, 2025
1f15315
chore: update copyright date
nsklikas Jan 7, 2025
b77efc3
fix: write device_code expiration in session
nsklikas Jan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: do not create openid session on device auth request
nsklikas committed Jan 22, 2025

Unverified

The email in this signature doesn’t match the committer email.
commit 5db11b02c444691e952793f28188871b53fdd88b
25 changes: 3 additions & 22 deletions handler/openid/flow_device_auth.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ import (
"github.com/ory/fosite/handler/rfc8628"

"github.com/ory/fosite"
"github.com/ory/x/errorsx"
)

// OpenIDConnectDeviceHandler a response handler for the Device Authorization Grant with OpenID Connect identity layer
@@ -25,26 +24,8 @@ type OpenIDConnectDeviceHandler struct {
}

func (c *OpenIDConnectDeviceHandler) HandleDeviceEndpointRequest(ctx context.Context, dar fosite.DeviceRequester, resp fosite.DeviceResponder) error {
if !(dar.GetRequestedScopes().Has("openid")) {
return nil
}

if !dar.GetClient().GetGrantTypes().Has(string(fosite.GrantTypeDeviceCode)) {
return nil
}

if resp.GetDeviceCode() == "" {
return errorsx.WithStack(fosite.ErrMisconfiguration.WithDebug("The device code has not been issued yet, indicating a broken code configuration."))
}

signature, err := c.DeviceCodeStrategy.DeviceCodeSignature(ctx, resp.GetDeviceCode())
if err != nil {
return err
}

if err := c.OpenIDConnectRequestStorage.CreateOpenIDConnectSession(ctx, signature, dar.Sanitize(oidcParameters)); err != nil {
return errorsx.WithStack(fosite.ErrServerError.WithWrap(err).WithDebug(err.Error()))
}

// We don't want to create the openid session on this call, because we don't know if the user
// will actually complete the flow and give consent. The implementer MUST call the CreateOpenIDConnectSession
// methods when the user logs in to instantiate the session.
return nil
}
38 changes: 0 additions & 38 deletions handler/openid/flow_device_auth_test.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ import (
"time"

"github.com/ory/fosite/internal"
"github.com/pkg/errors"
gomock "go.uber.org/mock/gomock"

"github.com/stretchr/testify/require"
@@ -90,37 +89,6 @@ func TestDeviceAuth_HandleDeviceEndpointRequest(t *testing.T) {
},
},
},
{
description: "should fail because device code is not issued",
authreq: &fosite.DeviceRequest{
Request: fosite.Request{
RequestedScope: fosite.Arguments{"openid", "email"},
Client: client,
},
},
authresp: &fosite.DeviceResponse{},
expectErr: fosite.ErrMisconfiguration,
},
{
description: "should fail because cannot create session",
authreq: &fosite.DeviceRequest{
Request: fosite.Request{
RequestedScope: fosite.Arguments{"openid", "email"},
Client: client,
Session: session,
},
},
authresp: &fosite.DeviceResponse{
DeviceCode: "device_code",
},
setup: func(authreq *fosite.DeviceRequest) {
store.
EXPECT().
CreateOpenIDConnectSession(gomock.Any(), gomock.Any(), gomock.Eq(authreq.Sanitize(oidcParameters))).
Return(errors.New(""))
},
expectErr: fosite.ErrServerError,
},
{
description: "should pass",
authreq: &fosite.DeviceRequest{
@@ -133,12 +101,6 @@ func TestDeviceAuth_HandleDeviceEndpointRequest(t *testing.T) {
authresp: &fosite.DeviceResponse{
DeviceCode: "device_code",
},
setup: func(authreq *fosite.DeviceRequest) {
store.
EXPECT().
CreateOpenIDConnectSession(gomock.Any(), gomock.Any(), gomock.Eq(authreq.Sanitize(oidcParameters))).
Return(nil)
},
},
}