Skip to content
Open
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
2 changes: 2 additions & 0 deletions Xero.NetStandard.OAuth2Client/src/Client/IXeroClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xero.NetStandard.OAuth2.Config;
Expand All @@ -22,6 +23,7 @@ public interface IXeroClient
Task<IXeroToken> GetCurrentValidTokenAsync(IXeroToken xeroToken);
Task<List<Tenant>> GetConnectionsAsync(IXeroToken xeroToken);
Task DeleteConnectionAsync(IXeroToken xeroToken, Tenant xeroTenant);
Task DeleteConnectionAsync(IXeroToken xeroToken, Guid connectionId);
Task RevokeAccessTokenAsync(IXeroToken xeroToken);
}
}
23 changes: 23 additions & 0 deletions Xero.NetStandard.OAuth2Client/src/Client/XeroClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public async Task<List<Tenant>> GetConnectionsAsync(IXeroToken xeroToken)
/// <param name="xeroToken"></param>
/// <param name="xeroTenant"></param>
/// <returns>List of Tenants attached to accesstoken</returns>
[Obsolete("This method is being removed. Switch to using DeleteConnectionAsync using the connectionId guid")]
public async Task DeleteConnectionAsync(IXeroToken xeroToken, Tenant xeroTenant)
{
using (var requestMessage = new HttpRequestMessage(HttpMethod.Delete, $"{xeroConfiguration.XeroApiBaseUri}/connections" + "/" + xeroTenant.id))
Expand All @@ -332,6 +333,28 @@ public async Task DeleteConnectionAsync(IXeroToken xeroToken, Tenant xeroTenant)
}
}

/// <summary>
/// Delete the connection given the accesstoken and xero tenant id
/// </summary>
/// <param name="xeroToken"></param>
/// <param name="connectionId"></param>
/// <returns>Delete a connection using its connection id</returns>
public async Task DeleteConnectionAsync(IXeroToken xeroToken, Guid connectionId)
{
using (var requestMessage = new HttpRequestMessage(HttpMethod.Delete, $"{xeroConfiguration.XeroApiBaseUri}/connections" + "/" + connectionId))
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", xeroToken.AccessToken);

var result = await _httpClient.SendAsync(requestMessage);
if (result.StatusCode == System.Net.HttpStatusCode.NoContent)
{
return;
}

throw new HttpRequestException(await result.Content.ReadAsStringAsync());
}
}

/// <summary>
/// Revokes the current token - immediate disconnect all orgs and stops the user authorisation
/// </summary>
Expand Down