public async Task ReplaceWithNewConnectionAsync(string did, OwnIdConnection connection) { var connectionId = string.IsNullOrEmpty(connection.Fido2CredentialId) ? connection.PublicKey.ToSha256() : connection.Fido2CredentialId; var newDbConnection = _firebaseContext.Db.Collection(Constants.CollectionName) .Document(connectionId.ReplaceSpecPathSymbols()); var oldConnections = await _firebaseContext.Db.Collection(Constants.CollectionName) .WhereEqualTo(Constants.UserIdFieldName, did).GetSnapshotAsync(); await _firebaseContext.Db.RunTransactionAsync(transaction => { foreach (var oldConnection in oldConnections) { transaction.Delete(oldConnection.Reference); } transaction.Create(newDbConnection, new { pubKey = connection.PublicKey, keyHsh = connection.PublicKey.ToSha256(), recoveryId = connection.RecoveryToken, recoveryEncData = connection.RecoveryData, fido2CredentialId = connection.Fido2CredentialId, fido2SignatureCounter = connection.Fido2SignatureCounter, userId = did, authType = connection.AuthType.ToString() }); return(Task.CompletedTask); }); }
public async Task OnLinkAsync(string did, OwnIdConnection connection) { var accountInfo = await _restApiClient.SearchAsync <UidContainer>(GigyaFields.UID, did); if (!accountInfo.IsSuccess) { if (accountInfo.ErrorCode != 0) { throw new Exception(accountInfo.GetFailureMessage()); } throw new Exception($"Can't find user with did = {did}"); } accountInfo.First.Data ??= new AccountData(); if (accountInfo.First.Data.OwnId.Connections.Count >= _ownIdConfiguration.MaximumNumberOfConnectedDevices) { throw new Exception( $"Gigya.OnLink error -> maximum number ({_ownIdConfiguration.MaximumNumberOfConnectedDevices}) of linked devices reached"); } // add new public key to connection accountInfo.First.Data.OwnId.Connections.Add(new GigyaOwnIdConnection(connection)); var setAccountMessage = await _restApiClient.SetAccountInfoAsync <TProfile>(did, data : accountInfo.First.Data); if (setAccountMessage.ErrorCode != 0) { throw new Exception( $"Gigya.setAccountInfo error -> {setAccountMessage.GetFailureMessage()}"); } }
public async Task UpgradeConnectionAsync(string publicKey, OwnIdConnection newConnection) { var user = await _restApiClient.SearchByPublicKey(publicKey); if (user == null) { return; } // Remove old connection var connectionToRemove = user.Data.OwnId.Connections.First(x => x.PublicKey == publicKey); user.Data.OwnId.Connections.Remove(connectionToRemove); // Add new one user.Data.OwnId.Connections.Add(new GigyaOwnIdConnection(newConnection)); var setAccountResponse = await _restApiClient.SetAccountInfoAsync(user.UID, (TProfile)null, user.Data); if (setAccountResponse.ErrorCode > 0) { throw new Exception( $"did: {user.UID} " + $"Gigya.setAccountInfo for EXISTING user error -> {setAccountResponse.GetFailureMessage()}"); } }
public async Task UpgradeConnectionAsync(string publicKey, OwnIdConnection newConnection) { var oldConnectionQuery = _firebaseContext.Db.Collection(Constants.CollectionName) .Document(publicKey.ToSha256().ReplaceSpecPathSymbols()); var oldConnectionSnapshot = await oldConnectionQuery.GetSnapshotAsync(); if (!oldConnectionSnapshot.Exists) { throw new Exception("User not found"); } await _firebaseContext.Db.RunTransactionAsync(transaction => { transaction.Delete(oldConnectionQuery); var connectionId = string.IsNullOrEmpty(newConnection.Fido2CredentialId) ? newConnection.PublicKey.ToSha256() : newConnection.Fido2CredentialId; var newDbConnection = _firebaseContext.Db.Collection(Constants.CollectionName) .Document(connectionId.ReplaceSpecPathSymbols()); transaction.Create(newDbConnection, new { pubKey = newConnection.PublicKey, keyHsh = newConnection.PublicKey.ToSha256(), recoveryId = newConnection.RecoveryToken, recoveryEncData = newConnection.RecoveryData, fido2CredentialId = newConnection.Fido2CredentialId, fido2SignatureCounter = newConnection.Fido2SignatureCounter, userId = oldConnectionSnapshot.GetValue <string>(Constants.UserIdFieldName), authType = newConnection.AuthType.ToString() }); return(Task.CompletedTask); }); }
public GigyaOwnIdConnection(OwnIdConnection ownIdConnection) { PublicKey = ownIdConnection.PublicKey; RecoveryToken = ownIdConnection.RecoveryToken; RecoveryData = ownIdConnection.RecoveryData; Fido2CredentialId = ownIdConnection.Fido2CredentialId; Fido2SignatureCounter = ownIdConnection.Fido2SignatureCounter; AuthType = ownIdConnection.AuthType; }
public async Task ReplaceWithNewConnectionAsync(string did, OwnIdConnection connection) { var gigyaOwnIdConnection = new GigyaOwnIdConnection(connection); var responseMessage = await _apiClient.SetAccountInfoAsync <TProfile>(did, data : new AccountData(gigyaOwnIdConnection)); if (responseMessage.ErrorCode != 0) { throw new Exception($"Gigya.setAccountInfo error -> {responseMessage.GetFailureMessage()}"); } }
public async Task OnLinkAsync(string did, OwnIdConnection connection) { var connectionId = string.IsNullOrEmpty(connection.Fido2CredentialId) ? connection.PublicKey.ToSha256().ReplaceSpecPathSymbols() : connection.Fido2CredentialId; await _firebaseContext.Db.Collection(Constants.CollectionName).Document(connectionId).CreateAsync(new { pubKey = connection.PublicKey, keyHsh = connection.PublicKey.ToSha256(), recoveryId = connection.RecoveryToken, recoveryEncData = connection.RecoveryData, fido2CredentialId = connection.Fido2CredentialId, fido2SignatureCounter = connection.Fido2SignatureCounter, userId = did, authType = connection.AuthType.ToString() }); }
public Task UpgradeConnectionAsync(string publicKey, OwnIdConnection newConnection) { return(_adaptee.UpgradeConnectionAsync(publicKey, newConnection)); }
public Task <AuthResult <object> > RegisterPartialAsync(string did, OwnIdConnection ownIdConnection) { return(Task.FromException <AuthResult <object> >(new NotSupportedException())); }
public Task <AuthResult <object> > RegisterPartialAsync(string did, OwnIdConnection ownIdConnection) { return(_adaptee.RegisterPartialAsync(did, ownIdConnection)); }