Ejemplo n.º 1
0
        public async Task HandleCreateIdentityResultCallbackAsync(NDIDCallbackIdentityModel model)
        {
            if (model.IsSuccess)
            {
                string        sid   = _db.GetReferecne(model.ReferenceId, "sid");
                string[]      parts = sid.Split('-');
                NDIDUserModel user  = new NDIDUserModel();
                user.NameSpace  = parts[0];
                user.Identifier = parts[1];
                string            accessor_id = _db.GetReferecne(model.ReferenceId, "accessor_id");
                NDIDAccessorModel accessor    = new NDIDAccessorModel();
                accessor.AccessorId = accessor_id;
                accessor.Secret     = model.Secret;
                // update key
                string newKeyName = sid + "-" + "0";
                // not use base64 file name because windows cannot support filename with "/" charactor
                _dpki.UpdateKey(sid, newKeyName);
                string pubKey = await _dpki.GetPubKey(newKeyName);

                accessor.AccessorPubKey = pubKey;
                user.Accessors.Add(accessor);
                // save new user
                _db.CreateNewUser(user);
                // remove all referenceId
                _db.RemoveReference(model.ReferenceId);
            }
            else
            {
                throw new ApplicationException();
            }
        }
Ejemplo n.º 2
0
 public void HandleResponseResultCallback(NDIDCallbackIdentityModel model)
 {
     if (model.IsSuccess)
     {
         _db.RemoveUserRequest(model.RequestId);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// this method will handle identity request response from ndid api. It will do as follows
 /// - check for existing user
 /// - get accessor_id and store it
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void HandleCreateIdentityRequestCallback(NDIDCallbackIdentityModel model)
 {
     if (model.IsSuccess)
     {
         // do nothing
     }
     else
     {
         _db.RemoveReference(model.ReferenceId);
     }
 }
 public IActionResult IDPResponse([FromBody] NDIDCallbackIdentityModel request)
 {
     if (request.Type == NDIDConstant.CallbackType.RESPONSE_RESULT)
     {
         _ndid.HandleResponseResultCallback(request);
     }
     else
     {
         throw new NotImplementedException();
     }
     return(NoContent());
 }
 public async Task <IActionResult> IdentityResult([FromBody] NDIDCallbackIdentityModel request)
 {
     if (request.Type == NDIDConstant.CallbackType.ADD_IDENTITY_REQUEST_RESULT)
     {
         _ndid.HandleCreateIdentityRequestCallback(request);
     }
     else if (request.Type == NDIDConstant.CallbackType.ADD_IDENTITY_RESULT)
     {
         await _ndid.HandleCreateIdentityResultCallbackAsync(request);
     }
     else
     {
         throw new NotImplementedException();
     }
     return(NoContent());
 }
Ejemplo n.º 6
0
        public async Task CreateNewIdentity(NewIdentityModel iden)
        {
            // 1. generate new keypair
            NewIdentityModel newIdentity = new NewIdentityModel();

            newIdentity.NameSpace  = iden.NameSpace;
            newIdentity.Identifier = iden.Identifier;
            string sid = newIdentity.NameSpace + "-" + newIdentity.Identifier;
            await _dpki.GenNewKey(sid);

            // 2. read public key
            string pubKey = await _dpki.GetPubKey(sid);

            // 3. construct new identity api request
            newIdentity.AccessorType   = "RSA";
            newIdentity.AccessorPubKey = pubKey;
            newIdentity.ReferenceId    = Guid.NewGuid().ToString();
            newIdentity.CallbackUrl    = new Uri(new Uri(_config.GetCallbackPath()), "api/callback/identity").ToString();
            newIdentity.IAL            = 2.3m;
            _db.SaveAccessorSign(newIdentity.ReferenceId, sid);
            _db.SaveReference(newIdentity.ReferenceId, "sid", sid);
            // 4. check response from api reqeust
            using (HttpClient client = new HttpClient())
            {
                Uri url = new Uri(_apiServerAddress + "/v2/identity");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(
                    new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                string        jsonContent = JsonConvert.SerializeObject(newIdentity);
                StringContent content     = new StringContent(jsonContent, Encoding.UTF8, "application/json");
                var           result      = client.PostAsync(url, content).Result;
                string        resultJson  = await result.Content.ReadAsStringAsync();

                if (result.IsSuccessStatusCode)
                {
                    NDIDCallbackIdentityModel model = JsonConvert.DeserializeObject <NDIDCallbackIdentityModel>(resultJson);
                    _db.SaveReference(newIdentity.ReferenceId, "accessor_id", model.AccessorId);
                    _db.SaveReference(newIdentity.ReferenceId, "request_id", model.RequestId);
                }
                else
                {
                    NDIDCallbackRequestModel model = JsonConvert.DeserializeObject <NDIDCallbackRequestModel>(resultJson);
                    throw new ApplicationException(model.Error.Message);
                }
            }
        }
Ejemplo n.º 7
0
 public Task HandleResponseResultCallbackAsync(NDIDCallbackIdentityModel model)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 8
0
 public Task HandleCreateIdentityRequestCallbackAsync(NDIDCallbackIdentityModel model)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 9
0
 void INDIDService.HandleCreateIdentityResultCallback(NDIDCallbackIdentityModel model)
 {
     throw new NotImplementedException();
 }