Skip to content

Commit

Permalink
feat: adding authentication session (#553)
Browse files Browse the repository at this point in the history
* feat: adding authentication session

* fix: solving test

* fix: wrong domain data type, converting sessionID to uuid

* fix: changing uuid example
  • Loading branch information
javip97 authored Nov 22, 2023
1 parent e87b41f commit 1c17199
Show file tree
Hide file tree
Showing 13 changed files with 476 additions and 17 deletions.
74 changes: 72 additions & 2 deletions api_ui/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,34 @@ paths:
$ref: '#/components/responses/500'

#authentication
/v1/authentication/sessions/{id}:
get:
summary: Get Authentication Connection
operationId: getAuthenticationConnection
description: get authentication connection
parameters:
- $ref: '#/components/parameters/id'
tags:
- Auth
- Connection
security:
- basicAuth: [ ]
responses:
'200':
description: ok
content:
application/json:
schema:
$ref: '#/components/schemas/GetAuthenticationConnectionResponse'
'400':
$ref: '#/components/responses/400'
'401':
$ref: '#/components/responses/401'
'404':
$ref: '#/components/responses/404'
'500':
$ref: '#/components/responses/500'

/v1/authentication/qrcode:
get:
summary: Get Connection QRCode
Expand Down Expand Up @@ -981,8 +1009,17 @@ components:
example: did:polygonid:polygon:mumbai:2qFpPHotk6oyaX1fcrpQFT4BMnmg8YszUwxYtaoGoe

QrCodeLinkShortResponse:
type: string
example: iden3comm://?request_uri=https%3A%2F%2Fissuer-demo.polygonid.me%2Fapi%2Fqr-store%3Fid%3Df780a169-8959-4380-9461-f7200e2ed3f4
type: object
required:
- qrCodeLink
- sessionID
properties:
qrCodeLink:
type: string
example: iden3comm://?request_uri=https%3A%2F%2Fissuer-demo.polygonid.me%2Fapi%2Fqr-store%3Fid%3Df780a169-8959-4380-9461-f7200e2ed3f4
sessionID:
$ref: '#/components/schemas/UUIDString'


QrCodeLinkWithSchemaTypeShortResponse:
type: object
Expand Down Expand Up @@ -1084,6 +1121,11 @@ components:
x-omitempty: false
example: c79c9c04-8c98-40f2-a7a0-5eeabf08d836

UUIDString:
type: string
x-omitempty: false
example: b7144f1c-d54e-4f67-a4f1-f2e7ff1beb07

GenericErrorMessage:
type: object
required:
Expand Down Expand Up @@ -1302,6 +1344,34 @@ components:
items:
$ref: '#/components/schemas/GetConnectionResponse'

AuthenticationConnection:
type: object
required:
- id
- userID
- issuerID
- createdAt
- modifiedAt
properties:
id:
$ref: '#/components/schemas/UUIDString'
userID:
$ref: '#/components/schemas/UUIDString'
issuerID:
$ref: '#/components/schemas/UUIDString'
createdAt:
$ref: '#/components/schemas/TimeUTC'
modifiedAt:
$ref: '#/components/schemas/TimeUTC'

GetAuthenticationConnectionResponse:
type: object
required:
- connection
properties:
connection:
$ref: '#/components/schemas/AuthenticationConnection'

GetConnectionResponse:
type: object
required:
Expand Down
144 changes: 143 additions & 1 deletion internal/api_ui/api.gen.go

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

29 changes: 27 additions & 2 deletions internal/api_ui/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,38 @@ func (s *Server) AuthCallback(ctx context.Context, request AuthCallbackRequestOb
return AuthCallback200Response{}, nil
}

// GetAuthenticationConnection returns the connection related to a given session
func (s *Server) GetAuthenticationConnection(ctx context.Context, req GetAuthenticationConnectionRequestObject) (GetAuthenticationConnectionResponseObject, error) {
conn, err := s.connectionsService.GetByUserSessionID(ctx, req.Id)
if err != nil {
log.Error(ctx, "get authentication connection", "err", err, "req", req)
if errors.Is(err, services.ErrConnectionDoesNotExist) {
return GetAuthenticationConnection404JSONResponse{N404JSONResponse{err.Error()}}, nil
}
return GetAuthenticationConnection500JSONResponse{N500JSONResponse{"Unexpected error while getting authentication session"}}, nil
}

return GetAuthenticationConnection200JSONResponse{
Connection: AuthenticationConnection{
Id: conn.ID.String(),
UserID: conn.UserDID.String(),
IssuerID: conn.IssuerDID.String(),
CreatedAt: TimeUTC(conn.CreatedAt),
ModifiedAt: TimeUTC(conn.ModifiedAt),
},
}, nil
}

// AuthQRCode returns the qr code for authenticating a user
func (s *Server) AuthQRCode(ctx context.Context, _ AuthQRCodeRequestObject) (AuthQRCodeResponseObject, error) {
qrCode, err := s.identityService.CreateAuthenticationQRCode(ctx, s.cfg.APIUI.ServerURL, s.cfg.APIUI.IssuerDID)
qrCode, sessionID, err := s.identityService.CreateAuthenticationQRCode(ctx, s.cfg.APIUI.ServerURL, s.cfg.APIUI.IssuerDID)
if err != nil {
return AuthQRCode500JSONResponse{N500JSONResponse{"Unexpected error while creating qr code"}}, nil
}
return NewQrContentResponse([]byte(qrCode)), nil
return AuthQRCode200JSONResponse{
QrCodeLink: qrCode,
SessionID: sessionID.String(),
}, nil
}

// GetConnection returns a connection with its related credentials
Expand Down
Loading

0 comments on commit 1c17199

Please sign in to comment.