Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
chore: remove OIDC server related endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Yevgen Pukhta <[email protected]>
  • Loading branch information
ypukhta committed Sep 27, 2022
1 parent 4b6c339 commit d4f6826
Show file tree
Hide file tree
Showing 26 changed files with 1,325 additions and 5,426 deletions.
29 changes: 2 additions & 27 deletions cmd/auth-rest/startcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ import (
"github.com/trustbloc/auth/pkg/gnap/accesspolicy"
"github.com/trustbloc/auth/pkg/gnap/interact/redirect"
"github.com/trustbloc/auth/pkg/restapi"
"github.com/trustbloc/auth/pkg/restapi/common/hydra"
oidcmodel "github.com/trustbloc/auth/pkg/restapi/common/oidc"
"github.com/trustbloc/auth/pkg/restapi/gnap"
"github.com/trustbloc/auth/pkg/restapi/operation"
)

Expand Down Expand Up @@ -484,36 +482,13 @@ func startAuthService(parameters *authRestParameters, srv server) error {
// TODO: support creating multiple GNAP user interaction handlers
interact, err := redirect.New(&redirect.Config{
StoreProvider: provider,
InteractBasePath: parameters.externalURL + gnap.InteractPath,
InteractBasePath: parameters.externalURL + operation.InteractPath,
})
if err != nil {
return fmt.Errorf("initializing GNAP interaction handler: %w", err)
}

svc, err := restapi.New(&operation.Config{
TransientStoreProvider: provider,
StoreProvider: provider,
Hydra: hydra.NewClient(parameters.oidcParams.hydraURL, rootCAs),
OIDC: &oidcmodel.Config{
CallbackURL: parameters.oidcParams.callbackURL,
Providers: parameters.oidcParams.providers,
},
BootstrapConfig: &operation.BootstrapConfig{
DocumentSDSVaultURL: parameters.bootstrapParams.documentSDSVaultURL,
KeySDSVaultURL: parameters.bootstrapParams.keySDSVaultURL,
AuthZKeyServerURL: parameters.bootstrapParams.authZKeyServerURL,
OpsKeyServerURL: parameters.bootstrapParams.opsKeyServerURL,
},
DeviceRootCerts: parameters.devicecertParams.caCerts,
TLSConfig: &tls.Config{RootCAs: rootCAs}, //nolint:gosec
UIEndpoint: uiEndpoint,
Cookies: &operation.CookieConfig{
AuthKey: parameters.keys.sessionCookieAuthKey,
EncKey: parameters.keys.sessionCookieEncKey,
},
StartupTimeout: parameters.startupTimeout,
SecretsToken: parameters.secretsAPIToken,
}, &gnap.Config{
StoreProvider: provider,
BaseURL: parameters.externalURL,
AccessPolicyConfig: gnapAPConfig,
Expand All @@ -525,7 +500,7 @@ func startAuthService(parameters *authRestParameters, srv server) error {
CallbackURL: parameters.oidcParams.callbackURL,
Providers: parameters.oidcParams.providers,
},
BootstrapConfig: &gnap.BootstrapConfig{
BootstrapConfig: &operation.BootstrapConfig{
DocumentSDSVaultURL: parameters.bootstrapParams.documentSDSVaultURL,
KeySDSVaultURL: parameters.bootstrapParams.keySDSVaultURL,
OpsKeyServerURL: parameters.bootstrapParams.opsKeyServerURL,
Expand Down
2 changes: 1 addition & 1 deletion component/gnap/as/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/trustbloc/edge-core/pkg/log"
_ "golang.org/x/crypto/sha3" // nolint:gci // init sha3 hash.

gnaprest "github.com/trustbloc/auth/pkg/restapi/gnap"
gnaprest "github.com/trustbloc/auth/pkg/restapi/operation"
"github.com/trustbloc/auth/spi/gnap"
)

Expand Down
2 changes: 1 addition & 1 deletion component/gnap/as/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/square/go-jose/v3"
"github.com/stretchr/testify/require"

gnaprest "github.com/trustbloc/auth/pkg/restapi/gnap"
gnaprest "github.com/trustbloc/auth/pkg/restapi/operation"
"github.com/trustbloc/auth/spi/gnap"
)

Expand Down
2 changes: 1 addition & 1 deletion component/gnap/rs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/trustbloc/edge-core/pkg/log"

gnaprest "github.com/trustbloc/auth/pkg/restapi/gnap"
gnaprest "github.com/trustbloc/auth/pkg/restapi/operation"
"github.com/trustbloc/auth/spi/gnap"
)

Expand Down
2 changes: 1 addition & 1 deletion component/gnap/rs/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/square/go-jose/v3"
"github.com/stretchr/testify/require"

gnaprest "github.com/trustbloc/auth/pkg/restapi/gnap"
gnaprest "github.com/trustbloc/auth/pkg/restapi/operation"
"github.com/trustbloc/auth/spi/gnap"
)

Expand Down
14 changes: 2 additions & 12 deletions pkg/restapi/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,18 @@ import (
"fmt"

"github.com/trustbloc/auth/pkg/restapi/common"
"github.com/trustbloc/auth/pkg/restapi/gnap"
"github.com/trustbloc/auth/pkg/restapi/operation"
)

// New returns new controller instance.
func New(config *operation.Config, gnapConfig *gnap.Config) (*Controller, error) {
func New(gnapConfig *operation.Config) (*Controller, error) {
var allHandlers []common.Handler

rpService, err := operation.New(config)
if err != nil {
return nil, fmt.Errorf("failed to initialize auth-rest operations: %w", err)
}

allHandlers = append(allHandlers, rpService.GetRESTHandlers()...)

gnapService, err := gnap.New(gnapConfig)
gnapService, err := operation.New(gnapConfig)
if err != nil {
return nil, fmt.Errorf("failed to initialize auth-rest gnap operations: %w", err)
}

rpService.SetIntrospectHandler(gnapService.InternalIntrospectHandler())

allHandlers = append(allHandlers, gnapService.GetRESTHandlers()...)

return &Controller{handlers: allHandlers}, nil
Expand Down
64 changes: 4 additions & 60 deletions pkg/restapi/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,101 +7,56 @@ SPDX-License-Identifier: Apache-2.0
package restapi

import (
"crypto/aes"
"crypto/rand"
"errors"
"testing"

"github.com/google/uuid"
"github.com/hyperledger/aries-framework-go/component/storageutil/mem"
mockstore "github.com/hyperledger/aries-framework-go/pkg/mock/storage"
"github.com/stretchr/testify/require"

"github.com/trustbloc/auth/pkg/gnap/accesspolicy"
"github.com/trustbloc/auth/pkg/internal/common/mockinteract"
"github.com/trustbloc/auth/pkg/internal/common/mockoidc"
"github.com/trustbloc/auth/pkg/internal/common/mockstorage"
oidcmodel "github.com/trustbloc/auth/pkg/restapi/common/oidc"
"github.com/trustbloc/auth/pkg/restapi/gnap"
"github.com/trustbloc/auth/pkg/restapi/operation"
)

func TestController_New(t *testing.T) {
t.Run("success", func(t *testing.T) {
config := config(t)

controller, err := New(config, gnapConfig(t))
controller, err := New(gnapConfig(t))
require.NoError(t, err)
require.NotNil(t, controller)
})

t.Run("error if operations cannot start", func(t *testing.T) {
conf := config(t)
conf.TransientStoreProvider = &mockstore.MockStoreProvider{
ErrOpenStoreHandle: errors.New("test"),
}

_, err := New(conf, gnapConfig(t))
require.Error(t, err)
})

t.Run("error if gnap operations cannot start", func(t *testing.T) {
conf := config(t)
gconf := gnapConfig(t)

expectErr := errors.New("expected error")

gconf.StoreProvider = &mockstorage.Provider{ErrOpenStoreHandle: expectErr}

_, err := New(conf, gconf)
_, err := New(gconf)
require.Error(t, err)
require.ErrorIs(t, err, expectErr)
})
}

func TestController_GetOperations(t *testing.T) {
config := config(t)

controller, err := New(config, gnapConfig(t))
controller, err := New(gnapConfig(t))
require.NoError(t, err)
require.NotNil(t, controller)

ops := controller.GetOperations()
require.NotEmpty(t, ops)
}

func config(t *testing.T) *operation.Config {
func gnapConfig(t *testing.T) *operation.Config {
t.Helper()

path := mockoidc.StartProvider(t)

return &operation.Config{
OIDC: &oidcmodel.Config{
CallbackURL: "https://example.com/callback",
Providers: map[string]*oidcmodel.ProviderConfig{
"test": {
URL: path,
ClientID: uuid.New().String(),
ClientSecret: uuid.New().String(),
},
},
},
TransientStoreProvider: mem.NewProvider(),
StoreProvider: mem.NewProvider(),
Cookies: &operation.CookieConfig{
AuthKey: cookieKey(t),
EncKey: cookieKey(t),
},
StartupTimeout: 1,
}
}

func gnapConfig(t *testing.T) *gnap.Config {
t.Helper()

path := mockoidc.StartProvider(t)

return &gnap.Config{
StoreProvider: mem.NewProvider(),
AccessPolicyConfig: &accesspolicy.Config{},
BaseURL: "example.com",
Expand All @@ -120,14 +75,3 @@ func gnapConfig(t *testing.T) *gnap.Config {
TransientStoreProvider: mem.NewProvider(),
}
}

func cookieKey(t *testing.T) []byte {
t.Helper()

key := make([]byte, aes.BlockSize)

_, err := rand.Read(key)
require.NoError(t, err)

return key
}
102 changes: 0 additions & 102 deletions pkg/restapi/gnap/dependencies.go

This file was deleted.

23 changes: 0 additions & 23 deletions pkg/restapi/gnap/models.go

This file was deleted.

Loading

0 comments on commit d4f6826

Please sign in to comment.