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

Support passport::photo field #250

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 42 additions & 0 deletions examples/fact_request/photo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2020 Self Group Ltd. All Rights Reserved.

# frozen_string_literal: true

require 'selfsdk'

# Process input data
abort("provide self_id to request information to") if ARGV.length != 1
user = ARGV.first
SelfSDK.logger = ::Logger.new($stdout).tap do |log|
log.progname = "SelfSDK examples"
end if ENV.has_key?'LOGS'

# You can point to a different environment by passing optional values to the initializer
opts = ENV.has_key?('SELF_ENV') ? { env: ENV["SELF_ENV"] } : {}
storage_dir = "#{File.expand_path("..", File.dirname(__FILE__))}/self_storage"

# Connect your app to Self network, get your connection details creating a new
# app on https://developer.selfsdk.net/
@app = SelfSDK::App.new(ENV["SELF_APP_ID"], ENV["SELF_APP_DEVICE_SECRET"], ENV["STORAGE_KEY"], storage_dir, opts)

# Request display_name and email_address to the specified user
begin
@app.facts.request(user, [{source: :passport, fact: :photo}]) do |res|
# Information request has been rejected by the user
if res.status == "rejected"
puts 'Information request rejected'
exit!
end

objects = res.attested_objects_for(:photo)
objects.first.save("/tmp/photo.jpg")
puts "your attested file is on /tmp/photo.jpg"
exit!
end
rescue => e
puts "ERROR : #{e}"
exit!
end

# Wait for asyncrhonous process to finish
sleep 100
4 changes: 3 additions & 1 deletion lib/messages/attestation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module SelfSDK
module Messages
class Attestation
attr_accessor :verified, :origin, :source, :value, :operator, :expected_value, :fact_name, :to, :audience
attr_accessor :verified, :origin, :source, :value, :operator, :expected_value, :fact_name, :to, :audience, :objects

def initialize(messaging)
@messaging = messaging
Expand All @@ -30,11 +30,13 @@ def parse(name, attestation)
payload[:facts].each do |f|
if f[:key] == name.to_s
@value = f[:value]
@objects = f[:objects]
break
end
end
else
@value = payload[name]
@objects = []
end
end

Expand Down
13 changes: 13 additions & 0 deletions lib/messages/fact_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ def attestation_values_for(name)
a.map{|a| a.value}
end

def attested_objects_for(name)
a = attestations_for(name)
auth_token = @messaging.jwt.auth_token
self_url = @messaging.client.self_url
objects = []
a.each do |at|
at.objects.each do |o|
objects << SelfSDK::Chat::FileObject.new(auth_token, self_url).build_from_object(o)
end
end
objects
end

def validate!(original)
super
@facts.each do |f|
Expand Down
1 change: 1 addition & 0 deletions lib/source_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module SelfSDK
"phone_number"
],
"passport" => [
"photo",
"document_number",
"surname",
"given_names",
Expand Down