Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions api/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ paths:
validityPeriod: 3600
userAttributes: ["email", "username"]
allowedUserTypes: ["employee", "customer"]
passkeyAllowedOrigins: ["https://myapp.example.com", "https://myapp-staging.example.com"]
loginConsent:
validityPeriod: 3600
inboundAuthConfig:
Expand Down Expand Up @@ -192,6 +193,7 @@ paths:
validityPeriod: 3600
userAttributes: ["email", "username"]
allowedUserTypes: ["employee", "customer"]
passkeyAllowedOrigins: ["https://myapp.example.com", "https://myapp-staging.example.com"]
loginConsent:
enabled: true
validityPeriod: 3600
Expand Down Expand Up @@ -336,6 +338,7 @@ paths:
validityPeriod: 3600
userAttributes: ["email", "username"]
allowedUserTypes: ["employee", "customer"]
passkeyAllowedOrigins: ["https://myapp.example.com", "https://myapp-staging.example.com"]
loginConsent:
enabled: true
validityPeriod: 3600
Expand Down Expand Up @@ -466,6 +469,7 @@ paths:
validityPeriod: 3600
userAttributes: ["email", "username"]
allowedUserTypes: ["employee", "customer"]
passkeyAllowedOrigins: ["https://myapp.example.com", "https://myapp-staging.example.com"]
loginConsent:
validityPeriod: 3600
inboundAuthConfig:
Expand Down Expand Up @@ -543,6 +547,7 @@ paths:
validityPeriod: 3600
userAttributes: ["email", "username"]
allowedUserTypes: ["employee", "customer"]
passkeyAllowedOrigins: ["https://myapp.example.com", "https://myapp-staging.example.com"]
loginConsent:
enabled: true
validityPeriod: 3600
Expand Down Expand Up @@ -849,6 +854,12 @@ components:
type: string
description: Array of allowed user types for this application.
example: ["employee", "customer", "partner"]
passkeyAllowedOrigins:
type: array
items:
type: string
description: Allowed origins for WebAuthn/passkey operations for this application. When set, overrides the server-level passkey allowed origins for flow-based passkey operations.
example: ["https://myapp.example.com", "https://myapp-staging.example.com"]
loginConsent:
type: object
properties:
Expand Down Expand Up @@ -988,6 +999,12 @@ components:
type: string
description: Array of allowed user types for this application.
example: ["employee", "customer", "partner"]
passkeyAllowedOrigins:
type: array
items:
type: string
description: Allowed origins for WebAuthn/passkey operations for this application. When set, overrides the server-level passkey allowed origins for flow-based passkey operations.
example: ["https://myapp.example.com", "https://myapp-staging.example.com"]
loginConsent:
type: object
properties:
Expand Down Expand Up @@ -1109,6 +1126,12 @@ components:
type: string
description: Array of allowed user types for this application.
example: ["employee", "customer", "partner"]
passkeyAllowedOrigins:
type: array
items:
type: string
description: Allowed origins for WebAuthn/passkey operations for this application. When set, overrides the server-level passkey allowed origins for flow-based passkey operations.
example: ["https://myapp.example.com", "https://myapp-staging.example.com"]
loginConsent:
type: object
properties:
Expand Down
2 changes: 1 addition & 1 deletion backend/cmd/server/servicemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func registerServices(mux *http.ServeMux, cacheManager cache.CacheManagerInterfa
// TODO: Remove entityService dependency after finalizing declarative resource loading pattern
applicationService, applicationExporter, err := application.Initialize(
mux, mcpServer, entityProvider, entityService, inboundClientService, ouService, i18nService,
runtimeCryptoSvc)
runtimeCryptoSvc, serverConfigService)
fatalOnError(ctx, logger, err, "Failed to initialize ApplicationService")
exporters = append(exporters, applicationExporter)

Expand Down
11 changes: 6 additions & 5 deletions backend/internal/actorprovider/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ func assembleApplication(
app := &providers.Application{
ID: client.ID,
InboundAuthProfile: providers.InboundAuthProfile{
AuthFlowID: client.AuthFlowID,
SignOutFlowID: client.SignOutFlowID,
Assertion: client.Assertion,
LoginConsent: client.LoginConsent,
AllowedUserTypes: client.AllowedUserTypes,
AuthFlowID: client.AuthFlowID,
SignOutFlowID: client.SignOutFlowID,
Assertion: client.Assertion,
LoginConsent: client.LoginConsent,
AllowedUserTypes: client.AllowedUserTypes,
PasskeyAllowedOrigins: client.PasskeyAllowedOrigins,
},
}

Expand Down
1 change: 1 addition & 0 deletions backend/internal/application/declarative_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func parseToApplicationDTO(data []byte) (*model.ApplicationDTO, error) {
LayoutID: appRequest.LayoutID,
Assertion: appRequest.Assertion,
AllowedUserTypes: appRequest.AllowedUserTypes,
PasskeyAllowedOrigins: appRequest.PasskeyAllowedOrigins,
LoginConsent: appRequest.LoginConsent,
},
Type: appRequest.Type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ certificate:
allowedUserTypes:
- internal
- external
passkeyAllowedOrigins:
- https://app.example.com
- https://login.example.com
`

appDTO, err := parseToApplicationDTO([]byte(yamlData))
Expand All @@ -99,6 +102,7 @@ allowedUserTypes:
assert.NotNil(s.T(), appDTO.Assertion)
assert.Equal(s.T(), int64(3600), appDTO.Assertion.ValidityPeriod)
assert.Equal(s.T(), 2, len(appDTO.AllowedUserTypes))
assert.Equal(s.T(), []string{"https://app.example.com", "https://login.example.com"}, appDTO.PasskeyAllowedOrigins)
}

func (s *ParseToApplicationDTOTestSuite) TestParseToApplicationDTO_MinimalFields() {
Expand Down Expand Up @@ -513,3 +517,27 @@ func (s *ParseToApplicationDTOTestSuite) TestParseToApplicationDTO_OUHandlePasse
assert.Equal(s.T(), "default", appDTO.OUHandle)
assert.Empty(s.T(), appDTO.OUID)
}

func (s *ParseToApplicationDTOTestSuite) TestParseToApplicationDTO_PasskeyAllowedOriginsParsed() {
yamlData := []byte(`
id: passkey-app
name: Passkey Application
passkeyAllowedOrigins:
- https://app.example.com
- https://login.example.com
`)

appDTO, err := parseToApplicationDTO(yamlData)

assert.NoError(s.T(), err)
assert.Equal(s.T(), []string{"https://app.example.com", "https://login.example.com"}, appDTO.PasskeyAllowedOrigins)
}

func (s *ParseToApplicationDTOTestSuite) TestParseToApplicationDTO_PasskeyAllowedOriginsAbsent() {
yamlData := []byte("id: no-passkey-app\nname: No Passkey App\n")

appDTO, err := parseToApplicationDTO(yamlData)

assert.NoError(s.T(), err)
assert.Nil(s.T(), appDTO.PasskeyAllowedOrigins)
}
5 changes: 5 additions & 0 deletions backend/internal/application/handler.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the declarative_resouce.go also, whether there is another place to update

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (ah *applicationHandler) HandleApplicationPostRequest(w http.ResponseWriter
LayoutID: appRequest.LayoutID,
Assertion: appRequest.Assertion,
AllowedUserTypes: appRequest.AllowedUserTypes,
PasskeyAllowedOrigins: appRequest.PasskeyAllowedOrigins,
Comment thread
NutharaNR marked this conversation as resolved.
LoginConsent: appRequest.LoginConsent,
Attestation: appRequest.Attestation,
},
Expand Down Expand Up @@ -119,6 +120,7 @@ func (ah *applicationHandler) HandleApplicationPostRequest(w http.ResponseWriter
LayoutID: createdAppDTO.LayoutID,
Assertion: createdAppDTO.Assertion,
AllowedUserTypes: createdAppDTO.AllowedUserTypes,
PasskeyAllowedOrigins: createdAppDTO.PasskeyAllowedOrigins,
LoginConsent: createdAppDTO.LoginConsent,
Attestation: createdAppDTO.Attestation,
},
Expand Down Expand Up @@ -200,6 +202,7 @@ func (ah *applicationHandler) HandleApplicationGetRequest(w http.ResponseWriter,
LayoutID: appDTO.LayoutID,
Assertion: appDTO.Assertion,
AllowedUserTypes: appDTO.AllowedUserTypes,
PasskeyAllowedOrigins: appDTO.PasskeyAllowedOrigins,
LoginConsent: appDTO.LoginConsent,
Attestation: appDTO.Attestation,
},
Expand Down Expand Up @@ -343,6 +346,7 @@ func (ah *applicationHandler) HandleApplicationPutRequest(w http.ResponseWriter,
LayoutID: appRequest.LayoutID,
Assertion: appRequest.Assertion,
AllowedUserTypes: appRequest.AllowedUserTypes,
PasskeyAllowedOrigins: appRequest.PasskeyAllowedOrigins,
LoginConsent: appRequest.LoginConsent,
Attestation: appRequest.Attestation,
},
Expand Down Expand Up @@ -381,6 +385,7 @@ func (ah *applicationHandler) HandleApplicationPutRequest(w http.ResponseWriter,
LayoutID: updatedAppDTO.LayoutID,
Assertion: updatedAppDTO.Assertion,
AllowedUserTypes: updatedAppDTO.AllowedUserTypes,
PasskeyAllowedOrigins: updatedAppDTO.PasskeyAllowedOrigins,
LoginConsent: updatedAppDTO.LoginConsent,
Attestation: updatedAppDTO.Attestation,
},
Expand Down
63 changes: 63 additions & 0 deletions backend/internal/application/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2433,3 +2433,66 @@ func (suite *HandlerTestSuite) TestHandleApplicationGetRequest_EmptyResponseType

mockService.AssertExpectations(suite.T())
}

func (suite *HandlerTestSuite) TestHandleApplicationPostRequest_ForwardsPasskeyAllowedOrigins() {
mockService := NewApplicationServiceInterfaceMock(suite.T())
handler := newApplicationHandler(mockService)

origins := []string{"https://app.example.com", "https://other.example.com"}
appRequest := model.ApplicationRequest{
OUID: "ou-123",
Name: "TestApp",
}
appRequest.PasskeyAllowedOrigins = origins

expectedApp := &model.ApplicationDTO{ID: "test-app-id", Name: "TestApp"}
expectedApp.PasskeyAllowedOrigins = origins

mockService.On("CreateApplication", mock.Anything,
mock.MatchedBy(func(dto *model.ApplicationDTO) bool {
return assert.Equal(suite.T(), origins, dto.PasskeyAllowedOrigins)
}),
).Return(expectedApp, nil)

body, _ := json.Marshal(appRequest)
req := httptest.NewRequest(http.MethodPost, "/applications", bytes.NewBuffer(body))
req.Header.Set("Content-Type", "application/json")
w := httptest.NewRecorder()

handler.HandleApplicationPostRequest(w, req)

assert.Equal(suite.T(), http.StatusCreated, w.Code)
mockService.AssertExpectations(suite.T())
}

func (suite *HandlerTestSuite) TestHandleApplicationPutRequest_ForwardsPasskeyAllowedOrigins() {
mockService := NewApplicationServiceInterfaceMock(suite.T())
handler := newApplicationHandler(mockService)

origins := []string{"https://app.example.com"}
appRequest := model.ApplicationRequest{
OUID: "ou-123",
Name: "UpdatedApp",
}
appRequest.PasskeyAllowedOrigins = origins

expectedApp := &model.ApplicationDTO{ID: "test-app-id", Name: "UpdatedApp"}
expectedApp.PasskeyAllowedOrigins = origins

mockService.On("UpdateApplication", mock.Anything, "test-app-id",
mock.MatchedBy(func(dto *model.ApplicationDTO) bool {
return assert.Equal(suite.T(), origins, dto.PasskeyAllowedOrigins)
}),
).Return(expectedApp, nil)

body, _ := json.Marshal(appRequest)
req := httptest.NewRequest(http.MethodPut, "/applications/test-app-id", bytes.NewBuffer(body))
req.Header.Set("Content-Type", "application/json")
req.SetPathValue("id", "test-app-id")
w := httptest.NewRecorder()

handler.HandleApplicationPutRequest(w, req)

assert.Equal(suite.T(), http.StatusOK, w.Code)
mockService.AssertExpectations(suite.T())
}
4 changes: 3 additions & 1 deletion backend/internal/application/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/thunder-id/thunderid/internal/entityprovider"
"github.com/thunder-id/thunderid/internal/inboundclient"
oupkg "github.com/thunder-id/thunderid/internal/ou"
"github.com/thunder-id/thunderid/internal/serverconfig"
serverconst "github.com/thunder-id/thunderid/internal/system/constants"
declarativeresource "github.com/thunder-id/thunderid/internal/system/declarative_resource"
i18nmgt "github.com/thunder-id/thunderid/internal/system/i18n/mgt"
Expand All @@ -46,9 +47,10 @@ func Initialize(
ouService oupkg.OrganizationUnitServiceInterface,
i18nService i18nmgt.I18nServiceInterface,
cryptoSvc kmprovider.RuntimeCryptoProvider,
serverConfigSvc serverconfig.ServerConfigService,
) (ApplicationServiceInterface, declarativeresource.ResourceExporter, error) {
appService := newApplicationService(
inboundClient, entityProvider, ouService, i18nService, cryptoSvc,
inboundClient, entityProvider, ouService, i18nService, cryptoSvc, serverConfigSvc,
)

if err := entityService.LoadIndexedAttributes(getAppIndexedAttributes()); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions backend/internal/application/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func (suite *InitTestSuite) TestInitialize_WithDeclarativeResourcesDisabled() {
nil, // ouService - not needed for this test
nil, // i18nService - not needed for this test
nil, // cryptoSvc - not needed for this test
nil, // serverConfigSvc - not needed for this test
)

// Assert
Expand Down Expand Up @@ -202,6 +203,7 @@ func (suite *InitTestSuite) TestInitialize_WithMCPServer() {
nil, // ouService - not needed for this test
nil, // i18nService - not needed for this test
nil, // cryptoSvc - not needed for this test
nil, // serverConfigSvc - not needed for this test
)

// Assert
Expand Down Expand Up @@ -593,6 +595,7 @@ func TestInitialize_Standalone(t *testing.T) {
nil, // ouService - not needed for this test
nil, // i18nService - not needed for this test
nil, // cryptoSvc - not needed for this test
nil, // serverConfigSvc - not needed for this test
)

// Assert
Expand Down Expand Up @@ -644,6 +647,7 @@ func TestInitialize_WithDeclarativeResources_Standalone(t *testing.T) {
nil, // ouService - not needed for this test
nil, // i18nService - not needed for this test
nil, // cryptoSvc - not needed for this test
nil, // serverConfigSvc - not needed for this test
)

// Assert
Expand Down
Loading
Loading