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 2246 go retrieve session #282

Merged
merged 44 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0a7667c
SDK-2240:fixed multiple error vars
mehmet-yoti Jul 20, 2023
8825126
SDK-2246:go retrieve session
mehmet-yoti Aug 8, 2023
82b3fc9
SDK-2246:go retrieve session update
mehmet-yoti Aug 8, 2023
b326008
SDK-2246:Resolved Problems
mehmet-yoti Aug 22, 2023
c30c85b
SDK-2246:Resolved Problems
mehmet-yoti Aug 22, 2023
d0f8123
SDK-2246:update review changes
mehmet-yoti Aug 29, 2023
f0be59e
SDK-2246:removed buildDigitalIdentitySessionSpec
mehmet-yoti Aug 30, 2023
f6de789
Update digitalidentity/service_test.go
mehmet-yoti Aug 31, 2023
dc8aeb7
Update digitalidentity/share_session.go
mehmet-yoti Aug 31, 2023
3d92450
Update digital_identity_client.go
mehmet-yoti Aug 31, 2023
391b925
Update digital_identity_client.go
mehmet-yoti Aug 31, 2023
49a758c
SDK-2246 refactor needed changes
mehmet-yoti Sep 6, 2023
bdda8e4
SDK-2246 refactor needed changes
mehmet-yoti Sep 6, 2023
d011b02
Update digitalidentity/share_session.go
mehmet-yoti Sep 6, 2023
6f5d220
Update digitalidentity/share_session.go
mehmet-yoti Sep 6, 2023
8b2a670
Update digitalidentity/service.go
mehmet-yoti Sep 6, 2023
ade2267
Update digitalidentity/service.go
mehmet-yoti Sep 6, 2023
9fe3f6c
Update digital_identity_client.go
mehmet-yoti Sep 6, 2023
8c88429
Update digital_identity_client.go
mehmet-yoti Sep 6, 2023
4a9ff75
SDK-2246 refactor needed changes
mehmet-yoti Sep 6, 2023
ca50060
SDK-2246 update tests and httpstatus codes
mehmet-yoti Sep 8, 2023
787a94b
SDK-2246 update tests and httpstatus codes
mehmet-yoti Sep 8, 2023
198f704
SDK-2246 update tests and httpstatus codes
mehmet-yoti Sep 8, 2023
f86f324
Update digital_identity_client_test.go
mehmet-yoti Sep 14, 2023
fdce2b6
SDK-2226:refactor some code
mehmet-yoti Sep 14, 2023
95eb7c5
SDK-2226:refactor some code
mehmet-yoti Sep 19, 2023
3ddcb2c
SDK-2226:refactor some code
mehmet-yoti Sep 19, 2023
51f50dc
SDK-2246:refactoring
mehmet-yoti Sep 25, 2023
2591663
SDK-2246 bug fix on create session
mehmet-yoti Sep 25, 2023
565204d
SDK-2246 Cleared commented lines
mehmet-yoti Sep 26, 2023
0fa3553
SDK-2246 updated optional parameters
mehmet-yoti Sep 27, 2023
3321f3e
SDK-2246 updated optional parameters
mehmet-yoti Sep 27, 2023
c7d96fc
SDK-2246 updated optional parameters
mehmet-yoti Sep 27, 2023
c4c3290
SDK-2246 removed unnecessary files
mehmet-yoti Sep 27, 2023
004d711
SDK-2246 updated tests to match with optional values
mehmet-yoti Sep 27, 2023
edf368c
SDK-2246 add updated test file
mehmet-yoti Sep 27, 2023
9d43a02
SDK:2246 update sonar properties
mehmet-yoti Oct 6, 2023
d99947b
SDK:2246 update sonar properties
mehmet-yoti Oct 6, 2023
1c74f09
SDK-2246: added digitalidentity specific request and yotierr to handl…
Oct 11, 2023
aad8d97
SDK-2246:pr updates
mehmet-yoti Oct 12, 2023
75fe18e
Update digitalidentity/share_session_builder.go
mehmet-yoti Oct 13, 2023
6566ede
Update digitalidentity/yotierror/response.go
mehmet-yoti Oct 13, 2023
fba5a14
SDK-2246:updates for pr checks
mehmet-yoti Oct 13, 2023
0df76b0
SDK-2246:updates for pr checks
mehmet-yoti Oct 13, 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
53 changes: 53 additions & 0 deletions _examples/idv/models.sessionspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,56 @@ func buildDBSSessionSpec() (sessionSpec *create.SessionSpecification, err error)
}
return sessionSpec, nil
}

func buildDigitalIdentitySessionSpec() (sessionSpec *create.SessionSpecification, err error) {
fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
var sdkConfig *create.SDKConfig
sdkConfig, err = create.NewSdkConfigBuilder().
WithAllowsCameraAndUpload().
WithPrimaryColour("#2d9fff").
WithSecondaryColour("#FFFFFF").
WithFontColour("#FFFFFF").
WithLocale("en-GB").
WithPresetIssuingCountry("GBR").
WithSuccessUrl("https://localhost:8080/success").
WithErrorUrl("https://localhost:8080/error").
WithPrivacyPolicyUrl("https://localhost:8080/privacy-policy").
Build()
if err != nil {
return nil, err
}

identityProfile := []byte(`{
"trust_framework": "UK_TFIDA",
"scheme": {
"type": "RTW"
}
}`)

ttl := time.Hour * 24 * 30
importToken, err := create.NewImportTokenBuilder().
WithTTL(int(ttl.Seconds())).
Build()
if err != nil {
return nil, err
}

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

sessionSpec, err = create.NewSessionSpecificationBuilder().
WithClientSessionTokenTTL(6000).
WithResourcesTTL(900000).
WithUserTrackingID("some-tracking-id").
WithSDKConfig(sdkConfig).
WithIdentityProfileRequirements(identityProfile).
WithCreateIdentityProfilePreview(true).
WithSubject(subject).
WithImportToken(importToken).
Build()

if err != nil {
return nil, err
}
return sessionSpec, nil
}
1 change: 1 addition & 0 deletions _examples/idv/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ func initializeRoutes() {
router.GET("/success", showSuccessPage)
router.GET("/media", getMedia)
router.GET("/privacy-policy", showPrivacyPolicyPage)
router.GET("/digital-identity", showDigitalPage)
fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
}
30 changes: 15 additions & 15 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func (mock *mockHTTPClient) Do(request *http.Request) (*http.Response, error) {
}

func TestNewClient(t *testing.T) {
key, readErr := os.ReadFile("./test/test-key.pem")
assert.NilError(t, readErr)
key, err := os.ReadFile("./test/test-key.pem")
assert.NilError(t, err)

_, err := NewClient("some-sdk-id", key)
_, err = NewClient("some-sdk-id", key)
assert.NilError(t, err)
}

Expand All @@ -48,11 +48,11 @@ func TestNewClient_KeyLoad_Failure(t *testing.T) {
}

func TestYotiClient_PerformAmlCheck(t *testing.T) {
key, readErr := os.ReadFile("./test/test-key.pem")
assert.NilError(t, readErr)
key, err := os.ReadFile("./test/test-key.pem")
assert.NilError(t, err)

client, clientErr := NewClient("some-sdk-id", key)
assert.NilError(t, clientErr)
client, err := NewClient("some-sdk-id", key)
assert.NilError(t, err)

client.HTTPClient = &mockHTTPClient{
do: func(*http.Request) (*http.Response, error) {
Expand All @@ -78,11 +78,11 @@ func TestYotiClient_PerformAmlCheck(t *testing.T) {
}

func TestYotiClient_CreateShareURL(t *testing.T) {
key, readErr := os.ReadFile("./test/test-key.pem")
assert.NilError(t, readErr)
key, err := os.ReadFile("./test/test-key.pem")
assert.NilError(t, err)

client, clientErr := NewClient("some-sdk-id", key)
assert.NilError(t, clientErr)
client, err := NewClient("some-sdk-id", key)
assert.NilError(t, err)

client.HTTPClient = &mockHTTPClient{
do: func(*http.Request) (*http.Response, error) {
Expand All @@ -93,11 +93,11 @@ func TestYotiClient_CreateShareURL(t *testing.T) {
},
}

policy, policyErr := (&dynamic.PolicyBuilder{}).WithFullName().WithWantedRememberMe().Build()
assert.NilError(t, policyErr)
policy, err := (&dynamic.PolicyBuilder{}).WithFullName().WithWantedRememberMe().Build()
assert.NilError(t, err)

scenario, scenarioErr := (&dynamic.ScenarioBuilder{}).WithPolicy(policy).Build()
assert.NilError(t, scenarioErr)
scenario, err := (&dynamic.ScenarioBuilder{}).WithPolicy(policy).Build()
assert.NilError(t, err)

result, err := client.CreateShareURL(&scenario)
assert.NilError(t, err)
Expand Down
15 changes: 10 additions & 5 deletions digital_identity_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/getyoti/yoti-go-sdk/v3/requests"
)

const DefaultURL = "https://api.yoti.com/api/"
const DefaultURL = "https://api.yoti.com/share/"

// DigitalIdentityClient represents a client that can communicate with yoti and return information about Yoti users.
type DigitalIdentityClient struct {
Expand All @@ -27,14 +27,14 @@ type DigitalIdentityClient struct {
}

// NewDigitalIdentityClient constructs a Client object
func NewDigitalIdentityClient(sdkID string, key []byte) (*Client, error) {
func NewDigitalIdentityClient(sdkID string, key []byte) (*DigitalIdentityClient, error) {
decodedKey, err := cryptoutil.ParseRSAKey(key)

if err != nil {
return nil, err
}

return &Client{
return &DigitalIdentityClient{
SdkID: sdkID,
Key: decodedKey,
}, err
Expand All @@ -54,7 +54,7 @@ func (client *DigitalIdentityClient) getAPIURL() string {
return value
}

return apiDefaultURL
return DefaultURL
}

// GetSdkID gets the Client SDK ID attached to this client instance
Expand All @@ -63,6 +63,11 @@ func (client *DigitalIdentityClient) GetSdkID() string {
}

// CreateShareURL creates a QR code for a specified share session configuration.
func (client *DigitalIdentityClient) CreateShareURL(shareSession *digitalidentity.ShareSession) (share digitalidentity.ShareURL, err error) {
func (client *DigitalIdentityClient) CreateShareSession(shareSession *digitalidentity.ShareSession) (share digitalidentity.SessionResult, err error) {
fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
return digitalidentity.CreateShareSession(client.HTTPClient, shareSession, client.GetSdkID(), client.getAPIURL(), client.Key)
}

// getSession creates a QR code for a specified share session configuration.
func (client *DigitalIdentityClient) GetSession(sessionID string) (share digitalidentity.ShareSessionResult, err error) {
fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
return digitalidentity.GetSession(client.HTTPClient, sessionID, client.GetSdkID(), client.getAPIURL(), client.Key)
}
38 changes: 10 additions & 28 deletions digital_identity_client_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package yoti

import (
"io"
"net/http"
"fmt"
"os"
"strings"
"testing"

"github.com/getyoti/yoti-go-sdk/v3/dynamic"
"github.com/getyoti/yoti-go-sdk/v3/digitalidentity"
"gotest.tools/v3/assert"
)

func TestDigitalIDClient(t *testing.T) {
key, readErr := os.ReadFile("./test/test-key.pem")
assert.NilError(t, readErr)
key, err := os.ReadFile("./test/test-key.pem")
assert.NilError(t, err)

_, err := NewDigitalIdentityClient("some-sdk-id", key)
_, err = NewDigitalIdentityClient("some-sdk-id", key)
assert.NilError(t, err)
}

Expand All @@ -34,28 +32,12 @@ func TestDigitalIDClient_KeyLoad_Failure(t *testing.T) {
}

func TestDigitalIDClient_CreateShareURL(t *testing.T) {
key, readErr := os.ReadFile("./test/test-key.pem")
assert.NilError(t, readErr)

client, clientErr := NewDigitalIdentityClient("some-sdk-id", key)
assert.NilError(t, clientErr)

client.HTTPClient = &mockHTTPClient{
do: func(*http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: 201,
Body: io.NopCloser(strings.NewReader(`{"qrcode":"https://code.yoti.com/some-qr","ref_id":"0"}`)),
}, nil
},
}

policy, policyErr := (&dynamic.PolicyBuilder{}).WithFullName().WithWantedRememberMe().Build()
assert.NilError(t, policyErr)

scenario, scenarioErr := (&dynamic.ScenarioBuilder{}).WithPolicy(policy).Build()
assert.NilError(t, scenarioErr)
policy, err := (&digitalidentity.PolicyBuilder{}).WithFullName().WithWantedRememberMe().Build()
fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
assert.NilError(t, err)

result, err := client.CreateShareURL(&scenario)
session, err := (&digitalidentity.ShareSessionBuilder{}).WithPolicy(policy).Build()
assert.NilError(t, err)
assert.Equal(t, result.ShareURL, "https://code.yoti.com/some-qr")
fmt.Println(session)

}
42 changes: 39 additions & 3 deletions digitalidentity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
"github.com/getyoti/yoti-go-sdk/v3/yotierror"
)

const identitySesssionCreationEndpoint = "/v2/sessions"
const identitySesssionCreationEndpoint = "v2/sessions"
mehmet-yoti marked this conversation as resolved.
Show resolved Hide resolved
const identitySessionRetrieval = "v2/sessions/%s"

// SessionResult contains the information about a created session
type SessionResult struct {
Expand All @@ -20,26 +21,61 @@ type SessionResult struct {
}

// CreateShareSession creates session using the supplied session specification
func CreateShareSession(httpClient requests.HttpClient, shareSession *ShareSession, clientSdkId, apiUrl string, key *rsa.PrivateKey) (share ShareURL, err error) {
func CreateShareSession(httpClient requests.HttpClient, shareSession *ShareSession, clientSdkId, apiUrl string, key *rsa.PrivateKey) (share SessionResult, err error) {
fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
endpoint := identitySesssionCreationEndpoint

payload, err := shareSession.MarshalJSON()
if err != nil {
return share, err
}

headers := requests.AuthHeader(clientSdkId)

request, err := requests.SignedRequest{
Key: key,
HTTPMethod: http.MethodPost,
BaseURL: apiUrl,
Endpoint: endpoint,
Headers: nil,
Headers: headers,
fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
Body: payload,
}.Request()
if err != nil {
return share, err
}

response, err := requests.Execute(httpClient, request, ShareURLHTTPErrorMessages, yotierror.DefaultHTTPErrorMessages)
fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
//fmt.Printf("err 2:=> %s\n\r", err)
fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
return share, err
}

defer response.Body.Close()

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

err = json.Unmarshal(responseBytes, &share)

return share, err
}

// GetSession get session info using the supplied sessionID
func GetSession(httpClient requests.HttpClient, sessionID string, clientSdkId, apiUrl string, key *rsa.PrivateKey) (share ShareSessionResult, err error) {
fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
endpoint := identitySesssionCreationEndpoint
fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
mehmet-yoti marked this conversation as resolved.
Show resolved Hide resolved
headers := requests.AuthHeader(clientSdkId)
request, err := requests.SignedRequest{
Key: key,
HTTPMethod: http.MethodGet,
BaseURL: apiUrl,
Endpoint: endpoint,
Headers: headers,
fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
}.Request()
if err != nil {
return share, err
}

fofiuiancu marked this conversation as resolved.
Show resolved Hide resolved
response, err := requests.Execute(httpClient, request, ShareURLHTTPErrorMessages, yotierror.DefaultHTTPErrorMessages)
if err != nil {
return share, err
Expand Down
Loading
Loading