2using System.Collections.Generic;
3using System.Threading.Tasks;
14 : base(
"/ValidateLegalId")
18 public override bool HandlesSubPaths =>
false;
19 public override bool UserSessions =>
true;
30 if (!(Obj is Dictionary<string, object> RequestObj) ||
31 !RequestObj.TryGetValue(
"LegalId", out Obj) || !(Obj is
string LegalId) ||
32 !RequestObj.TryGetValue(
"Purpose", out Obj) || !(Obj is
string Purpose) ||
33 !RequestObj.TryGetValue(
"Password", out Obj) || !(Obj is
string Password) ||
34 !RequestObj.TryGetValue(
"TabID", out Obj) || !(Obj is
string TabID))
39 if (LegalId.IndexOf(
'@') < 0)
45 Dictionary<string, object> ResponseObj;
50 ResponseObj = await this.Encode(Identity);
54 string PetitionId = Guid.NewGuid().ToString();
56 Purpose = Purpose.Trim();
57 if (
string.IsNullOrEmpty(Purpose))
58 Purpose =
"Validating Legal Identity through web interface at " +
Gateway.
Domain;
64 {
"PetitionId", e.PetitionId },
65 {
"PetitionResponse", e.Response },
66 {
"Identity", await this.Encode(e.RequestedIdentity) },
67 {
"Declined", e.RequestedIdentity is
null && !(e.Message is
null) },
68 {
"Timeout", e.Message is
null }
70 }, TimeSpan.FromMinutes(5)))
72 throw new ForbiddenException(
"Unable to sign petition. Either password is incorrect, or no legal identity assigned to broker.");
75 ResponseObj =
new Dictionary<string, object>()
79 {
"PetitionId", PetitionId },
80 {
"Message",
"The information has been petitioned from the owner. If the owner accepts to share the information, it will be displayed here when it arrives." }
84 await Response.
Return(ResponseObj);
87 private async Task<Dictionary<string, object>> Encode(
LegalIdentity Identity)
93 Dictionary<string, object> Properties =
new Dictionary<string, object>();
94 Dictionary<string, object> ResponseObj =
new Dictionary<string, object>()
96 {
"Id", Identity.Id },
97 {
"IdUri", Identity.IdUriString },
98 {
"Petition",
false },
99 {
"ClientKeyName", Identity.ClientKeyName },
100 {
"ClientPubKey", Identity.HasClientPublicKey ? Convert.ToBase64String(Identity.
ClientPubKey) :
null },
101 {
"ClientSignature", Identity.HasClientSignature ? Convert.ToBase64String(Identity.
ClientSignature) :
null },
102 {
"Created", Identity.Created },
103 {
"From", Identity.From },
104 {
"To", Identity.To },
105 {
"HasClientPublicKey", Identity.HasClientPublicKey },
106 {
"HasClientSignature", Identity.HasClientSignature },
107 {
"Provider", Identity.Provider },
108 {
"ServerSignature", Convert.ToBase64String(Identity.
ServerSignature) },
109 {
"State", Identity.
State.ToString() },
110 {
"Updated", Identity.Updated },
111 {
"ValidationStatus", Status.ToString() },
112 {
"Properties", Properties }
120 List<Dictionary<string, object>> Attachments =
new List<Dictionary<string, object>>();
124 Attachments.Add(
new Dictionary<string, object>()
126 {
"Id", Attachment.Id },
127 {
"ContentType", Attachment.ContentType },
128 {
"FileName", Attachment.FileName },
129 {
"Url", Attachment.Url },
131 {
"Timestamp", Attachment.Timestamp },
135 ResponseObj[
"Attachments"] = Attachments.ToArray();
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
The ClientEvents class allows applications to push information asynchronously to web clients connecte...
static Task< int > PushEvent(string[] TabIDs, string Type, object Data)
Puses an event to a set of Tabs, given their Tab IDs.
Static class managing the runtime environment of the IoT Gateway.
static CaseInsensitiveString Domain
Domain name.
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
static Task< bool > PetitionLegalIdentity(string LegalId, string PetitionId, string Purpose, EventHandlerAsync< LegalIdentityPetitionResponseEventArgs > Callback, TimeSpan Timeout)
Petitions information about a legal identity from its owner.
static ContractsClient ContractsClient
XMPP Contracts Client, if such a compoent is available on the XMPP broker.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
Represents an HTTP request.
bool HasData
If the request has data.
async Task< object > DecodeDataAsync()
Decodes data sent in request.
Represets a response of an HTTP client request.
async Task Return(object Object)
Returns an object to the client. This method can only be called once per response,...
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
Contains a reference to an attachment assigned to a legal object.
byte[] Signature
Binary signature of the attachment, generated by an approved legal identity of the account-holder....
Task< LegalIdentity > GetLegalIdentityAsync(string LegalIdentityId)
Gets legal identity registered with the account.
Task< IdentityStatus > ValidateAsync(LegalIdentity Identity)
Validates a legal identity.
IdentityState State
Current state of identity
byte[] ClientSignature
Client signature
byte[] ClientPubKey
Client Public key
byte[] ServerSignature
Server signature
Attachment[] Attachments
Attachments assigned to the legal identity.
Property[] Properties
Properties detailing the legal identity.
string Name
Name of property
string Value
Property value
bool AllowsPOST
If the POST method is allowed.
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
POST Interface for HTTP resources.
IdentityStatus
Validation Status of legal identity