Skip to content

Commit 59ebe1d

Browse files
committed
removed customerDID everywhere
1 parent abd3cb6 commit 59ebe1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1489
-865
lines changed

Makefile

-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ gen-api:
1818
-import-mapping='../common/ssi_types.yaml:github.com/nuts-foundation/nuts-demo-ehr/nuts/client/common' \
1919
-exclude-schemas SearchVCRequest,CredentialSubject \
2020
-o nuts/client/discovery/generated.go https://nuts-node.readthedocs.io/en/latest/_static/discovery/v1.yaml
21-
oapi-codegen -generate client,types -package didman \
22-
-import-mapping='../common/ssi_types.yaml:github.com/nuts-foundation/nuts-demo-ehr/nuts/client/common' \
23-
-o nuts/client/didman/generated.go -exclude-schemas OrganizationSearchResult https://nuts-node.readthedocs.io/en/latest/_static/didman/v1.yaml
24-
oapi-codegen -generate client,types -package vdr \
25-
-import-mapping='../common/ssi_types.yaml:github.com/nuts-foundation/nuts-demo-ehr/nuts/client/common' \
26-
-o nuts/client/vdr/generated.go https://nuts-node.readthedocs.io/en/latest/_static/vdr/v1.yaml
2721
oapi-codegen -generate client,types -package vdr_v2 \
2822
-import-mapping='../common/ssi_types.yaml:github.com/nuts-foundation/nuts-demo-ehr/nuts/client/common' \
2923
-o nuts/client/vdr_v2/generated.go https://nuts-node.readthedocs.io/en/latest/_static/vdr/v2.yaml

api/api.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type Wrapper struct {
5959
FHIRService fhir.Service
6060
EpisodeService episode.Service
6161
NotificationHandler notification.Handler
62-
TenantInitializer func(tenant int) error
62+
TenantInitializer func(tenant string) error
6363
}
6464

6565
func (w Wrapper) CheckSession(ctx echo.Context) error {
@@ -114,11 +114,11 @@ func (w Wrapper) CreateAuthorizationRequest(ctx echo.Context, params CreateAutho
114114
if err != nil {
115115
return err
116116
}
117-
customer, err := w.CustomerRepository.FindByID(customerID)
117+
_, err = w.CustomerRepository.FindByID(customerID)
118118
if err != nil {
119119
return ctx.JSON(http.StatusInternalServerError, errorResponse{err})
120120
}
121-
response, err := w.NutsClient.CreateAuthenticationRequest(*customer.Did, params.Verifier, params.Scope, params.RedirectUri)
121+
response, err := w.NutsClient.CreateAuthenticationRequest(customerID, params.Verifier, params.Scope, params.RedirectUri)
122122
if err != nil {
123123
return err
124124
}
@@ -148,7 +148,7 @@ func (w Wrapper) GetOpenID4VPAuthenticationResult(ctx echo.Context, token string
148148
func (w Wrapper) GetCustomer(ctx echo.Context) error {
149149
customerID := ctx.Get(CustomerID)
150150

151-
customer, err := w.CustomerRepository.FindByID(customerID.(int))
151+
customer, err := w.CustomerRepository.FindByID(customerID.(string))
152152
if err != nil {
153153
return ctx.JSON(http.StatusInternalServerError, errorResponse{err})
154154
}

api/api.yaml

+3-8
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ paths:
829829
description: ID of the customer.
830830
required: true
831831
schema:
832-
type: integer
832+
type: string
833833
- name: taskID
834834
in: path
835835
description: ID of the task.
@@ -856,14 +856,9 @@ components:
856856
- active
857857
properties:
858858
id:
859-
type: integer
859+
type: string
860860
description: The internal customer ID.
861861
example: 1
862-
did:
863-
type: string
864-
description: The customer DID.
865-
example:
866-
"did:nuts:123"
867862
name:
868863
type: string
869864
description: Internal name for this customer.
@@ -1009,7 +1004,7 @@ components:
10091004
properties:
10101005
customerID:
10111006
description: Internal ID of the customer for which is being logged in
1012-
type: integer
1007+
type: string
10131008
example: 1
10141009
password:
10151010
type: string

api/auth.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Auth struct {
3636

3737
type Session struct {
3838
Presentation *iam.VerifiablePresentation
39-
CustomerID int
39+
CustomerID string
4040
StartTime time.Time
4141
UserInfo UserInfo
4242
}
@@ -49,7 +49,7 @@ type UserInfo struct {
4949
}
5050

5151
type JWTCustomClaims struct {
52-
CustomerID int `json:"cis"`
52+
CustomerID string `json:"cis"`
5353
SessionID string `json:"sid"`
5454
JWTStandardClaims
5555
}
@@ -93,7 +93,7 @@ func NewAuth(key *ecdsa.PrivateKey, customers customers.Repository, passwd strin
9393
}
9494

9595
// CreateCustomerJWT creates a JWT that only stores the customer ID.
96-
func (auth *Auth) CreateCustomerJWT(customerId int) ([]byte, error) {
96+
func (auth *Auth) CreateCustomerJWT(customerId string) ([]byte, error) {
9797
t := openid.New()
9898
_ = t.Set(jwt.IssuedAtKey, time.Now())
9999
_ = t.Set(jwt.ExpirationKey, time.Now().Add(MaxSessionAge))
@@ -126,21 +126,21 @@ func (auth *Auth) GetSessions() map[string]Session {
126126
return sessions
127127
}
128128

129-
func (auth *Auth) GetCustomerIDFromHeader(ctx echo.Context) (int, error) {
129+
func (auth *Auth) GetCustomerIDFromHeader(ctx echo.Context) (string, error) {
130130
token, err := auth.extractJWTFromHeader(ctx)
131131
if err != nil {
132132
ctx.Echo().Logger.Error(err)
133-
return 0, echo.NewHTTPError(http.StatusUnauthorized, err)
133+
return "", echo.NewHTTPError(http.StatusUnauthorized, err)
134134
}
135135
rawID, ok := token.Get(CustomerID)
136136
if !ok {
137-
return 0, echo.NewHTTPError(http.StatusUnauthorized, "missing customerID in token")
137+
return "", echo.NewHTTPError(http.StatusUnauthorized, "missing customerID in token")
138138
}
139-
return int(rawID.(float64)), nil
139+
return rawID.(string), nil
140140
}
141141

142142
// CreateSessionJWT creates a JWT with customer ID and session ID
143-
func (auth *Auth) CreateSessionJWT(organizationName, userName string, customerId int, session string) ([]byte, error) {
143+
func (auth *Auth) CreateSessionJWT(organizationName, userName string, customerId string, session string) ([]byte, error) {
144144
t := openid.New()
145145
t.Set(jwt.SubjectKey, organizationName)
146146
t.Set("usi", userName)
@@ -182,7 +182,7 @@ func (auth *Auth) JWTHandler(next echo.HandlerFunc) echo.HandlerFunc {
182182
}
183183
}
184184

185-
func (auth *Auth) AuthenticatePassword(customerID int, password string) (string, UserInfo, error) {
185+
func (auth *Auth) AuthenticatePassword(customerID string, password string) (string, UserInfo, error) {
186186
_, err := auth.customers.FindByID(customerID)
187187
if err != nil {
188188
return "", UserInfo{}, errors.New("invalid customer ID")
@@ -200,7 +200,7 @@ func (auth *Auth) AuthenticatePassword(customerID int, password string) (string,
200200
return token, userInfo, nil
201201
}
202202

203-
func (auth *Auth) createSession(customerID int, userInfo UserInfo) string {
203+
func (auth *Auth) createSession(customerID string, userInfo UserInfo) string {
204204
auth.mux.Lock()
205205
defer auth.mux.Unlock()
206206

api/collaboration.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ func (w Wrapper) CreateCollaboration(ctx echo.Context, dossierID string) error {
2222
if err != nil {
2323
return err
2424
}
25-
if customer.Did == nil || *customer.Did == "" {
26-
return errors.New("DID missing for customer")
27-
}
2825
if request.Sender.Did == "" {
2926
return errors.New("DID missing for other party")
3027
}
@@ -34,7 +31,7 @@ func (w Wrapper) CreateCollaboration(ctx echo.Context, dossierID string) error {
3431
return err
3532
}
3633

37-
patient, err := w.PatientRepository.FindByID(ctx.Request().Context(), customer.Id, string(dossier.PatientID))
34+
patient, err := w.PatientRepository.FindByID(ctx.Request().Context(), customer.Id, dossier.PatientID)
3835
if err != nil {
3936
return err
4037
}
@@ -45,7 +42,7 @@ func (w Wrapper) CreateCollaboration(ctx echo.Context, dossierID string) error {
4542

4643
if err := w.EpisodeService.CreateCollaboration(
4744
ctx.Request().Context(),
48-
*customer.Did,
45+
customer.Id,
4946
dossierID,
5047
*patient.Ssn,
5148
request.Sender.Did,
@@ -62,9 +59,6 @@ func (w Wrapper) GetCollaboration(ctx echo.Context, dossierID string) error {
6259
if err != nil {
6360
return err
6461
}
65-
if customer.Did == nil {
66-
return errors.New("DID missing for customer")
67-
}
6862

6963
dossier, err := w.DossierRepository.FindByID(ctx.Request().Context(), customer.Id, dossierID)
7064
if err != nil {
@@ -83,7 +77,7 @@ func (w Wrapper) GetCollaboration(ctx echo.Context, dossierID string) error {
8377
// We want to find collaborations pointing to us, so we don't want to search on the customer DID
8478
// TODO: We changed this API to showing organizations we shared this episode with, need to
8579
// add another method that shows organizations that shared with us
86-
collaborations, err := w.EpisodeService.GetCollaborations(ctx.Request().Context(), *customer.Did, dossierID, *patient.Ssn, w.FHIRService.ClientFactory(fhir.WithTenant(customer.Id)))
80+
collaborations, err := w.EpisodeService.GetCollaborations(ctx.Request().Context(), customer.Id, dossierID, *patient.Ssn, w.FHIRService.ClientFactory(fhir.WithTenant(customer.Id)))
8781
if err != nil {
8882
return err
8983
}

api/generated.go

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/internal.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/monarko/fhirgo/STU3/resources"
1010
)
1111

12-
func (w Wrapper) TaskUpdate(ctx echo.Context, customerID int, taskID string) error {
12+
func (w Wrapper) TaskUpdate(ctx echo.Context, customerID string, taskID string) error {
1313
// get customer
1414
customer, err := w.CustomerRepository.FindByID(customerID)
1515
if err != nil {

api/patient.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (w Wrapper) GetRemotePatient(ctx echo.Context, params GetRemotePatientParam
107107
if err != nil {
108108
return err
109109
}
110-
patient, err := w.ZorginzageService.RemotePatient(ctx.Request().Context(), *customer.Did, params.RemotePartyDID, params.PatientSSN)
110+
patient, err := w.ZorginzageService.RemotePatient(ctx.Request().Context(), customer.Id, params.RemotePartyDID, params.PatientSSN)
111111
if err != nil {
112112
return fmt.Errorf("unable to load remote patient: %w", err)
113113
}
@@ -135,10 +135,10 @@ func (w Wrapper) getSession(ctx echo.Context) (*Session, error) {
135135
return &sessionCopy, nil
136136
}
137137

138-
func (w Wrapper) getCustomerID(ctx echo.Context) (int, error) {
138+
func (w Wrapper) getCustomerID(ctx echo.Context) (string, error) {
139139
session, err := w.getSession(ctx)
140140
if err != nil {
141-
return 0, err
141+
return "", err
142142
}
143143
return session.CustomerID, nil
144144
}

api/registry.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"net/http"
5+
"slices"
56

67
"github.com/labstack/echo/v4"
78
"github.com/nuts-foundation/nuts-demo-ehr/domain/types"
@@ -22,10 +23,16 @@ func (w Wrapper) SearchOrganizations(ctx echo.Context) error {
2223
return echo.NewHTTPError(http.StatusInternalServerError, err)
2324
}
2425

26+
// get all customer.Id DIDs
27+
dids, err := w.NutsClient.ListSubjectDIDs(ctx.Request().Context(), customer.Id)
28+
if err != nil {
29+
return echo.NewHTTPError(http.StatusInternalServerError, err)
30+
}
31+
2532
var results = make(map[string]types.Organization, 0)
2633
for _, organization := range organizations {
2734
// Hide our own organization
28-
if request.ExcludeOwn != nil && *request.ExcludeOwn && organization.ID == *customer.Did {
35+
if request.ExcludeOwn != nil && *request.ExcludeOwn && slices.Contains(dids, organization.ID) {
2936
continue
3037
}
3138
current, exists := results[organization.ID]

api/report.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (w Wrapper) GetReports(ctx echo.Context, patientID string, params GetReport
3232
}
3333

3434
if patient.Ssn != nil {
35-
remoteReports, err := w.EpisodeService.GetReports(ctx.Request().Context(), *customer.Did, *patient.Ssn)
35+
remoteReports, err := w.EpisodeService.GetReports(ctx.Request().Context(), customer.Id, *patient.Ssn)
3636
if err != nil {
3737
return err
3838
}

api/transfer.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,14 @@ func (w Wrapper) NotifyTransferUpdate(ctx echo.Context, taskID string) error {
222222
}
223223

224224
// client_id for senderDID and sub for customerDID
225-
senderDID := target["client_id"].(string)
226-
customerDID := target["sub"].(string)
225+
_ = json.Unmarshal([]byte(introspectionResult), &target)
226+
customerID := target["iss"].(string)
227+
senderDID := target["sub"].(string)
227228

228229
codeError := datatypes.Code("error")
229230
codeInvalid := datatypes.Code("invalid")
230231
severityError := datatypes.Code("error")
231-
customer, err := w.CustomerRepository.FindByDID(customerDID)
232+
customer, err := w.CustomerRepository.FindByID(customerID)
232233
if err != nil {
233234

234235
return ctx.JSON(http.StatusInternalServerError, &resources.OperationOutcome{
@@ -250,7 +251,7 @@ func (w Wrapper) NotifyTransferUpdate(ctx echo.Context, taskID string) error {
250251
}
251252

252253
if customer == nil {
253-
logrus.Warnf("Received transfer notification for unknown customer DID: %s", senderDID)
254+
logrus.Warnf("Received transfer notification for unknown customer: %s", customerID)
254255

255256
return ctx.JSON(http.StatusNotFound, &resources.OperationOutcome{
256257
Domain: resources.Domain{
@@ -271,10 +272,9 @@ func (w Wrapper) NotifyTransferUpdate(ctx echo.Context, taskID string) error {
271272
}
272273

273274
if err := w.NotificationHandler.Handle(ctx.Request().Context(), notification.Notification{
274-
TaskID: taskID,
275-
SenderDID: senderDID,
276-
CustomerDID: customerDID,
277-
CustomerID: customer.Id,
275+
TaskID: taskID,
276+
SenderDID: senderDID,
277+
CustomerID: customerID,
278278
}); err != nil {
279279
return err
280280
}

docker-compose/left/config/node/nuts.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ discovery:
2121
server:
2222
ids:
2323
- urn:nuts.nl:usecase:eOverdrachtDemo2024
24+
vdr:
25+
didmethods:
26+
- web

docker-compose/right/config/node/nuts.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ discovery:
1818
directory: /nuts/discovery
1919
client:
2020
refresh_interval: 1m
21+
vdr:
22+
didmethods:
23+
- web

domain/customers/repository.go

+2-20
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010
)
1111

1212
type Repository interface {
13-
FindByID(id int) (*types.Customer, error)
14-
FindByDID(did string) (*types.Customer, error)
13+
FindByID(id string) (*types.Customer, error)
1514
All() ([]types.Customer, error)
1615
}
1716

@@ -34,7 +33,7 @@ func NewJsonFileRepository(filepath string) Repository {
3433
}
3534
}
3635

37-
func (db *jsonFileRepo) FindByID(id int) (*types.Customer, error) {
36+
func (db *jsonFileRepo) FindByID(id string) (*types.Customer, error) {
3837
records, err := db.read()
3938
if err != nil {
4039
return nil, err
@@ -51,23 +50,6 @@ func (db *jsonFileRepo) FindByID(id int) (*types.Customer, error) {
5150
return nil, nil
5251
}
5352

54-
func (db *jsonFileRepo) FindByDID(did string) (*types.Customer, error) {
55-
records, err := db.read()
56-
if err != nil {
57-
return nil, err
58-
}
59-
60-
for _, r := range records {
61-
if r.Did != nil && *r.Did == did {
62-
// Hazardous to return a pointer, but this is a demo.
63-
return &r, nil
64-
}
65-
}
66-
67-
// Not found
68-
return nil, nil
69-
}
70-
7153
func (db *jsonFileRepo) All() ([]types.Customer, error) {
7254
records, err := db.read()
7355
if err != nil {

0 commit comments

Comments
 (0)