Skip to content

Commit

Permalink
Merge pull request #291 from getyoti/WAS-611-AdvancedIdentityProfile
Browse files Browse the repository at this point in the history
SDK-2379: added support for Advanced Identity Profile Requirements for idv and share v1
  • Loading branch information
klaidas authored Nov 8, 2023
2 parents 86fe48f + 791cfde commit fbd5d03
Show file tree
Hide file tree
Showing 16 changed files with 1,058 additions and 52 deletions.
14 changes: 14 additions & 0 deletions _examples/idv/handlers.session.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ func showDBSPage(c *gin.Context) {
pageFromSessionSpec(c, sessionSpec)
}

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

func pageFromSessionSpec(c *gin.Context, sessionSpec *create.SessionSpecification) {
err := initialiseDocScanClient()
if err != nil {
Expand Down
56 changes: 56 additions & 0 deletions _examples/idv/models.sessionspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,59 @@ func buildDBSSessionSpec() (sessionSpec *create.SessionSpecification, err error)

return sessionSpec, nil
}

func buildAdvancedIdentityProfileSessionSpec() (sessionSpec *create.SessionSpecification, err error) {
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
}

advancedIdentityProfile := []byte(`{
"profiles": [
{
"trust_framework": "UK_TFIDA",
"schemes": [
{
"label": "LB912",
"type": "RTW"
}
]
},
{
"trust_framework": "YOTI_GLOBAL",
"schemes": [
{
"label": "LB321",
"type": "IDENTITY",
"objective": "AL_L1"
}
]
}
]
}`)

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

return create.NewSessionSpecificationBuilder().
WithClientSessionTokenTTL(6000).
WithResourcesTTL(900000).
WithUserTrackingID("some-tracking-id").
WithSDKConfig(sdkConfig).
WithAdvancedIdentityProfileRequirements(advancedIdentityProfile).
WithCreateIdentityProfilePreview(true).
WithSubject(subject).
Build()
}
1 change: 1 addition & 0 deletions _examples/idv/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ func initializeRoutes() {
// Handle the index route
router.GET("/", showIndexPage)
router.GET("/dbs", showDBSPage)
router.GET("/advanced", showAdvancedIdentityProfilePage)
router.GET("/success", showSuccessPage)
router.GET("/media", getMedia)
router.GET("/privacy-policy", showPrivacyPolicyPage)
Expand Down
66 changes: 59 additions & 7 deletions _examples/idv/templates/success.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,35 @@ <h2>Identity Profile</h2>
{{ end }}
{{ end }}
{{ end }}
{{ if .getSessionResult.AdvancedIdentityProfileResponse }}
<div class="row pt-4">
<div class="col">
<h2>Advanced Identity Profile</h2>
</div>
</div>
{{ $media := index .getSessionResult.AdvancedIdentityProfileResponse.Report "media"}}
{{ if $media }}
{{ $media_id := index $media "id" }}
{{ if $media_id }}
<div class="row pt-4">
<div class="col">
<table class="table table-striped table-light">
<tbody>
<tr>
<td>ID</td>
<td>
<a href='/media?mediaId={{ $media_id }}'>
{{ $media_id }}
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
{{ end }}
{{ end }}
{{ end }}
{{ if .getSessionResult.IdentityProfilePreview }}
<div class="row pt-4">
<div class="col">
Expand All @@ -99,6 +128,29 @@ <h2>Identity Profile Preview</h2>
</div>
</div>
{{ end }}
{{ if .getSessionResult.AdvancedIdentityProfilePreview }}
<div class="row pt-4">
<div class="col">
<h2>Advanced Identity Profile Preview</h2>
</div>
</div>
<div class="row pt-4">
<div class="col">
<table class="table table-striped table-light">
<tbody>
<tr>
<td>ID</td>
<td>
<a href='/media?mediaId={{ .getSessionResult.AdvancedIdentityProfilePreview.Media.ID }}'>
{{ .getSessionResult.AdvancedIdentityProfilePreview.Media.ID }}
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
{{ end }}
{{ if .getSessionResult.ImportTokenResponse }}
<div class="row pt-4">
<div class="col">
Expand Down Expand Up @@ -777,15 +829,15 @@ <h2>Static Liveness Resources</h2>
<tr>
<td>ID</td>
<td>{{ $liveness.ID }}

</td>
</tr>

</tbody>
</table>

<div class="accordion mt-3">

<div class="card">
<div class="card-header" id="liveness-{{ $livenessNum }}-frames">
<h3 class="mb-0">
Expand All @@ -800,18 +852,18 @@ <h3 class="mb-0">
<div id="collapse-liveness-{{ $livenessNum }}-frames" class="collapse"
aria-labelledby="liveness-{{ $livenessNum }}-frames">
<div class="card-group">

<div class="card">
<img class="card-img-top"
src="/media?mediaId={{ $liveness.Image.Media.ID }}"/>
</div>

</div>
</div>
</div>

</div>

</div>
</div>
{{ end }}
Expand Down
65 changes: 65 additions & 0 deletions _examples/profile/advancedIdentityProfile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package main

import (
"context"
"fmt"
"net/http"

"github.com/getyoti/yoti-go-sdk/v3/dynamic"
)

func advancedIdentityProfile(w http.ResponseWriter, req *http.Request) {
advancedIdentityProfile := []byte(`{
"profiles": [
{
"trust_framework": "UK_TFIDA",
"schemes": [
{
"label": "LB912",
"type": "RTW"
}
]
},
{
"trust_framework": "YOTI_GLOBAL",
"schemes": [
{
"label": "LB321",
"type": "IDENTITY",
"objective": "AL_L1"
}
]
}
]
}`)

policy, err := (&dynamic.PolicyBuilder{}).
WithAdvancedIdentityProfileRequirements(advancedIdentityProfile).
Build()
if err != nil {
errorPage(w, req.WithContext(context.WithValue(
req.Context(),
contextKey("yotiError"),
fmt.Sprintf(scenarioBuilderErr, err),
)))
return
}

subject := []byte(`{
"subject_id": "my_subject_id"
}`)
scenario, err := (&dynamic.ScenarioBuilder{}).
WithPolicy(policy).
WithSubject(subject).
WithCallbackEndpoint(profileEndpoint).Build()
if err != nil {
errorPage(w, req.WithContext(context.WithValue(
req.Context(),
contextKey("yotiError"),
fmt.Sprintf(scenarioBuilderErr, err),
)))
return
}

pageFromScenario(w, req, "Advanced Identity Profile Example", scenario)
}
1 change: 1 addition & 0 deletions _examples/profile/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func main() {
http.HandleFunc("/dynamic-share", dynamicShare)
http.HandleFunc("/source-constraints", sourceConstraints)
http.HandleFunc("/dbs-check", dbsCheck)
http.HandleFunc("/advanced", advancedIdentityProfile)

rootdir, err := os.Getwd()
if err != nil {
Expand Down
40 changes: 27 additions & 13 deletions docscan/session/create/session_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ type SessionSpecification struct {
// within the scope of a trust framework and scheme.
IdentityProfileRequirements *json.RawMessage `json:"identity_profile_requirements,omitempty"`

// AdvancedIdentityProfileRequirements is a JSON object for defining a required advanced identity profile
// within the scope of specified trust frameworks and schemes.
AdvancedIdentityProfileRequirements *json.RawMessage `json:"advanced_identity_profile_requirements,omitempty"`

// CreateIdentityProfilePreview is a bool for enabling the creation of the IdentityProfilePreview
CreateIdentityProfilePreview bool `json:"create_identity_profile_preview,omitempty"`

Expand All @@ -54,19 +58,20 @@ type SessionSpecification struct {

// SessionSpecificationBuilder builds the SessionSpecification struct
type SessionSpecificationBuilder struct {
clientSessionTokenTTL int
resourcesTTL int
userTrackingID string
notifications *NotificationConfig
requestedChecks []check.RequestedCheck
requestedTasks []task.RequestedTask
sdkConfig *SDKConfig
requiredDocuments []filter.RequiredDocument
blockBiometricConsent *bool
identityProfileRequirements *json.RawMessage
createIdentityProfilePreview bool
subject *json.RawMessage
importToken *ImportToken
clientSessionTokenTTL int
resourcesTTL int
userTrackingID string
notifications *NotificationConfig
requestedChecks []check.RequestedCheck
requestedTasks []task.RequestedTask
sdkConfig *SDKConfig
requiredDocuments []filter.RequiredDocument
blockBiometricConsent *bool
identityProfileRequirements *json.RawMessage
advancedIdentityProfileRequirements *json.RawMessage
createIdentityProfilePreview bool
subject *json.RawMessage
importToken *ImportToken
}

// NewSessionSpecificationBuilder creates a new SessionSpecificationBuilder
Expand Down Expand Up @@ -128,6 +133,7 @@ func (b *SessionSpecificationBuilder) WithBlockBiometricConsent(blockBiometricCo
return b
}

// WithCreateIdentityProfilePreview sets whether or not an Identity Profile Preview will be created.
func (b *SessionSpecificationBuilder) WithCreateIdentityProfilePreview(createIdentityProfilePreview bool) *SessionSpecificationBuilder {
b.createIdentityProfilePreview = createIdentityProfilePreview
return b
Expand All @@ -139,6 +145,13 @@ func (b *SessionSpecificationBuilder) WithIdentityProfileRequirements(identityPr
return b
}

// WithAdvancedIdentityProfileRequirements adds Advanced Identity Profile Requirements to the session. Must be valid JSON.
func (b *SessionSpecificationBuilder) WithAdvancedIdentityProfileRequirements(advancedIdentityProfile json.RawMessage) *SessionSpecificationBuilder {
b.advancedIdentityProfileRequirements = &advancedIdentityProfile
return b
}

// WithSubject adds Subject to the session. Must be valid JSON.
func (b *SessionSpecificationBuilder) WithSubject(subject json.RawMessage) *SessionSpecificationBuilder {
b.subject = &subject
return b
Expand All @@ -163,6 +176,7 @@ func (b *SessionSpecificationBuilder) Build() (*SessionSpecification, error) {
b.requiredDocuments,
b.blockBiometricConsent,
b.identityProfileRequirements,
b.advancedIdentityProfileRequirements,
b.createIdentityProfilePreview,
b.subject,
b.importToken,
Expand Down
Loading

0 comments on commit fbd5d03

Please sign in to comment.