generated from coulomb/repo-seed
106 lines
2.9 KiB
Markdown
106 lines
2.9 KiB
Markdown
# Examples
|
|
|
|
## Register An Application And Catalog
|
|
|
|
```python
|
|
from user_engine.adapters.local import InMemoryUserEngineStore, LocalAuthorizationCheckPort
|
|
from user_engine.service import UserEngineService
|
|
from user_engine.testing.fixtures import (
|
|
FixtureIdentityClaimsAdapter,
|
|
human_actor_claims,
|
|
sample_application,
|
|
sample_application_binding,
|
|
sample_catalog,
|
|
)
|
|
|
|
service = UserEngineService(
|
|
store=InMemoryUserEngineStore(),
|
|
identity_adapter=FixtureIdentityClaimsAdapter(),
|
|
authorization=LocalAuthorizationCheckPort(),
|
|
)
|
|
|
|
session = service.me(human_actor_claims(), correlation_id="corr-me")
|
|
service.register_application(
|
|
session.actor,
|
|
sample_application(),
|
|
binding=sample_application_binding(),
|
|
correlation_id="corr-app",
|
|
)
|
|
service.publish_catalog(session.actor, sample_catalog(), correlation_id="corr-cat")
|
|
```
|
|
|
|
## Request An Application Projection
|
|
|
|
```python
|
|
from user_engine.domain import ProfileScope, ProjectionType
|
|
|
|
service.set_profile_value(
|
|
session.actor,
|
|
session.user.user_id,
|
|
"demo.display_density",
|
|
"compact",
|
|
scope=ProfileScope.APPLICATION,
|
|
scope_id="app.demo",
|
|
tenant="tenant:coulomb",
|
|
application_id="app.demo",
|
|
correlation_id="corr-profile",
|
|
)
|
|
|
|
projection = service.projection(
|
|
session.actor,
|
|
session.user.user_id,
|
|
ProjectionType.APPLICATION_RUNTIME,
|
|
tenant="tenant:coulomb",
|
|
application_id="app.demo",
|
|
correlation_id="corr-projection",
|
|
)
|
|
```
|
|
|
|
## Handle Profile Change Events
|
|
|
|
Profile mutations append audit records and outbox events in the same service
|
|
operation. Outbox consumers should treat `event_id` as the delivery id and
|
|
`correlation_id` as the cross-system trace key.
|
|
|
|
```python
|
|
for event in service.outbox_events():
|
|
print(event.event_type, event.aggregate_id, event.correlation_id)
|
|
```
|
|
|
|
## Onboard A Family Dataspace
|
|
|
|
```python
|
|
from user_engine.domain import FamilyDataspaceRequest, FamilyMemberSpec, FamilyRole
|
|
|
|
owner = service.me(owner_claims, correlation_id="corr-owner")
|
|
onboarding = service.onboard_family_dataspace(
|
|
owner.actor,
|
|
FamilyDataspaceRequest(
|
|
tenant="tenant:worsch-family",
|
|
family_scope_id="family:worsch",
|
|
family_display_name="Worsch Family",
|
|
application_id="app.personal-dataspace",
|
|
oidc_client_id="personal-dataspace-client",
|
|
protected_system_id="dataspace.personal.worsch",
|
|
member_specs=(
|
|
FamilyMemberSpec(
|
|
primary_email="child@example.test",
|
|
display_name="Child Member",
|
|
role=FamilyRole.CHILD,
|
|
),
|
|
),
|
|
),
|
|
correlation_id="corr-family-onboard",
|
|
)
|
|
|
|
accepted = service.accept_family_invitation(
|
|
child_claims,
|
|
onboarding.invitations[0].invitation.invitation_id,
|
|
correlation_id="corr-child-accept",
|
|
)
|
|
```
|
|
|
|
`accepted.identity_context` is the canon-facing context for the SSO adapter.
|
|
`accepted.claims_projection` is the application-visible profile projection for
|
|
the personal dataspace.
|