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 17 commits
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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ report.json
# idea files
.idea

# Generated binaries
/_examples/docscan/docscan

8 changes: 8 additions & 0 deletions _examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
.env
# Generated binaries
docscan/docscan
idv/idv
aml/aml
docscansandbox/docscansandbox
profile/profile
profilesandbox/profilesandbox
digitalidentity/digitalidentity
84 changes: 0 additions & 84 deletions _examples/idv/handlers.session.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package main

import (
"encoding/json"
"errors"
"fmt"
"net/http"
"os"

"github.com/getyoti/yoti-go-sdk/v3"
"github.com/getyoti/yoti-go-sdk/v3/digitalidentity"
"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 @@ -24,7 +21,6 @@ var (
key []byte
client *docscan.Client
createSessionResult *create.SessionResult
didClient *yoti.DigitalIdentityClient
)

func showIndexPage(c *gin.Context) {
Expand Down Expand Up @@ -212,83 +208,3 @@ func showPrivacyPolicyPage(c *gin.Context) {
render(c, gin.H{}, "privacy.html")
return
}

/* For Testing */

func showDigitalPage(c *gin.Context) {
sessionReq, err := buildDigitalIdentitySessionReq()
if err != nil {
c.HTML(
http.StatusInternalServerError,
"error.html",
gin.H{
"ErrorTitle": "Error when building sessions spec",
"ErrorMessage": err.Error()})
return
}
pageFromShareSessionReq(c, sessionReq)
}

func initialiseDigitalIdentityClient() error {
var err error
sdkID = os.Getenv("YOTI_CLIENT_SDK_ID")
keyFilePath := os.Getenv("YOTI_KEY_FILE_PATH")
key, err = os.ReadFile(keyFilePath)
if err != nil {
return fmt.Errorf("failed to get key from YOTI_KEY_FILE_PATH :: %w", err)
}

didClient, err = yoti.NewDigitalIdentityClient(sdkID, key)
if err != nil {
return fmt.Errorf("failed to initialise Share client :: %w", err)
}
//didClient.OverrideAPIURL("https://connect.public.stg1.dmz.yoti.com/share/")
didClient.OverrideAPIURL("https://api.yoti.com/share")

return nil
}

func pageFromShareSessionReq(c *gin.Context, sessionReq *digitalidentity.ShareSessionRequest) {
err := initialiseDigitalIdentityClient()
if err != nil {
c.HTML(
http.StatusUnprocessableEntity,
"error.html",
gin.H{
"ErrorTitle": "Error initialising DID Client",
"ErrorMessage": errors.Unwrap(err)})
return
}
b, err := json.Marshal(sessionReq)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(b))

shareSession, err := didClient.CreateShareSession(sessionReq)

createQr, err := didClient.CreateShareQrCode(shareSession.Id)

b, err = json.Marshal(createQr)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(b))

if err != nil {
c.HTML(
http.StatusInternalServerError,
"error.html",
gin.H{
"ErrorTitle": "Error when creating Share session",
"ErrorMessage": err.Error()})
return
}

c.SetCookie("session_id", shareSession.Id, 60*20, "/", "localhost", true, false)
return
}

/* For Testing */
Binary file removed _examples/idv/idv
Binary file not shown.
28 changes: 0 additions & 28 deletions _examples/idv/models.sessionspec.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package main

import (
"encoding/json"
"time"

"github.com/getyoti/yoti-go-sdk/v3/digitalidentity"
"github.com/getyoti/yoti-go-sdk/v3/docscan/session/create"
"github.com/getyoti/yoti-go-sdk/v3/docscan/session/create/check"
"github.com/getyoti/yoti-go-sdk/v3/docscan/session/create/filter"
Expand Down Expand Up @@ -214,29 +212,3 @@ func buildDBSSessionSpec() (sessionSpec *create.SessionSpecification, err error)
}
return sessionSpec, nil
}

/* For Testing */
func buildDigitalIdentitySessionReq() (sessionSpec *digitalidentity.ShareSessionRequest, err error) {
identityProfile := json.RawMessage(`{
"trust_framework": "UK_TFIDA",
"scheme": {
"type": "RTW"
}
}`)
policy, err := (&digitalidentity.PolicyBuilder{}).WithIdentityProfileRequirements(identityProfile).Build()
if err != nil {
return nil, err
}

subject := []byte(`{
"subject_id": "unique-user-id-for-examples"
}`)

sessionReq, err := (&digitalidentity.ShareSessionRequestBuilder{}).WithPolicy(policy).WithRedirectUri("https:/www.yoti.com").WithSubject(subject).Build()
if err != nil {
return nil, err
}
return &sessionReq, nil
}

/* For Testing */
3 changes: 0 additions & 3 deletions _examples/idv/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@ func initializeRoutes() {
router.GET("/success", showSuccessPage)
router.GET("/media", getMedia)
router.GET("/privacy-policy", showPrivacyPolicyPage)
/* For Testing */
router.GET("/digital-identity", showDigitalPage)
/* For Testing */
}
7 changes: 6 additions & 1 deletion digital_identity_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ func (client *DigitalIdentityClient) GetShareSession(sessionID string) (*digital
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
// CreateShareQrCode generates a sharing session QR code to initiate a sharing process based on session ID
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.ShareSessionQrCode, err error) {
Comment on lines +80 to +81
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.ShareSessionQrCode, err error) {
// GetShareSessionQrCode retrieves a session QR code based on generated Qr ID
func (client *DigitalIdentityClient) GetShareSessionQrCode(qrCodeId string) (share digitalidentity.ShareSessionQrCode, err error) {

comment + func name (i haven't checked other sdks so happy to just have it all align with whatever they have)

return digitalidentity.GetShareSessionQrCode(client.HTTPClient, qrCodeId, client.GetSdkID(), client.getAPIURL(), client.Key)
}
33 changes: 0 additions & 33 deletions digitalidentity/create_qr_code_builder.go

This file was deleted.

73 changes: 0 additions & 73 deletions digitalidentity/create_qr_code_builder_test.go

This file was deleted.

34 changes: 33 additions & 1 deletion 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 @@ -82,7 +83,7 @@ func GetShareSession(httpClient requests.HttpClient, sessionID string, clientSdk
return shareSession, err
}

// CreateQrCode using the supplied sessionID parameter
// 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) {
endpoint := fmt.Sprintf(identitySessionQrCodeCreation, sessionID)

Expand Down Expand Up @@ -113,3 +114,34 @@ func CreateShareQrCode(httpClient requests.HttpClient, sessionID string, clientS
err = json.Unmarshal(responseBytes, qrCode)
return qrCode, err
}

// GetShareSessionQrCode is used to fetch the qr code by id.
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
// GetShareSessionQrCode is used to fetch the qr code by id.
// GetShareSessionQrCode is used to fetch the qr code by id.

extra space

func GetShareSessionQrCode(httpClient requests.HttpClient, qrCodeId string, clientSdkId, apiUrl string, key *rsa.PrivateKey) (fetchedQrCode ShareSessionQrCode, err error) {
endpoint := fmt.Sprintf(identitySessionQrCodeRetrieval, qrCodeId)
headers := requests.AuthHeader(clientSdkId)
request, err := requests.SignedRequest{
Key: key,
HTTPMethod: http.MethodGet,
BaseURL: apiUrl,
Endpoint: endpoint,
Headers: headers,
}.Request()
if err != nil {
return fetchedQrCode, err
}

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

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

err = json.Unmarshal(responseBytes, &fetchedQrCode)

return fetchedQrCode, err
}
21 changes: 20 additions & 1 deletion digitalidentity/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestGetShareSession(t *testing.T) {

}

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

Expand All @@ -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_QR_CODE_ID"
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 := GetShareSessionQrCode(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
Loading