Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into AddDocusaurus
  • Loading branch information
RobinTTY committed May 21, 2024
2 parents ead5d5a + 0538380 commit 9c89edf
Show file tree
Hide file tree
Showing 86 changed files with 4,263 additions and 1,234 deletions.
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# NordigenApiClient

This project provides a C# client for
the [GoCardless Bank Account Data API](https://gocardless.com/bank-account-data/) (formerly Nordigen API). The following API endpoints are supported:
the [GoCardless Bank Account Data API](https://gocardless.com/bank-account-data/) (formerly Nordigen API). The following
API endpoints are supported:

- Token
- Institutions
- Agreements
- Requisitions
- Accounts

**Update June 6th 2023:** The Nordigen company merged with https://gocardless.com/. The new documentation can be found
at: https://developer.gocardless.com/bank-account-data/endpoints.
You can find the official GoCardless documentation for the
API [here](https://developer.gocardless.com/bank-account-data/endpoints).

## Getting started

Expand All @@ -34,7 +35,7 @@ at: https://developer.gocardless.com/bank-account-data/endpoints.
3. You can now use the different endpoints through the client:

```cs
var response = await client.InstitutionsEndpoint.GetInstitutions(country: "GB");
var response = await client.InstitutionsEndpoint.GetInstitutions(SupportedCountry.UnitedKingdom);
```

The responses that are returned always have the same structure:
Expand All @@ -58,7 +59,7 @@ example [here](src/RobinTTY.NordigenApiClient.ExampleApplication)):
1. Get a list of institutions in your country (e.g. Great Britain):

```cs
var institutionsResponse = await client.InstitutionsEndpoint.GetInstitutions(country: "GB");
var institutionsResponse = await client.InstitutionsEndpoint.GetInstitutions(SupportedCountry.UnitedKingdom);
if (institutionsResponse.IsSuccess)
institutionsResponse.Result.ForEach(institution =>
{
Expand All @@ -72,11 +73,8 @@ example [here](src/RobinTTY.NordigenApiClient.ExampleApplication)):

```cs
var institution = "BANK_OF_SCOTLAND_BOFSGBS1";
var userLanguage = "EN";
var reference = "your-internal-reference";
var redirect = new Uri("https://where-nordigen-will-redirect-after-authentication.com");
var requisitionRequest = new CreateRequisitionRequest(redirect, institution, reference, userLanguage);
var requisitionResponse = await client.RequisitionsEndpoint.CreateRequisition(requisitionRequest);
var requisitionResponse = await client.RequisitionsEndpoint.CreateRequisition(institution, redirect);

if (requisitionResponse.IsSuccess)
{
Expand Down Expand Up @@ -183,8 +181,8 @@ void OnTokenPairUpdated(object? sender, TokenPairUpdatedEventArgs e)
{
// The event args contain the updated token
Console.WriteLine("Updated token pair:");
Console.WriteLine($"Access Token: {e.JsonWebTokenPair!.AccessToken.EncodedToken}");
Console.WriteLine($"Refresh Token: {e.JsonWebTokenPair!.RefreshToken.EncodedToken}");
Console.WriteLine($"Access Token: {e.JsonWebTokenPair.AccessToken.EncodedToken}");
Console.WriteLine($"Refresh Token: {e.JsonWebTokenPair.RefreshToken.EncodedToken}");
}
```

Expand Down
7 changes: 2 additions & 5 deletions src/RobinTTY.NordigenApiClient.ExampleApplication/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

////* Getting balances and transactions for a bank account */////
// 1. Get a list of institutions in your country (e.g. Great Britain):
var institutionsResponse = await client.InstitutionsEndpoint.GetInstitutions("GB");
var institutionsResponse = await client.InstitutionsEndpoint.GetInstitutions(SupportedCountry.UnitedKingdom);
if (institutionsResponse.IsSuccess)
institutionsResponse.Result.ForEach(institution =>
{
Expand All @@ -21,11 +21,8 @@
// 2. Choose the institution your bank account is registered with and create a requisition for it:

var institution = "BANK_OF_SCOTLAND_BOFSGBS1";
var userLanguage = "EN";
var reference = "your-internal-reference";
var redirect = new Uri("https://where-nordigen-will-redirect-after-authentication.com");
var requisitionRequest = new CreateRequisitionRequest(redirect, institution, reference, userLanguage);
var requisitionResponse = await client.RequisitionsEndpoint.CreateRequisition(requisitionRequest);
var requisitionResponse = await client.RequisitionsEndpoint.CreateRequisition(institution, redirect);

if (requisitionResponse.IsSuccess)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
using Microsoft.IdentityModel.JsonWebTokens;
using RobinTTY.NordigenApiClient.Models;
using RobinTTY.NordigenApiClient.Models.Jwt;
using RobinTTY.NordigenApiClient.Utility;

namespace RobinTTY.NordigenApiClient.Tests;

internal class JsonWebTokenPairTests
/// <summary>
/// Tests aspects of authentication related to the <see cref="NordigenClientCredentials" /> and
/// <see cref="JsonWebTokenPair" /> classes.
/// </summary>
internal class AuthenticationTests
{
private NordigenClient _apiClient = null!;

[OneTimeSetUp]
public void Setup()
/// <summary>
/// Tests creating <see cref="NordigenClientCredentials" />, passing null as an argument.
/// </summary>
[Test]
public void CreateCredentialsWithNull()
{
_apiClient = TestExtensions.GetConfiguredClient();
Assert.Throws<ArgumentNullException>(() => { _ = new NordigenClientCredentials(null!, null!); });
}

/// <summary>
Expand Down Expand Up @@ -48,22 +54,6 @@ public void CreateInvalidJsonWebTokenPair()
Assert.Throws<ArgumentException>(() => new JsonWebTokenPair(exampleToken, exampleToken));
}

/// <summary>
/// Tests that <see cref="NordigenClient.JsonWebTokenPair" /> is populated after the first authenticated request is made.
/// </summary>
[Test]
public async Task CheckValidTokensAfterRequest()
{
Assert.That(_apiClient.JsonWebTokenPair, Is.Null);
await _apiClient.RequisitionsEndpoint.GetRequisitions(5, 0, CancellationToken.None);
Assert.Multiple(() =>
{
Assert.That(_apiClient.JsonWebTokenPair, Is.Not.Null);
Assert.That(_apiClient.JsonWebTokenPair!.AccessToken.EncodedToken, Has.Length.GreaterThan(0));
Assert.That(_apiClient.JsonWebTokenPair!.RefreshToken.EncodedToken, Has.Length.GreaterThan(0));
});
}

/// <summary>
/// Tests the token expiry extension method for correct behavior respecting time zones.
/// </summary>
Expand Down
85 changes: 0 additions & 85 deletions src/RobinTTY.NordigenApiClient.Tests/CredentialTests.cs

This file was deleted.

Loading

0 comments on commit 9c89edf

Please sign in to comment.