Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-2259:added retrieve qr code #290

Merged
merged 57 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
6691dec
SDK-2259:added retrieve qr code
mehmet-yoti Oct 22, 2023
be2b96b
SDK-2235 added retrieve receipt
mehmet-yoti Oct 23, 2023
6f50c88
SDK-2235 Added Retrieve Receipt
mehmet-yoti Oct 25, 2023
fb79e33
SDK-2235 Added Retrieve Receipt
mehmet-yoti Oct 25, 2023
1586dea
SDK-2235 Added Retrieve Receipt
mehmet-yoti Oct 25, 2023
c2d3b6c
SDK-2235 Added Retrieve Receipt
mehmet-yoti Oct 25, 2023
22d0896
SDK-2254 Resolved pr comments
mehmet-yoti Nov 1, 2023
359a293
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
cb5f083
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
ce57837
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
f61e496
SDK-2254 Resolved pr comments
mehmet-yoti Nov 1, 2023
708fe86
SDK-2254:updated pr changes
mehmet-yoti Nov 2, 2023
2a0f087
SDK-2254 removed unused builder
mehmet-yoti Nov 5, 2023
5912800
SDK-2259:added retrieve qr code
mehmet-yoti Oct 22, 2023
e4a1fc8
SDK-2254 Removed unused examples and updated function namings
mehmet-yoti Nov 1, 2023
06d91c3
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
f410402
SDK-2259:removed unused example files
mehmet-yoti Nov 1, 2023
fd1f342
Merge remote-tracking branch 'origin/SDK-2259-go-retrieve-qr-code' in…
Nov 7, 2023
86d40a4
SDK-2259:added retrieve qr code structs
mehmet-yoti Oct 22, 2023
60e2f4d
SDK-2254 Removed unused examples and updated function namings
mehmet-yoti Nov 1, 2023
7a955f4
SDK-2259:removed unused example files
mehmet-yoti Nov 1, 2023
33131cc
Merge remote-tracking branch 'origin/SDK-2259-go-retrieve-qr-code' in…
Nov 7, 2023
ae46a53
SDK-2254 Resolved pr comments
mehmet-yoti Nov 1, 2023
22bbe7d
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
9a619e8
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
bc20038
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
00ef7b0
SDK-2254 Resolved pr comments
mehmet-yoti Nov 1, 2023
4cf2791
SDK-2254:updated pr changes
mehmet-yoti Nov 2, 2023
ad1f3f9
SDK-2254 removed unused builder
mehmet-yoti Nov 5, 2023
87d61de
SDK-2259:added retrieve qr code structs
mehmet-yoti Oct 22, 2023
6c2d312
SDK-2254 Removed unused examples and updated function namings
mehmet-yoti Nov 1, 2023
d40c218
SDK-2259:removed unused example files
mehmet-yoti Nov 1, 2023
f8657c2
SDK-2254 Removed unused examples and updated function namings
mehmet-yoti Nov 1, 2023
4c019b3
SDK-2259:removed unused example files
mehmet-yoti Nov 1, 2023
a841a3e
SDK-2235:error handling, updated comments
mehmet-yoti Nov 7, 2023
87f5098
SDK-2235:updated method descriptions and addedd error handlers with d…
mehmet-yoti Nov 8, 2023
2492915
SDK-2235:added some error handling, updated comments, added error han…
mehmet-yoti Nov 10, 2023
5bf052f
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
9661755
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
75502ef
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
b7d7b23
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
8e20b5e
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
b893957
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
4993e35
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
e52a26c
Update cryptoutil/crypto_utils.go
mehmet-yoti Nov 23, 2023
b9d8fed
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
c09c2c2
Update cryptoutil/crypto_utils.go
mehmet-yoti Nov 23, 2023
8dd3c7c
SDK-2235: added error details, cleaned unneccessary func and merged i…
mehmet-yoti Nov 24, 2023
f705d44
Merge branch 'SDK-2259-go-retrieve-qr-code' into SDK-2235-share-v-2-r…
mehmet-yoti Nov 24, 2023
a4775d2
Update cryptoutil/crypto_utils.go
mehmet-yoti Dec 7, 2023
3da5372
SDK-2235:reduced complexity
mehmet-yoti Dec 7, 2023
9d403b8
SDK-2235 removed unused method, added panic controls, added error con…
mehmet-yoti Dec 12, 2023
af99524
SDK-2235 added error contexts
mehmet-yoti Dec 12, 2023
a3d8314
Update digitalidentity/service.go
mehmet-yoti Dec 14, 2023
5f1ec57
Update digitalidentity/service.go
mehmet-yoti Dec 14, 2023
3fb2de7
SDK-2235 updated error context text
mehmet-yoti Dec 14, 2023
ac64677
Merge pull request #289 from getyoti/SDK-2235-share-v-2-retrieve-receipt
mehmet-yoti Dec 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion _examples/idv/handlers.session.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ func pageFromShareSessionReq(c *gin.Context, sessionReq *digitalidentity.ShareSe

klaidas marked this conversation as resolved.
Show resolved Hide resolved
createQr, err := didClient.CreateShareQrCode(shareSession.Id)

b, err = json.Marshal(createQr)
getQr, err := didClient.GetQrCode(createQr.Id)
klaidas marked this conversation as resolved.
Show resolved Hide resolved

b, err = json.Marshal(getQr)
if err != nil {
fmt.Println(err)
return
Expand Down
Binary file modified _examples/idv/idv
Binary file not shown.
5 changes: 5 additions & 0 deletions digital_identity_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ func (client *DigitalIdentityClient) GetShareSession(sessionID string) (*digital
func (client *DigitalIdentityClient) CreateShareQrCode(sessionID string) (share *digitalidentity.QrCode, err error) {
return digitalidentity.CreateShareQrCode(client.HTTPClient, sessionID, client.GetSdkID(), client.getAPIURL(), client.Key)
}

// Get session QR code based on generated Qr ID
func (client *DigitalIdentityClient) GetQrCode(qrCodeId string) (share digitalidentity.ShareSessionFetchedQrCode, err error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Get session QR code based on generated Qr ID
func (client *DigitalIdentityClient) GetQrCode(qrCodeId string) (share digitalidentity.ShareSessionFetchedQrCode, err error) {
// GetShareSessionQrCode retrieves a session QR code based on generated Qr ID
func (client *DigitalIdentityClient) GetShareSessionQrCode(qrCodeId string) (share digitalidentity.ShareSessionQrCode, err error) {

might aswell keep the naming consistent "ShareSession" everywhere

return digitalidentity.GetShareQr(client.HTTPClient, qrCodeId, client.GetSdkID(), client.getAPIURL(), client.Key)
}
32 changes: 32 additions & 0 deletions digitalidentity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
const identitySessionCreationEndpoint = "/v2/sessions"
const identitySessionRetrieval = "/v2/sessions/%s"
const identitySessionQrCodeCreation = "/v2/sessions/%s/qr-codes"
const identitySessionQrCodeRetrieval = "/v2/qr-codes/%s"

// CreateShareSession creates session using the supplied session specification
func CreateShareSession(httpClient requests.HttpClient, shareSessionRequest *ShareSessionRequest, clientSdkId, apiUrl string, key *rsa.PrivateKey) (*ShareSession, error) {
Expand Down Expand Up @@ -113,3 +114,34 @@ func CreateShareQrCode(httpClient requests.HttpClient, sessionID string, clientS
err = json.Unmarshal(responseBytes, qrCode)
return qrCode, err
}

// Get Share QR info using the supplied sessionID
func GetShareQr(httpClient requests.HttpClient, sessionID string, clientSdkId, apiUrl string, key *rsa.PrivateKey) (share ShareSessionFetchedQrCode, err error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both the function and the comment use the wrong id. This is not the sessionId but the qrId from the qr code creation endpoint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

klaidas marked this conversation as resolved.
Show resolved Hide resolved
endpoint := fmt.Sprintf(identitySessionQrCodeRetrieval, sessionID)
headers := requests.AuthHeader(clientSdkId)
request, err := requests.SignedRequest{
Key: key,
HTTPMethod: http.MethodGet,
BaseURL: apiUrl,
Endpoint: endpoint,
Headers: headers,
}.Request()
if err != nil {
return share, err
}

response, err := requests.Execute(httpClient, request)
if err != nil {
return share, err
}
defer response.Body.Close()

responseBytes, err := io.ReadAll(response.Body)
if err != nil {
return share, err
}

err = json.Unmarshal(responseBytes, &share)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

share? This as instance of ShareSessionFetchedQrCode should be named accordinly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


return share, err
}
19 changes: 19 additions & 0 deletions digitalidentity/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,22 @@ func TestCreateQrCode(t *testing.T) {
_, err := CreateShareQrCode(client, mockSessionID, "sdkId", "https://apiurl", key)
assert.NilError(t, err)
}

func TestGetQrCode(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func TestGetQrCode(t *testing.T) {
func GetShareSessionQrCode(t *testing.T) {

key := test.GetValidKey("../test/test-key.pem")
mockQrId := "SOME_SESSION_ID"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SOME_QR_CODE_ID or similiar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

mockClientSdkId := "SOME_CLIENT_SDK_ID"
mockApiUrl := "https://example.com/api"
client := &mockHTTPClient{
do: func(*http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: 201,
Body: io.NopCloser(strings.NewReader(`{}`)),
}, nil
},
}

_, err := GetShareQr(client, mockQrId, mockClientSdkId, mockApiUrl, key)
assert.NilError(t, err)

}
10 changes: 10 additions & 0 deletions digitalidentity/share_retrieve_qr.go
klaidas marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package digitalidentity

type ShareSessionFetchedQrCode struct {
klaidas marked this conversation as resolved.
Show resolved Hide resolved
ID string `json:"id"`
Expiry string `json:"expiry"`
Policy string `json:"policy"`
Extensions []interface{} `json:"extensions"`
Session ShareSessionCreated `json:"session"`
klaidas marked this conversation as resolved.
Show resolved Hide resolved
RedirectURI string `json:"redirectUri"`
}
8 changes: 8 additions & 0 deletions digitalidentity/share_session_created.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package digitalidentity

// ShareSessionCreated Share Session QR Result
type ShareSessionCreated struct {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how GO architecture works but I'm pretty sure there is a way to reuse the response obj from the session creation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is, but the session object here is smaller than what's returned for session created - unless the api docs are mistaken?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have made this struct inline so i think this is now unnecessary

Copy link

@irotech irotech Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dunno what API u're referring to but both Session creation and QR fetch response (limited to the session) are

{
  "id": "",
  "status": "",
  "expiry": ""
}

where the full response for the QR fetch endpoint is

{
  "id": "",
  "expiry": "",
  "policy": "", 
  "extensions": [ ],
  "session": {
    "id": "",
    "status": "",
    "expiry": ""
  },
  "redirectUri": ""
}

would something like the below work?

type session struct {
	id 		string
	status  string
	expiry	string
}

type qr struct {
	id		string
	expiry 	string
	policy 	string
	session
	...
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you fetch the session, the session resource seems to be larger than what is returned in the fetch qr code response (what you posted), we could embed it and just have it unmarshal the whole thing, but some extra fields will just be empty for the RP, imo it's better to avoid it if the API itself specifically limits the fields and not give the RP any cause for confusion or incorrect expectations.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I thought I answered this but I must have not pushed the button. I meant this session created response

ID string `json:"id"`
Satus string `json:"status"`
klaidas marked this conversation as resolved.
Show resolved Hide resolved
Expiry string `json:"expiry"`
}
Loading