Skip to content

Commit

Permalink
Merge pull request #1 from formelio/patient-auth
Browse files Browse the repository at this point in the history
Add patient id signer
  • Loading branch information
vilaug authored Apr 24, 2024
2 parents cf5462f + 7dfe571 commit 780dfaa
Show file tree
Hide file tree
Showing 12 changed files with 744 additions and 3 deletions.
2 changes: 2 additions & 0 deletions auth/api/auth/v1/client/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions auth/api/auth/v1/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions auth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package auth
import (
"github.com/nuts-foundation/nuts-node/auth/services"
"github.com/nuts-foundation/nuts-node/auth/services/dummy"
"github.com/nuts-foundation/nuts-node/auth/services/patient"
"github.com/nuts-foundation/nuts-node/auth/services/selfsigned"
"github.com/nuts-foundation/nuts-node/auth/services/uzi"
)
Expand Down Expand Up @@ -54,6 +55,7 @@ func DefaultConfig() Config {
uzi.ContractFormat,
dummy.ContractFormat,
selfsigned.ContractFormat,
patient.ContractFormat,
},
AccessTokenLifeSpan: 60, // seconds, as specced in RFC003
}
Expand Down
12 changes: 12 additions & 0 deletions auth/contract/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ var StandardContractTemplates = TemplateStore{
TemplateAttributes: []string{LegalEntityAttr, LegalEntityCityAttr, ValidFromAttr, ValidToAttr},
Regexp: `NL:BehandelaarLogin:v3 Hierbij verklaar ik te handelen in naam van (.+) te (.+). Deze verklaring is geldig van (.+) tot (.+).`,
},
}, "PatientLogin": {
"v1": &Template{
Type: "PatientLogin",
Version: "v1",
Language: "NL",
Locale: "nl_NL",
SignerAttributes: StandardSignerAttributes,
// TODO: Fix the template and the regexp
Template: `NL:PatientLogin:v1 Ondergetekende geeft toestemming aan {{{` + ActingPartyAttr + `}}} om namens {{{` + LegalEntityAttr + `}}} en ondergetekende het Nuts netwerk te bevragen. Deze toestemming is geldig van {{` + ValidFromAttr + `}} tot {{` + ValidToAttr + `}}.`,
TemplateAttributes: []string{ActingPartyAttr, LegalEntityAttr, ValidFromAttr, ValidToAttr},
Regexp: `NL:PatientLogin:v1 Ondergetekende geeft toestemming aan (.+) om namens (.+) en ondergetekende het Nuts netwerk te bevragen. Deze toestemming is geldig van (.+) tot (.+).`,
},
}},
"EN": {"PractitionerLogin": {
"v3": &Template{
Expand Down
12 changes: 11 additions & 1 deletion auth/services/notary/notary.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ import (
"errors"
"fmt"

"github.com/nuts-foundation/nuts-node/core"
"reflect"
"strings"
"time"

"github.com/nuts-foundation/nuts-node/core"

ssi "github.com/nuts-foundation/go-did"
"github.com/nuts-foundation/go-did/did"
"github.com/nuts-foundation/go-did/vc"
"github.com/nuts-foundation/nuts-node/auth/contract"
"github.com/nuts-foundation/nuts-node/auth/services"
"github.com/nuts-foundation/nuts-node/auth/services/dummy"
"github.com/nuts-foundation/nuts-node/auth/services/irma"
"github.com/nuts-foundation/nuts-node/auth/services/patient"
"github.com/nuts-foundation/nuts-node/auth/services/selfsigned"
"github.com/nuts-foundation/nuts-node/auth/services/uzi"
"github.com/nuts-foundation/nuts-node/auth/services/x509"
Expand Down Expand Up @@ -211,6 +213,14 @@ func (n *notary) Configure() error {
n.signers[selfsigned.ContractFormat] = es
}

if n.config.hasContractValidator(patient.ContractFormat) {
patientSigner := patient.NewSigner(n.vcr, n.config.PublicURL)
patientValidator := patient.NewValidator(n.vcr, contract.StandardContractTemplates)

n.verifiers[patient.VerifiablePresentationType] = patientValidator
n.signers[patient.ContractFormat] = patientSigner
}

return nil
}

Expand Down
95 changes: 95 additions & 0 deletions auth/services/patient/session.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package patient

import (
"encoding/json"
"time"

"github.com/nuts-foundation/go-did/vc"
"github.com/nuts-foundation/nuts-node/vcr/credential"
)

type signingSessionResult struct {
id string
status string
request string
verifiablePresentation *vc.VerifiablePresentation
}

func (s signingSessionResult) Status() string {
return s.status
}

func (s signingSessionResult) VerifiablePresentation() (*vc.VerifiablePresentation, error) {
return s.verifiablePresentation, nil
}

type sessionPointer struct {
sessionID string
}

func (s sessionPointer) SessionID() string {
return s.sessionID
}

func (s sessionPointer) Payload() []byte {
return []byte{}
}

func (s sessionPointer) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
SessionID string `json:"sessionID"`
}{SessionID: s.sessionID})
}

// Session contains the contract text and Session signing Status
type Session struct {
ExpiresAt time.Time
Contract string
Status string
ReferringOrganization string
Patient Patient
}

func (s Session) CredentialSubject() []interface{} {
subject := PatientIdentityCredentialSubject{
BaseCredentialSubject: credential.BaseCredentialSubject{
ID: s.ReferringOrganization,
},
Type: "Organization",
Member: PatientIdentityCredentialMember{
Identifier: s.Patient.Identifier,
Member: PatientIdentityCredentialMemberMember{
FamilyName: s.Patient.FamilyName,
Initials: s.Patient.Initials,
Type: "Patient",
},
},
}
data, _ := json.Marshal(subject)
result := map[string]interface{}{}
_ = json.Unmarshal(data, &result)
return []interface{}{result}
}

type Patient struct {
Identifier string
Initials string
FamilyName string
}

type PatientIdentityCredentialSubject struct {
credential.BaseCredentialSubject
Type string `json:"type"`
Member PatientIdentityCredentialMember `json:"member"`
}

type PatientIdentityCredentialMember struct {
Identifier string `json:"identifier"`
Member PatientIdentityCredentialMemberMember `json:"member"`
}

type PatientIdentityCredentialMemberMember struct {
Initials string `json:"initials"`
FamilyName string `json:"familyName"`
Type string `json:"type"`
}
Loading

0 comments on commit 780dfaa

Please sign in to comment.