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

feat: more extension points #4272

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions driver/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
extraGoMigrations popx.Migrations
replacementStrategies []NewStrategy
extraHooks map[string]func(config.SelfServiceHook) any
extraHandlers []NewHandlerRegistrar
disableMigrationLogging bool
jsonnetPool jsonnetsecure.Pool
}
Expand Down Expand Up @@ -236,6 +237,14 @@
}
}

type NewHandlerRegistrar func(deps any) x.HandlerRegistrar

func WithExtraHandlers(handlers ...NewHandlerRegistrar) RegistryOption {
return func(o *options) {
o.extraHandlers = handlers

Check warning on line 244 in driver/registry.go

View check run for this annotation

Codecov / codecov/patch

driver/registry.go#L242-L244

Added lines #L242 - L244 were not covered by tests
}
}

func Inspect(f func(reg Registry) error) RegistryOption {
return func(o *options) {
o.inspect = f
Expand Down
20 changes: 20 additions & 0 deletions driver/registry_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
ctxer contextx.Contextualizer

injectedSelfserviceHooks map[string]func(config.SelfServiceHook) interface{}
extraHandlerFactories []NewHandlerRegistrar
extraHandlers []x.HandlerRegistrar

nosurf nosurf.Handler
trc *otelx.Tracer
Expand Down Expand Up @@ -175,6 +177,9 @@
}

func (m *RegistryDefault) RegisterPublicRoutes(ctx context.Context, router *x.RouterPublic) {
for _, h := range m.ExtraHandlers() {
h.RegisterPublicRoutes(router)

Check warning on line 181 in driver/registry_default.go

View check run for this annotation

Codecov / codecov/patch

driver/registry_default.go#L181

Added line #L181 was not covered by tests
}
m.LoginHandler().RegisterPublicRoutes(router)
m.RegistrationHandler().RegisterPublicRoutes(router)
m.LogoutHandler().RegisterPublicRoutes(router)
Expand All @@ -198,6 +203,9 @@
}

func (m *RegistryDefault) RegisterAdminRoutes(ctx context.Context, router *x.RouterAdmin) {
for _, h := range m.ExtraHandlers() {
h.RegisterAdminRoutes(router)

Check warning on line 207 in driver/registry_default.go

View check run for this annotation

Codecov / codecov/patch

driver/registry_default.go#L207

Added line #L207 was not covered by tests
}
m.RegistrationHandler().RegisterAdminRoutes(router)
m.LoginHandler().RegisterAdminRoutes(router)
m.LogoutHandler().RegisterAdminRoutes(router)
Expand Down Expand Up @@ -640,6 +648,9 @@
if o.extraHooks != nil {
m.WithHooks(o.extraHooks)
}
if o.extraHandlers != nil {
m.WithExtraHandlers(o.extraHandlers)

Check warning on line 652 in driver/registry_default.go

View check run for this annotation

Codecov / codecov/patch

driver/registry_default.go#L652

Added line #L652 was not covered by tests
}

if o.replaceIdentitySchemaProvider != nil {
m.identitySchemaProvider = o.replaceIdentitySchemaProvider(m)
Expand Down Expand Up @@ -904,3 +915,12 @@
}
return m.sessionTokenizer
}

func (m *RegistryDefault) ExtraHandlers() []x.HandlerRegistrar {
if m.extraHandlers == nil {
for _, newHandler := range m.extraHandlerFactories {
m.extraHandlers = append(m.extraHandlers, newHandler(m))

Check warning on line 922 in driver/registry_default.go

View check run for this annotation

Codecov / codecov/patch

driver/registry_default.go#L922

Added line #L922 was not covered by tests
}
}
return m.extraHandlers
}
3 changes: 3 additions & 0 deletions driver/registry_default_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
func (m *RegistryDefault) WithHooks(hooks map[string]func(config.SelfServiceHook) interface{}) {
m.injectedSelfserviceHooks = hooks
}
func (m *RegistryDefault) WithExtraHandlers(handlers []NewHandlerRegistrar) {
m.extraHandlerFactories = handlers

Check warning on line 64 in driver/registry_default_hooks.go

View check run for this annotation

Codecov / codecov/patch

driver/registry_default_hooks.go#L63-L64

Added lines #L63 - L64 were not covered by tests
}

func (m *RegistryDefault) getHooks(credentialsType string, configs []config.SelfServiceHook) (i []interface{}) {
var addSessionIssuer bool
Expand Down
16 changes: 15 additions & 1 deletion embedx/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@
"linkedin",
"linkedin_v2",
"lark",
"x"
"x",
"fedcm-test"
],
"examples": ["google"]
},
Expand Down Expand Up @@ -578,6 +579,19 @@
"type": "string",
"enum": ["auto", "never", "force"],
"default": "auto"
},
"fedcm_config_url": {
"title": "Federation Configuration URL",
"description": "The URL where the FedCM IdP configuration is located for the provider. This is only effective in the Ory Network.",
"type": "string",
"format": "uri",
"examples": ["https://example.com/config.json"]
},
"net_id_token_origin_header": {
"title": "NetID Token Origin Header",
"description": "Contains the orgin header to be used when exchanging a NetID FedCM token for an ID token",
"type": "string",
"examples": ["https://example.com"]
}
},
"additionalProperties": false,
Expand Down
6 changes: 6 additions & 0 deletions internal/client-go/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ docs/ContinueWithVerificationUiFlow.md
docs/CourierAPI.md
docs/CourierMessageStatus.md
docs/CourierMessageType.md
docs/CreateFedcmFlowResponse.md
docs/CreateIdentityBody.md
docs/CreateRecoveryCodeForIdentityBody.md
docs/CreateRecoveryLinkForIdentityBody.md
Expand Down Expand Up @@ -70,6 +71,7 @@ docs/OAuth2ConsentRequestOpenIDConnectContext.md
docs/OAuth2LoginRequest.md
docs/PatchIdentitiesBody.md
docs/PerformNativeLogoutBody.md
docs/Provider.md
docs/RecoveryCodeForIdentity.md
docs/RecoveryFlow.md
docs/RecoveryFlowState.md
Expand Down Expand Up @@ -98,6 +100,7 @@ docs/UiNodeMeta.md
docs/UiNodeScriptAttributes.md
docs/UiNodeTextAttributes.md
docs/UiText.md
docs/UpdateFedcmFlowBody.md
docs/UpdateIdentityBody.md
docs/UpdateLoginFlowBody.md
docs/UpdateLoginFlowWithCodeMethod.md
Expand Down Expand Up @@ -150,6 +153,7 @@ model_continue_with_verification_ui.go
model_continue_with_verification_ui_flow.go
model_courier_message_status.go
model_courier_message_type.go
model_create_fedcm_flow_response.go
model_create_identity_body.go
model_create_recovery_code_for_identity_body.go
model_create_recovery_link_for_identity_body.go
Expand Down Expand Up @@ -193,6 +197,7 @@ model_o_auth2_consent_request_open_id_connect_context.go
model_o_auth2_login_request.go
model_patch_identities_body.go
model_perform_native_logout_body.go
model_provider.go
model_recovery_code_for_identity.go
model_recovery_flow.go
model_recovery_flow_state.go
Expand Down Expand Up @@ -221,6 +226,7 @@ model_ui_node_meta.go
model_ui_node_script_attributes.go
model_ui_node_text_attributes.go
model_ui_text.go
model_update_fedcm_flow_body.go
model_update_identity_body.go
model_update_login_flow_body.go
model_update_login_flow_with_code_method.go
Expand Down
5 changes: 5 additions & 0 deletions internal/client-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Class | Method | HTTP request | Description
*FrontendAPI* | [**CreateBrowserRegistrationFlow**](docs/FrontendAPI.md#createbrowserregistrationflow) | **Get** /self-service/registration/browser | Create Registration Flow for Browsers
*FrontendAPI* | [**CreateBrowserSettingsFlow**](docs/FrontendAPI.md#createbrowsersettingsflow) | **Get** /self-service/settings/browser | Create Settings Flow for Browsers
*FrontendAPI* | [**CreateBrowserVerificationFlow**](docs/FrontendAPI.md#createbrowserverificationflow) | **Get** /self-service/verification/browser | Create Verification Flow for Browser Clients
*FrontendAPI* | [**CreateFedcmFlow**](docs/FrontendAPI.md#createfedcmflow) | **Get** /self-service/fed-cm/parameters | Get FedCM Parameters
*FrontendAPI* | [**CreateNativeLoginFlow**](docs/FrontendAPI.md#createnativeloginflow) | **Get** /self-service/login/api | Create Login Flow for Native Apps
*FrontendAPI* | [**CreateNativeRecoveryFlow**](docs/FrontendAPI.md#createnativerecoveryflow) | **Get** /self-service/recovery/api | Create Recovery Flow for Native Apps
*FrontendAPI* | [**CreateNativeRegistrationFlow**](docs/FrontendAPI.md#createnativeregistrationflow) | **Get** /self-service/registration/api | Create Registration Flow for Native Apps
Expand All @@ -105,6 +106,7 @@ Class | Method | HTTP request | Description
*FrontendAPI* | [**ListMySessions**](docs/FrontendAPI.md#listmysessions) | **Get** /sessions | Get My Active Sessions
*FrontendAPI* | [**PerformNativeLogout**](docs/FrontendAPI.md#performnativelogout) | **Delete** /self-service/logout/api | Perform Logout for Native Apps
*FrontendAPI* | [**ToSession**](docs/FrontendAPI.md#tosession) | **Get** /sessions/whoami | Check Who the Current HTTP Session Belongs To
*FrontendAPI* | [**UpdateFedcmFlow**](docs/FrontendAPI.md#updatefedcmflow) | **Post** /self-service/fed-cm/token | Submit a FedCM token
*FrontendAPI* | [**UpdateLoginFlow**](docs/FrontendAPI.md#updateloginflow) | **Post** /self-service/login | Submit a Login Flow
*FrontendAPI* | [**UpdateLogoutFlow**](docs/FrontendAPI.md#updatelogoutflow) | **Get** /self-service/logout | Update Logout Flow
*FrontendAPI* | [**UpdateRecoveryFlow**](docs/FrontendAPI.md#updaterecoveryflow) | **Post** /self-service/recovery | Update Recovery Flow
Expand Down Expand Up @@ -150,6 +152,7 @@ Class | Method | HTTP request | Description
- [ContinueWithVerificationUiFlow](docs/ContinueWithVerificationUiFlow.md)
- [CourierMessageStatus](docs/CourierMessageStatus.md)
- [CourierMessageType](docs/CourierMessageType.md)
- [CreateFedcmFlowResponse](docs/CreateFedcmFlowResponse.md)
- [CreateIdentityBody](docs/CreateIdentityBody.md)
- [CreateRecoveryCodeForIdentityBody](docs/CreateRecoveryCodeForIdentityBody.md)
- [CreateRecoveryLinkForIdentityBody](docs/CreateRecoveryLinkForIdentityBody.md)
Expand Down Expand Up @@ -193,6 +196,7 @@ Class | Method | HTTP request | Description
- [OAuth2LoginRequest](docs/OAuth2LoginRequest.md)
- [PatchIdentitiesBody](docs/PatchIdentitiesBody.md)
- [PerformNativeLogoutBody](docs/PerformNativeLogoutBody.md)
- [Provider](docs/Provider.md)
- [RecoveryCodeForIdentity](docs/RecoveryCodeForIdentity.md)
- [RecoveryFlow](docs/RecoveryFlow.md)
- [RecoveryFlowState](docs/RecoveryFlowState.md)
Expand Down Expand Up @@ -221,6 +225,7 @@ Class | Method | HTTP request | Description
- [UiNodeScriptAttributes](docs/UiNodeScriptAttributes.md)
- [UiNodeTextAttributes](docs/UiNodeTextAttributes.md)
- [UiText](docs/UiText.md)
- [UpdateFedcmFlowBody](docs/UpdateFedcmFlowBody.md)
- [UpdateIdentityBody](docs/UpdateIdentityBody.md)
- [UpdateLoginFlowBody](docs/UpdateLoginFlowBody.md)
- [UpdateLoginFlowWithCodeMethod](docs/UpdateLoginFlowWithCodeMethod.md)
Expand Down
Loading
Loading