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-2254-go-create-qr-code #288

Merged
merged 62 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
9027db5
SDK-2254: updated tests
mehmet-yoti Oct 22, 2023
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
46993f4
SDK-2254 Resolved pr comments
mehmet-yoti Nov 1, 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
5506087
SDK-2254:updated pr changes
mehmet-yoti Nov 2, 2023
384a28b
SDK-2254 removed unused builder
mehmet-yoti Nov 5, 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
fb179ee
Merge pull request #290 from getyoti/SDK-2259-go-retrieve-qr-code
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ report.json

# Generated binaries
/_examples/docscan/docscan

/_examples/idv
klaidas marked this conversation as resolved.
Show resolved Hide resolved
Binary file added _examples/digitalidentity/digitalidentity
klaidas marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
19 changes: 19 additions & 0 deletions _examples/digitalidentity/yotiSelfSignedCert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDGzCCAgOgAwIBAgIRAMbPvzctr0qXtQ+ESN1qBz8wDQYJKoZIhvcNAQELBQAw
DzENMAsGA1UEChMEWW90aTAeFw0yMzEwMjQxODIzMThaFw0yNTEwMjMxODIzMTha
MA8xDTALBgNVBAoTBFlvdGkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
AQDCgg+gPT6qqZyafQPC/oTccns3GFq4pwIdyrGzP0kzSd5uxfMxNHW6Y/5qo1y0
b4+MJiF096EaVQRtrjhgOpJbDEKeMbCqIO8PEScAeJ5FwK1Cv1ZIENwd1+TfFAGj
IkdsBngbIjE0XhFTH1nAxMAvHcNNVwC0FDghJKtM24EuUJF+c3wEDcOZAYk9gWp4
Cacfn+kpQ9e1JtqopMMz6V0ufeG/eyCHsggQo9Bsej9/auGbzWcGnGBDVoUItaJt
Cbis7tANQjT+2yl8Bfqj0/b9a4fe+ogOWbBMuuswDoHLznzRC6f+yV6PuIJgguXb
2fa1Agss+btBObFZ8+0h9701AgMBAAGjcjBwMA4GA1UdDwEB/wQEAwICpDATBgNV
HSUEDDAKBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTQT4rA
SBLhypenYm4xD8JSQntlFjAZBgNVHREEEjAQgg4xMjcuMC4wLjE6ODA4MDANBgkq
hkiG9w0BAQsFAAOCAQEAcTV3inE9b9kzcP63CoREn23PDJeVFpaXsj57HSM4qxpS
bzNbspclKnEP5BIj8uRq8XaFILaQxXrvBLn6oF8aIOi230MqEg5IPP9m8zy/zm4K
Nm3vhzNF4avm20kgcccCgQlHw3n1AhDo+jDJy9t0B0FHNCdoM20tuQ7zog9Rr/3H
oQ3IoqwTP0ugLe9ww+qIHbS4XDdUcCaWmXR+ucN0w8AZIkkzQB/Va5GReWf3yXle
SulQ16qjjj5Pfx+W+obXdShpreDY+VYRnQNF31XYcIWssJTLk0gF/Ta98y+hbopY
YIyHMbl5EjXPP9T3OL7nh9ISLj/TBSGwUPhjS/tnvw==
-----END CERTIFICATE-----
27 changes: 27 additions & 0 deletions _examples/digitalidentity/yotiSelfSignedKey.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAwoIPoD0+qqmcmn0Dwv6E3HJ7NxhauKcCHcqxsz9JM0nebsXz
MTR1umP+aqNctG+PjCYhdPehGlUEba44YDqSWwxCnjGwqiDvDxEnAHieRcCtQr9W
SBDcHdfk3xQBoyJHbAZ4GyIxNF4RUx9ZwMTALx3DTVcAtBQ4ISSrTNuBLlCRfnN8
BA3DmQGJPYFqeAmnH5/pKUPXtSbaqKTDM+ldLn3hv3sgh7IIEKPQbHo/f2rhm81n
BpxgQ1aFCLWibQm4rO7QDUI0/tspfAX6o9P2/WuH3vqIDlmwTLrrMA6By8580Qun
/slej7iCYILl29n2tQILLPm7QTmxWfPtIfe9NQIDAQABAoIBAFAOdBwB2S8pDFnR
pqC1XT3WqLwue/iQVKCqcqVSIPDJMJHrS4MvEl2bFnYRsvBZEn4em5qm6VoLL/1s
vattsBtlWm3+CbacQ4iyCJl7C7mt6iIU2pBi0BZAa+UdOOdKDpd5uimA0zu4k+zg
dHKRCIDcASxt6M41nDyX+SFzHyJOMrM1ga/ZedxwumiQ2uot4Fl6q8Us0AJAglUU
7JtqTMYHTDvuuRwViwlO7PoIeIR+MeXkI3o+wSTV4cZux8LiwNMMGtdPFQkNyIpf
pvPl7bgf7XVHi6xj/ff5sHd1AgaCbrVhuZHCWuj4OAg34UvQ8e2yCgcVVY6QNIla
pWOoR+kCgYEAzlTDN1FuHy2ypWo80kpJVZMxqPqFHHp7XR6NlE9/2QX7rt/Zuo0d
hXrmC3RWkFffCC+GPcVH2yhlXDN7tRABQCg6N7eOJ6xb1aAqFb/bVnle1Cx5yKd7
0DOB5M23GmHGpxTvRm49R/Hm1QmTFcAP9+eIj4jXhggVSjY22TCqH6MCgYEA8VSy
tVuG0Uqno18lz9Jn79bYr4csUVxWcunvFCnWQgsf/L8RjHI2commjXpf+3zl7jm/
40llHYdL07ytoo++/0Sii4JPWnEWXXsXPGEbLS9vQapekofg1UKzM/dZYgcw4Thg
fuoe03LCRhiyt4fdrmk3R26c0hXNJ5g3Ges2nUcCgYAbjqSYEc8kaOUQRLUk3PkY
bdVXHUaD/DPXxwnfwhJwOOVZgNpCmTBVMInjA8G/+4x1OmuyelPTiHypKNMf5qhU
GktUP7bDw7hsOr0ENKCl1wX8TohhbUUTFJ4HohYPdvmiPSCMBpM2ta8/ysyTPhij
4o+RpBQs+Y1mYQFIVsCSAwKBgQC4W3y94LKoFcDkpB4Nme2+ocEcrkWjzcdYt+7k
12UPRNJl0UzFnsaLTy6F69OBGhPIniNBrWLqYN4DXaLDic5d0X/e1WhrbfKo7Qx+
GqyZIyB56H2gsN6H7BFcBHwqz9V+aAQHUDDGVWemBt4YKFmoEEajchOoxfDYa4bE
bRRmpwKBgBFYFBs5dIqylXamLjuWRt6V2kBDmaxE/CnlzlJcYXK/UaUo5l5qvjvf
oiGTXm/G5UPhwh7/EqPr1gG9w+KRuhHIftji+7Idws0Wz4DqOPkj43oFXIlAfSoJ
Q4xVrO85PhSIhlNdvTz1W1XGmFjTLN7tXOiDHJhlMZoPD/JkocmS
-----END RSA PRIVATE KEY-----
2 changes: 2 additions & 0 deletions _examples/idv/handlers.session.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"os"

"github.com/getyoti/yoti-go-sdk/v3"
"github.com/getyoti/yoti-go-sdk/v3/docscan"
"github.com/getyoti/yoti-go-sdk/v3/docscan/session/create"
"github.com/gin-gonic/gin"
Expand All @@ -21,6 +22,7 @@ var (
key []byte
client *docscan.Client
createSessionResult *create.SessionResult
didClient *yoti.DigitalIdentityClient
klaidas marked this conversation as resolved.
Show resolved Hide resolved
)

func showIndexPage(c *gin.Context) {
Expand Down
5 changes: 5 additions & 0 deletions digital_identity_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,8 @@ func (client *DigitalIdentityClient) CreateShareSession(shareSessionRequest *dig
func (client *DigitalIdentityClient) GetShareSession(sessionID string) (*digitalidentity.ShareSession, error) {
return digitalidentity.GetShareSession(client.HTTPClient, sessionID, client.GetSdkID(), client.getAPIURL(), client.Key)
}

// Create a sharing session QR code to initiate a sharing process based on session ID
klaidas marked this conversation as resolved.
Show resolved Hide resolved
func (client *DigitalIdentityClient) CreateShareQrCode(sessionID string) (share *digitalidentity.QrCode, err error) {
return digitalidentity.CreateShareQrCode(client.HTTPClient, sessionID, client.GetSdkID(), client.getAPIURL(), client.Key)
}
33 changes: 33 additions & 0 deletions digitalidentity/create_qr_code_builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package digitalidentity

import (
"encoding/json"
)

// ShareSessionBuilder builds a session
type CreateShareQrCodeBuilder struct {
createShareQrCode CreateShareQrCodeResult
err error
}

// ShareSession represents a sharesession
type CreateShareQrCodeResult struct {
id string
uri string
}

// Build constructs the ShareSession
func (builder *CreateShareQrCodeBuilder) Build() (CreateShareQrCodeResult, error) {
return builder.createShareQrCode, builder.err
}

// MarshalJSON returns the JSON encoding
func (createShareQrCode CreateShareQrCodeResult) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Id string `json:"id"`
Uri string `json:"uri"`
}{
Id: createShareQrCode.id,
Uri: createShareQrCode.uri,
})
}
klaidas marked this conversation as resolved.
Show resolved Hide resolved
73 changes: 73 additions & 0 deletions digitalidentity/create_qr_code_builder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package digitalidentity

import (
"encoding/json"
"fmt"
"testing"
)

func TestCreateShareQrCodeBuilder_Build(t *testing.T) {
expectedID := "SOME_ID"
expectedURI := "https://example.com/qr"

builder := CreateShareQrCodeBuilder{
createShareQrCode: CreateShareQrCodeResult{
id: expectedID,
uri: expectedURI,
},
}

result, err := builder.Build()

if err != nil {
t.Errorf("Expected no error, but got: %v", err)
}
if result.id != expectedID {
t.Errorf("Expected ID: %s, but got: %s", expectedID, result.id)
}
if result.uri != expectedURI {
t.Errorf("Expected URI: %s, but got: %s", expectedURI, result.uri)
}
}

func TestCreateShareQrCode_MarshalJSON(t *testing.T) {
createShareQrCode := CreateShareQrCodeResult{
id: "SOME_ID",
uri: "https://example.com/qr",
}

expectedJSON := `{"id":"SOME_ID","uri":"https://example.com/qr"}`

resultJSON, err := json.Marshal(createShareQrCode)
if err != nil {
t.Errorf("Expected no error, but got: %v", err)
}
if string(resultJSON) != expectedJSON {
t.Errorf("Expected JSON:\n%s\nbut got:\n%s\n", expectedJSON, string(resultJSON))
}
}

func ExampleCreateShareQrCodeBuilder_Build() {
builder := CreateShareQrCodeBuilder{
createShareQrCode: CreateShareQrCodeResult{
id: "SOME_ID",
uri: "https://example.com/qr",
},
}

result, err := builder.Build()

if err != nil {
fmt.Printf("Error: %v\n", err)
return
}

data, err := json.Marshal(result)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}

fmt.Println(string(data))
// Output: {"id":"SOME_ID","uri":"https://example.com/qr"}
irotech marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 6 additions & 0 deletions digitalidentity/qr_code.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package digitalidentity

type QrCode struct {
Id string `json:"id"`
Uri string `json:"uri"`
}
33 changes: 33 additions & 0 deletions digitalidentity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

const identitySessionCreationEndpoint = "/v2/sessions"
const identitySessionRetrieval = "/v2/sessions/%s"
const identitySessionQrCodeCreation = "/v2/sessions/%s/qr-codes"

// 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 @@ -80,3 +81,35 @@ func GetShareSession(httpClient requests.HttpClient, sessionID string, clientSdk
err = json.Unmarshal(responseBytes, shareSession)
return shareSession, err
}

// CreateShareQrCode generates a sharing qr code using the supplied sessionID parameter
func CreateShareQrCode(httpClient requests.HttpClient, sessionID string, clientSdkId, apiUrl string, key *rsa.PrivateKey) (*QrCode, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think it's missing a request body https://lampkicking.atlassian.net/wiki/spaces/CON/pages/3756458012/Share+v2+Flows#QR-Code-Creation it looks like it accepts some extra fields:

POST /v2/sessions/:sessionId/qr-codes

{
  "transport": "",     // optional - default is 'QR_CODE'
  "displayMode": ""    // optional - default is 'INLINE'
}

no idea what the accepted values are or if we should give clients a list of possible values, it's not documented there or in the ticket

Copy link

Choose a reason for hiding this comment

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

Java and Node SDK send empty JSON for this endpoint so the server-side defaults are used

Copy link
Collaborator

Choose a reason for hiding this comment

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

umm ok, happy to be consistent with other sdks, just curious why it's even an option if we won't expose these options to the RP

endpoint := fmt.Sprintf(identitySessionQrCodeCreation, sessionID)

request, err := requests.SignedRequest{
Key: key,
HTTPMethod: http.MethodPost,
BaseURL: apiUrl,
Endpoint: endpoint,
Headers: requests.AuthHeader(clientSdkId),
Body: nil,
Params: map[string]string{"sdkID": clientSdkId},
}.Request()
if err != nil {
return nil, err
}

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

defer response.Body.Close()
qrCode := &QrCode{}
responseBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(responseBytes, qrCode)
return qrCode, err
}
17 changes: 17 additions & 0 deletions digitalidentity/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,20 @@ func TestGetShareSession(t *testing.T) {
assert.NilError(t, err)

}

func TestCreateShareQrCode(t *testing.T) {
key := test.GetValidKey("../test/test-key.pem")
mockSessionID := "SOME_SESSION_ID"

client := &mockHTTPClient{
do: func(*http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: 201,
Body: io.NopCloser(strings.NewReader(`{}`)),
}, nil
},
}

_, err := CreateShareQrCode(client, mockSessionID, "sdkId", "https://apiurl", key)
assert.NilError(t, err)
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ require (
gotest.tools/v3 v3.3.0
)

require github.com/google/go-cmp v0.5.5 // indirect

require github.com/google/go-cmp v0.5.5 // indirect

go 1.19
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/fzipp/gocyclo v0.6.0 h1:lsblElZG7d3ALtGMx9fmxeTKZaLLpU8mET09yN4BBLo=
github.com/fzipp/gocyclo v0.6.0/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down
Loading