NHSDigital.ApiPlatform.Sdk.AspNetCore is the ASP.NET Core adapter
for:
NHSDigital.ApiPlatform.Sdk
It provides:
- Session-based token/state storage
- Cookie-based token/state storage (BFF-style)
- DI registration helpers
- Seamless integration into ASP.NET Core applications
dotnet add package NHSDigital.ApiPlatform.Sdk
dotnet add package NHSDigital.ApiPlatform.Sdk.AspNetCore{
"ApiPlatform": {
"CareIdentity": {
"ClientId": "...",
"ClientSecret": "...",
"RedirectUri": "...",
"AuthEndpoint": "...",
"TokenEndpoint": "...",
"UserInfoEndpoint": "...",
"AcrValues": "aal3"
},
"PersonalDemographicsService": {
"BaseUrl": "..."
}
}
}builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession();
builder.Services.AddApiPlatformSdkAspNetCore(
builder.Configuration.GetSection("ApiPlatform")
.Get<ApiPlatformConfigurations>(),
storageMode: ApiPlatformAspNetStorageMode.Session);
app.UseSession();builder.Services.AddApiPlatformSdkAspNetCore(
builder.Configuration.GetSection("ApiPlatform")
.Get<ApiPlatformConfigurations>(),
storageMode: ApiPlatformAspNetStorageMode.Cookies);Cookies are: - HttpOnly - Secure (when HTTPS) - SameSite=Lax
[ApiController]
[Route("auth")]
public sealed class AuthController : ControllerBase
{
private readonly IApiPlatformClient api;
public AuthController(IApiPlatformClient api) => this.api = api;
[HttpGet("login")]
public IActionResult Login()
{
string url = this.api.CareIdentityServices.Login();
return Redirect(url);
}
[HttpGet("callback")]
public IActionResult Callback(string code, string state)
{
this.api.CareIdentityServices.Callback(code, state);
return Redirect("/");
}
[HttpPost("logout")]
public IActionResult Logout()
{
this.api.CareIdentityServices.Logout();
return Redirect("/");
}
}[ApiController]
[Route("pds")]
public sealed class PdsController : ControllerBase
{
private readonly IApiPlatformClient api;
public PdsController(IApiPlatformClient api) => this.api = api;
[HttpGet("patients")]
public async Task<IActionResult> Search(string family)
{
string result = await this.api
.PersonalDemographicsServices
.SearchPatientsAsync(family);
return Content(result, "application/fhir+json");
}
}All calls automatically use:
GetAccessToken()If expired, the SDK:
- Uses refresh token
- Calls token endpoint
- Stores new tokens
- Continues execution
No extra developer code required.
AddSession()UseSession()
- HTTPS recommended for production
© North East London ICB