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 5 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: 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
82 changes: 0 additions & 82 deletions _examples/idv/handlers.session.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
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 Down Expand Up @@ -212,83 +210,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 */
}
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.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)
}
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)

}
14 changes: 14 additions & 0 deletions digitalidentity/share_session_qr_code.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package digitalidentity

type ShareSessionQrCode struct {
ID string `json:"id"`
Expiry string `json:"expiry"`
Policy string `json:"policy"`
Extensions []interface{} `json:"extensions"`
Session struct {
ID string `json:"id"`
Status string `json:"status"`
Expiry string `json:"expiry"`
} `json:"session"`
RedirectURI string `json:"redirectUri"`
}
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