Skip to content

Commit

Permalink
chore: fix authentication and links flow
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsaporiti committed Jul 29, 2024
1 parent 5627fa1 commit de78167
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/api/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (s *Server) AuthCallback(ctx context.Context, request AuthCallbackRequestOb
return AuthCallback400JSONResponse{N400JSONResponse{"Cannot proceed with empty body"}}, nil
}

_, err := s.identityService.Authenticate(ctx, *request.Body, request.Params.SessionID, s.cfg.APIUI.ServerURL, s.cfg.APIUI.IssuerDID)
_, err := s.identityService.Authenticate(ctx, *request.Body, request.Params.SessionID, s.cfg.ServerUrl)
if err != nil {
log.Error(ctx, "error authenticating", err.Error())
return AuthCallback500JSONResponse{}, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/api/links.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *Server) CreateLinkQrCodeCallback(ctx context.Context, request CreateLin
return CreateLinkQrCodeCallback400JSONResponse{N400JSONResponse{"Cannot proceed with empty body"}}, nil
}

arm, err := s.identityService.Authenticate(ctx, *request.Body, request.Params.SessionID, s.cfg.APIUI.ServerURL, s.cfg.APIUI.IssuerDID)
arm, err := s.identityService.Authenticate(ctx, *request.Body, request.Params.SessionID, s.cfg.ServerUrl)
if err != nil {
log.Error(ctx, "error authenticating", err.Error())
return CreateLinkQrCodeCallback500JSONResponse{}, nil
Expand All @@ -106,7 +106,7 @@ func (s *Server) CreateLinkQrCodeCallback(ctx context.Context, request CreateLin
log.Error(ctx, "error getting user DID", err.Error())
return CreateLinkQrCodeCallback400JSONResponse{N400JSONResponse{Message: "expecting a did in From"}}, nil
}
issuerDID, err := w3c.ParseDID(arm.From)
issuerDID, err := w3c.ParseDID(arm.To)
if err != nil {
log.Error(ctx, "error getting issuer DID", err.Error())
return CreateLinkQrCodeCallback400JSONResponse{N400JSONResponse{Message: "expecting a did in To"}}, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/api_ui/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *Server) AuthCallback(ctx context.Context, request AuthCallbackRequestOb
return AuthCallback400JSONResponse{N400JSONResponse{"Cannot proceed with empty body"}}, nil
}

_, err := s.identityService.Authenticate(ctx, *request.Body, request.Params.SessionID, s.cfg.APIUI.ServerURL, s.cfg.APIUI.IssuerDID)
_, err := s.identityService.Authenticate(ctx, *request.Body, request.Params.SessionID, s.cfg.APIUI.ServerURL)
if err != nil {
log.Debug(ctx, "error authenticating", err.Error())
return AuthCallback500JSONResponse{}, nil
Expand Down Expand Up @@ -703,7 +703,7 @@ func (s *Server) CreateLinkQrCodeCallback(ctx context.Context, request CreateLin
return CreateLinkQrCodeCallback400JSONResponse{N400JSONResponse{"Cannot proceed with empty body"}}, nil
}

arm, err := s.identityService.Authenticate(ctx, *request.Body, request.Params.SessionID, s.cfg.APIUI.ServerURL, s.cfg.APIUI.IssuerDID)
arm, err := s.identityService.Authenticate(ctx, *request.Body, request.Params.SessionID, s.cfg.APIUI.ServerURL)
if err != nil {
log.Debug(ctx, "error authenticating", err.Error())
return CreateLinkQrCodeCallback500JSONResponse{}, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/core/ports/identity_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type IdentityService interface {
GetTransactedStates(ctx context.Context) ([]domain.IdentityState, error)
GetStates(ctx context.Context, issuerDID w3c.DID) ([]domain.IdentityState, error)
CreateAuthenticationQRCode(ctx context.Context, serverURL string, issuerDID w3c.DID) (*CreateAuthenticationQRCodeResponse, error)
Authenticate(ctx context.Context, message string, sessionID uuid.UUID, serverURL string, issuerDID w3c.DID) (*protocol.AuthorizationResponseMessage, error)
Authenticate(ctx context.Context, message string, sessionID uuid.UUID, serverURL string) (*protocol.AuthorizationResponseMessage, error)
GetFailedState(ctx context.Context, identifier w3c.DID) (*domain.IdentityState, error)
PublishGenesisStateToRHS(ctx context.Context, did *w3c.DID) error
}
13 changes: 10 additions & 3 deletions internal/core/services/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (i *identity) UpdateIdentityState(ctx context.Context, state *domain.Identi
return err
}

func (i *identity) Authenticate(ctx context.Context, message string, sessionID uuid.UUID, serverURL string, issuerDID w3c.DID) (*protocol.AuthorizationResponseMessage, error) {
func (i *identity) Authenticate(ctx context.Context, message string, sessionID uuid.UUID, serverURL string) (*protocol.AuthorizationResponseMessage, error) {
authReq, err := i.sessionManager.Get(ctx, sessionID.String())
if err != nil {
log.Warn(ctx, "authentication session not found")
Expand All @@ -459,7 +459,14 @@ func (i *identity) Authenticate(ctx context.Context, message string, sessionID u
return nil, err
}

issuerDoc := newDIDDocument(serverURL, issuerDID)
from := authReq.From
issuerDID, err := w3c.ParseDID(from)
if err != nil {
log.Error(ctx, "failed to parse issuerDID", "err", err)
return nil, err
}

issuerDoc := newDIDDocument(serverURL, *issuerDID)
bytesIssuerDoc, err := json.Marshal(issuerDoc)
if err != nil {
log.Error(ctx, "failed to marshal issuerDoc", "err", err)
Expand All @@ -475,7 +482,7 @@ func (i *identity) Authenticate(ctx context.Context, message string, sessionID u

conn := &domain.Connection{
ID: uuid.New(),
IssuerDID: issuerDID,
IssuerDID: *issuerDID,
UserDID: *userDID,
IssuerDoc: bytesIssuerDoc,
UserDoc: arm.Body.DIDDoc,
Expand Down

0 comments on commit de78167

Please sign in to comment.