Skip to content

Commit

Permalink
Rename DeviceAuthorizeXXX to DeviceUserXXX
Browse files Browse the repository at this point in the history
  • Loading branch information
supercairos committed Dec 5, 2023
1 parent 6cded09 commit 7ad3851
Show file tree
Hide file tree
Showing 29 changed files with 264 additions and 264 deletions.
4 changes: 2 additions & 2 deletions compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func Compose(config *fosite.Config, storage interface{}, strategy interface{}, f
if dh, ok := res.(fosite.DeviceEndpointHandler); ok {
config.DeviceEndpointHandlers.Append(dh)
}
if dah, ok := res.(fosite.DeviceAuthorizeEndpointHandler); ok {
config.DeviceAuthorizeEndpointHandlers.Append(dah)
if dah, ok := res.(fosite.DeviceUserEndpointHandler); ok {
config.DeviceUserEndpointHandlers.Append(dah)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compose/compose_rfc8628.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func RFC8628DeviceFactory(config fosite.Configurator, storage interface{}, strat
func RFC8628DeviceAuthorizationTokenFactory(config fosite.Configurator, storage interface{}, strategy interface{}) interface{} {
return &rfc8628.DeviceCodeTokenEndpointHandler{
GenericCodeTokenEndpointHandler: oauth2.GenericCodeTokenEndpointHandler{
CodeTokenEndpointHandler: &rfc8628.DeviceAuthorizeHandler{
CodeTokenEndpointHandler: &rfc8628.DeviceUserHandler{
DeviceStrategy: strategy.(rfc8628.DeviceCodeStrategy),
DeviceStorage: storage.(rfc8628.DeviceCodeStorage),
},
Expand Down
10 changes: 5 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type DeviceAndUserCodeLifespanProvider interface {
GetDeviceAndUserCodeLifespan(ctx context.Context) time.Duration
}

type DeviceAuthorizeProvider interface {
type DeviceUserProvider interface {
GetDeviceDone(ctx context.Context) string
}

Expand Down Expand Up @@ -300,10 +300,10 @@ type DeviceEndpointHandlersProvider interface {
GetDeviceEndpointHandlers(ctx context.Context) DeviceEndpointHandlers
}

// DeviceAuthorizeEndpointHandlersProvider returns the provider for setting up the Device Authorize handlers.
type DeviceAuthorizeEndpointHandlersProvider interface {
// GetDeviceAuthorizeEndpointHandlers returns the handlers.
GetDeviceAuthorizeEndpointHandlers(ctx context.Context) DeviceAuthorizeEndpointHandlers
// DeviceUserEndpointHandlersProvider returns the provider for setting up the Device Authorize handlers.
type DeviceUserEndpointHandlersProvider interface {
// GetDeviceUserEndpointHandlers returns the handlers.
GetDeviceUserEndpointHandlers(ctx context.Context) DeviceUserEndpointHandlers
}

// UseLegacyErrorFormatProvider returns the provider for configuring whether to use the legacy error format.
Expand Down
8 changes: 4 additions & 4 deletions config_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ type Config struct {
// DeviceEndpointHandlers is a list of handlers that are called before the device endpoint is served.
DeviceEndpointHandlers DeviceEndpointHandlers

// DeviceAuthorizeEndpointHandlers is a list of handlers that are called before the device authorize endpoint is served.
DeviceAuthorizeEndpointHandlers DeviceAuthorizeEndpointHandlers
// DeviceUserEndpointHandlers is a list of handlers that are called before the device authorize endpoint is served.
DeviceUserEndpointHandlers DeviceUserEndpointHandlers

// GlobalSecret is the global secret used to sign and verify signatures.
GlobalSecret []byte
Expand Down Expand Up @@ -268,8 +268,8 @@ func (c *Config) GetDeviceEndpointHandlers(ctx context.Context) DeviceEndpointHa
return c.DeviceEndpointHandlers
}

func (c *Config) GetDeviceAuthorizeEndpointHandlers(ctx context.Context) DeviceAuthorizeEndpointHandlers {
return c.DeviceAuthorizeEndpointHandlers
func (c *Config) GetDeviceUserEndpointHandlers(ctx context.Context) DeviceUserEndpointHandlers {
return c.DeviceUserEndpointHandlers
}

func (c *Config) GetRevocationHandlers(ctx context.Context) RevocationHandlers {
Expand Down
24 changes: 0 additions & 24 deletions device_authorize_request.go

This file was deleted.

22 changes: 0 additions & 22 deletions device_authorize_response.go

This file was deleted.

21 changes: 0 additions & 21 deletions device_authorize_response_writer.go

This file was deleted.

4 changes: 2 additions & 2 deletions device_request_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestNewDeviceRequest(t *testing.T) {
query url.Values
expectedError error
mock func()
expect *DeviceAuthorizeRequest
expect *DeviceUserRequest
}{
/* empty request */
{
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestNewDeviceRequest(t *testing.T) {
GrantTypes: []string{"urn:ietf:params:oauth:grant-type:device_code"},
}, nil)
},
expect: &DeviceAuthorizeRequest{
expect: &DeviceUserRequest{
Request: Request{
Client: &DefaultClient{
Scopes: []string{"foo", "bar"},
Expand Down
2 changes: 1 addition & 1 deletion device_response_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func TestNewDeviceResponse(t *testing.T) {
ctrl := gomock.NewController(t)
handlers := []*MockDeviceEndpointHandler{NewMockDeviceEndpointHandler(ctrl)}
dar := NewMockDeviceAuthorizeRequester(ctrl)
dar := NewMockDeviceUserRequester(ctrl)
defer ctrl.Finish()

ctx := context.Background()
Expand Down
24 changes: 24 additions & 0 deletions device_user_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

package fosite

// DeviceUserRequest is an implementation of DeviceUserRequester
type DeviceUserRequest struct {
signature string
Request
}

func (d *DeviceUserRequest) GetDeviceCodeSignature() string {
return d.signature
}

func (d *DeviceUserRequest) SetDeviceCodeSignature(signature string) {
d.signature = signature
}

func NewDeviceUserRequest() *DeviceUserRequest {
return &DeviceUserRequest{
Request: *NewRequest(),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
"go.opentelemetry.io/otel/trace"
)

func (f *Fosite) NewDeviceAuthorizeRequest(ctx context.Context, r *http.Request) (_ DeviceAuthorizeRequester, err error) {
ctx, span := trace.SpanFromContext(ctx).TracerProvider().Tracer("github.com/ory/fosite").Start(ctx, "Fosite.NewDeviceAuthorizeRequest")
func (f *Fosite) NewDeviceUserRequest(ctx context.Context, r *http.Request) (_ DeviceUserRequester, err error) {
ctx, span := trace.SpanFromContext(ctx).TracerProvider().Tracer("github.com/ory/fosite").Start(ctx, "Fosite.NewDeviceUserRequest")
defer otelx.End(span, &err)

return f.newDeviceAuthorizeRequest(ctx, r)
return f.newDeviceUserRequest(ctx, r)
}

func (f *Fosite) newDeviceAuthorizeRequest(ctx context.Context, r *http.Request) (DeviceAuthorizeRequester, error) {
request := NewDeviceAuthorizeRequest()
func (f *Fosite) newDeviceUserRequest(ctx context.Context, r *http.Request) (DeviceUserRequester, error) {
request := NewDeviceUserRequest()
request.Lang = i18n.GetLangFromRequest(f.Config.GetMessageCatalog(ctx), r)

if err := r.ParseForm(); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
. "github.com/ory/fosite/internal"
)

func TestNewDeviceAuthorizeRequest(t *testing.T) {
func TestNewDeviceUserRequest(t *testing.T) {
var store *MockStorage
for k, c := range []struct {
desc string
Expand All @@ -31,7 +31,7 @@ func TestNewDeviceAuthorizeRequest(t *testing.T) {
form url.Values
expectedError error
mock func()
expect *DeviceAuthorizeRequest
expect *DeviceUserRequest
}{
/* invalid client */
{
Expand All @@ -49,7 +49,7 @@ func TestNewDeviceAuthorizeRequest(t *testing.T) {
conf: &Fosite{Store: store, Config: &Config{ScopeStrategy: ExactScopeStrategy, AudienceMatchingStrategy: DefaultAudienceMatchingStrategy}},
r: &http.Request{},
mock: func() {},
expect: &DeviceAuthorizeRequest{
expect: &DeviceUserRequest{
Request: Request{},
},
},
Expand All @@ -65,7 +65,7 @@ func TestNewDeviceAuthorizeRequest(t *testing.T) {
GrantTypes: []string{"urn:ietf:params:oauth:grant-type:device_code"},
}, nil)
},
expect: &DeviceAuthorizeRequest{
expect: &DeviceUserRequest{
Request: Request{
Client: &DefaultClient{
GrantTypes: []string{"urn:ietf:params:oauth:grant-type:device_code"},
Expand All @@ -85,7 +85,7 @@ func TestNewDeviceAuthorizeRequest(t *testing.T) {
GrantTypes: []string{"urn:ietf:params:oauth:grant-type:device_code"},
}, nil)
},
expect: &DeviceAuthorizeRequest{
expect: &DeviceUserRequest{
Request: Request{
Client: &DefaultClient{
GrantTypes: []string{"urn:ietf:params:oauth:grant-type:device_code"},
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestNewDeviceAuthorizeRequest(t *testing.T) {
}

c.conf.Store = store
ar, err := c.conf.NewDeviceAuthorizeRequest(context.Background(), c.r)
ar, err := c.conf.NewDeviceUserRequest(context.Background(), c.r)
if c.expectedError != nil {
assert.EqualError(t, err, c.expectedError.Error())
} else {
Expand Down
14 changes: 7 additions & 7 deletions device_authorize_request_test.go → device_user_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ import (
"github.com/stretchr/testify/assert"
)

func TestDeviceAuthorizeRequest(t *testing.T) {
func TestDeviceUserRequest(t *testing.T) {
for k, c := range []struct {
ar *DeviceAuthorizeRequest
ar *DeviceUserRequest
}{
{
ar: NewDeviceAuthorizeRequest(),
ar: NewDeviceUserRequest(),
},
{
ar: &DeviceAuthorizeRequest{},
ar: &DeviceUserRequest{},
},
{
ar: &DeviceAuthorizeRequest{
ar: &DeviceUserRequest{
Request: Request{
Client: &DefaultClient{RedirectURIs: []string{""}},
},
},
},
{
ar: &DeviceAuthorizeRequest{
ar: &DeviceUserRequest{
signature: "AAAA",
Request: Request{
Client: &DefaultClient{RedirectURIs: []string{""}},
},
},
},
{
ar: &DeviceAuthorizeRequest{
ar: &DeviceUserRequest{
Request: Request{
Client: &DefaultClient{RedirectURIs: []string{"https://foobar.com/cb"}},
RequestedAt: time.Now().UTC(),
Expand Down
22 changes: 22 additions & 0 deletions device_user_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

package fosite

import "net/http"

type DeviceUserResponse struct {
Header http.Header
}

func NewDeviceUserResponse() *DeviceUserResponse {
return &DeviceUserResponse{}
}

func (a *DeviceUserResponse) GetHeader() http.Header {
return a.Header
}

func (a *DeviceUserResponse) AddHeader(key, value string) {
a.Header.Add(key, value)
}
21 changes: 21 additions & 0 deletions device_user_response_writer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

package fosite

import (
"context"
)

func (f *Fosite) NewDeviceUserResponse(ctx context.Context, dar DeviceUserRequester, session Session) (DeviceUserResponder, error) {
var resp = &DeviceUserResponse{}

dar.SetSession(session)
for _, h := range f.Config.GetDeviceUserEndpointHandlers(ctx) {
if err := h.HandleDeviceUserEndpointRequest(ctx, dar, resp); err != nil {
return nil, err
}
}

return resp, nil
}
6 changes: 3 additions & 3 deletions device_authorize_writer.go → device_user_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (
"net/http"
)

// Once the user has approved the grant he will be redirected on his loggin machine
// Once the user has approved the grant he will be redirected on his interactive device
// to a webpage (usally hosted in hydra-ui) to understand that he was connected successfully
// and that he can close this tab and return to his non-interactive device;
func (f *Fosite) WriteDeviceAuthorizeResponse(ctx context.Context, r *http.Request, rw http.ResponseWriter, requester DeviceAuthorizeRequester, responder DeviceAuthorizeResponder) {
// and that he can close this tab safely and return to his non-interactive device;
func (f *Fosite) WriteDeviceUserResponse(ctx context.Context, r *http.Request, rw http.ResponseWriter, requester DeviceUserRequester, responder DeviceUserResponder) {
http.Redirect(rw, r, f.Config.GetDeviceDone(ctx), http.StatusSeeOther)
}
2 changes: 1 addition & 1 deletion device_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
. "github.com/ory/fosite"
)

func TestWriteDeviceAuthorizeResponse(t *testing.T) {
func TestWriteDeviceUserResponse(t *testing.T) {
oauth2 := &Fosite{Config: &Config{
DeviceAndUserCodeLifespan: time.Minute,
DeviceAuthTokenPollingInterval: time.Minute,
Expand Down
12 changes: 6 additions & 6 deletions fosite.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ func (a *DeviceEndpointHandlers) Append(h DeviceEndpointHandler) {
*a = append(*a, h)
}

// DeviceAuthorizeEndpointHandlers is a list of DeviceAuthorizeEndpointHandler
type DeviceAuthorizeEndpointHandlers []DeviceAuthorizeEndpointHandler
// DeviceUserEndpointHandlers is a list of DeviceUserEndpointHandler
type DeviceUserEndpointHandlers []DeviceUserEndpointHandler

// Append adds an DeviceAuthorizeEndpointHandlers to this list. Ignores duplicates based on reflect.TypeOf.
func (a *DeviceAuthorizeEndpointHandlers) Append(h DeviceAuthorizeEndpointHandler) {
// Append adds an DeviceUserEndpointHandlers to this list. Ignores duplicates based on reflect.TypeOf.
func (a *DeviceUserEndpointHandlers) Append(h DeviceUserEndpointHandler) {
for _, this := range *a {
if reflect.TypeOf(this) == reflect.TypeOf(h) {
return
Expand Down Expand Up @@ -162,9 +162,9 @@ type Configurator interface {
RevocationHandlersProvider
UseLegacyErrorFormatProvider
DeviceEndpointHandlersProvider
DeviceAuthorizeEndpointHandlersProvider
DeviceUserEndpointHandlersProvider
DeviceProvider
DeviceAuthorizeProvider
DeviceUserProvider
}

func NewOAuth2Provider(s Storage, c Configurator) *Fosite {
Expand Down
Loading

0 comments on commit 7ad3851

Please sign in to comment.