/// <summary> /// The Enroll identity endpoint is used to enroll new identities for the smart contract app. /// A success response includes the API Token generated for the identity. /// This API Token can be used to call API End points on behalf of the enrolled identity. /// /// This endpoint provides equivalent functionality to adding new identity manually using Xooa console, /// and identities added using this endpoint will appear, and can be managed, /// using Xooa console under the identities tab of the smart contract app /// /// Required permission: manage identities (canManageIdentities=true) /// </summary> /// <exception cref="Xooa.Client.Exception.XooaApiException">Thrown when fails to make API call</exception> /// <param name="IdentityRequest">Identity Data to enroll.</param> /// <returns>PendingTransactionResponse giving the resultId of the pending transaction.</returns> public PendingTransactionResponse enrollIdentityAsync(IdentityRequest identityRequest) { Log.Info("Invoking URL - " + XooaConstants.IDENTITIES_URL); var localVarPath = XooaConstants.IDENTITIES_URL; var contentType = XooaConstants.CONTENT_TYPE; var localVarQueryParameters = new List <KeyValuePair <string, string> >(); localVarQueryParameters.Add(new KeyValuePair <string, string>(XooaConstants.ASYNC, XooaConstants.TRUE)); localVarQueryParameters.Add(new KeyValuePair <string, string>(XooaConstants.TIMEOUT, "1000")); var localVarHeaderParams = new Dictionary <string, string>(); localVarHeaderParams.Add(XooaConstants.ACCEPT, XooaConstants.CONTENT_TYPE); localVarHeaderParams.Add(XooaConstants.AUTHORIZATION, XooaConstants.TOKEN + ApiToken); string jsonBody = identityRequest.toString(); int statusCode = 0; try { RestRequest request = XooaSDK.Client.Util.Request.PrepareRequest(localVarPath, RestSharp.Method.POST, localVarQueryParameters, jsonBody, localVarHeaderParams, null, null, contentType); IRestResponse response = RestClient.ExecuteTaskAsync(request).Result; JObject details = XooaSDK.Client.Util.Request.getDataAsync(response); PendingTransactionResponse pendingTransactionResponse = new PendingTransactionResponse( details["resultId"].ToString(), details["resultURL"].ToString()); return(pendingTransactionResponse); } catch (XooaApiException xae) { Log.Error(xae); throw xae; } catch (System.Exception e) { Log.Error(e); throw new XooaApiException(statusCode, e.Message); } }
/// <summary> /// The Enroll identity endpoint is used to enroll new identities for the smart contract app. /// A success response includes the API Token generated for the identity. /// This API Token can be used to call API End points on behalf of the enrolled identity. /// /// This endpoint provides equivalent functionality to adding new identity manually using Xooa console, /// and identities added using this endpoint will appear, and can be managed, /// using Xooa console under the identities tab of the smart contract app. /// /// Required permission: manage identities (canManageIdentities=true) /// </summary> /// <exception cref="Xooa.Client.Exception.XooaApiException">Thrown when fails to make API call</exception> /// <exception cref="Xooa.Client.Exception.XooaRequestTimeoutException">Thrown when a 202 response is recieved.</exception> /// <param name="IdentityRequest">Identity to Enroll.</param> /// <param name="timeout">Timeout interval for transaction.</param> /// <returns>IdentityResponse giving the data about the new Identity.</returns> public IdentityResponse enrollIdentity(IdentityRequest identityRequest, string timeout = "3000") { Log.Info("Invoking URL - " + XooaConstants.IDENTITIES_URL); var localVarPath = XooaConstants.IDENTITIES_URL; var contentType = XooaConstants.CONTENT_TYPE; var localVarQueryParameters = new List <KeyValuePair <string, string> >(); localVarQueryParameters.Add(new KeyValuePair <string, string>(XooaConstants.ASYNC, XooaConstants.FALSE)); localVarQueryParameters.Add(new KeyValuePair <string, string>(XooaConstants.TIMEOUT, timeout)); var localVarHeaderParams = new Dictionary <string, string>(); localVarHeaderParams.Add(XooaConstants.ACCEPT, XooaConstants.CONTENT_TYPE); localVarHeaderParams.Add(XooaConstants.AUTHORIZATION, XooaConstants.TOKEN + ApiToken); string jsonBody = identityRequest.toString(); int statusCode = 0; try { RestRequest request = XooaSDK.Client.Util.Request.PrepareRequest(localVarPath, RestSharp.Method.POST, localVarQueryParameters, jsonBody, localVarHeaderParams, null, null, contentType); IRestResponse response = RestClient.Execute(request); JObject details = XooaSDK.Client.Util.Request.GetData(response); var Attrs = details["Attrs"]; List <attrs> attributes = new List <attrs>(); foreach (var attrObject in Attrs) { attrs attr = new attrs(attrObject["name"].ToString(), attrObject["value"].ToString(), (bool)attrObject["ecert"]); attributes.Add(attr); } IdentityResponse identityResponse = new IdentityResponse( (details["IdentityName"] != null) ? details["IdentityName"].ToString() : "", (details["Access"] != null) ? details["Access"].ToString() : "", (bool)details["canManageIdentities"], (details["createdAt"] != null) ? details["createdAt"].ToString() : "", (details["ApiToken"] != null) ? details["ApiToken"].ToString() : "", (details["Id"] != null) ? details["Id"].ToString() : "", attributes); return(identityResponse); } catch (XooaRequestTimeoutException xrte) { Log.Error(xrte); throw xrte; } catch (XooaApiException xae) { Log.Error(xae); throw xae; } catch (System.Exception e) { Log.Error(e); throw new XooaApiException(statusCode, e.Message); } }