Goffo.OracleFusion.Api.Core
1.1.0
dotnet add package Goffo.OracleFusion.Api.Core --version 1.1.0
NuGet\Install-Package Goffo.OracleFusion.Api.Core -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Goffo.OracleFusion.Api.Core" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Goffo.OracleFusion.Api.Core" Version="1.1.0" />
<PackageReference Include="Goffo.OracleFusion.Api.Core" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Goffo.OracleFusion.Api.Core --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Goffo.OracleFusion.Api.Core, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Goffo.OracleFusion.Api.Core@1.1.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Goffo.OracleFusion.Api.Core&version=1.1.0
#tool nuget:?package=Goffo.OracleFusion.Api.Core&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Goffo.OracleFusion.Api.Core
How to use
Create an implementation for the IFusionApi<TRequest, TResponse>
TRequest is what will hold your request payload for the Oracle Fusion API.
TResponse is what will hold the return response from the Oracle Fusion API
Use the ITokenProvider to create an implementation to get a token
Example
Appsettings.json
{
"FusionApiEndpoints": {
"Post": "https://example.com/api/post"
}
}
public class ApiExample
{
private readonly IServiceCollection _services;
public ApiExample()
{
// Dependency injection setup
_services = new ServiceCollection();
// Uses appsettings.json to configure the Fusion API endpoints
_services.AddFusionApi<FusionApi, FusionRequest, FusionResponse>();
// Our configure in method
//_services.AddFusionApi<FusionApi, FusionRequest, FusionResponse>((endpoints) =>
//{
// endpoints.Post = "https://api.example.com/fusion";
//});
_services.AddHttpClient<ITokenProvider, TokenProvider>();
}
public class FusionApi : IFusionApi<FusionRequest, FusionResponse>
{
// Inject HttpClient via constructor injection
// This is setup in the AddFusionApi extension method
private readonly HttpClient _client;
private readonly ITokenProvider _tokenProvider;
public FusionApi(HttpClient client, ITokenProvider tokenProvider)
{
_client = client;
_tokenProvider = tokenProvider;
}
public async Task<FusionResponse> PostAsync(FusionRequest request, CancellationToken cancellationToken = default)
{
// Your code to handle the request and return a response...
// For example you might need to get a token first
Token token = await _tokenProvider.GetTokenAsync(cancellationToken);
// use the token to set the Authorization header
_client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(token.TokenType, token.AccessToken);
// Now you can make the actual API call
var response = await _client.PostAsJsonAsync("https://api.example.com/fusion", request, cancellationToken);
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadFromJsonAsync<FusionResponse>();
}
return new FusionResponse(IsSuccess: false);
}
}
public record FusionRequest(string Payload);
public record FusionResponse(bool IsSuccess);
public class TokenProvider : ITokenProvider
{
private readonly HttpClient _client;
private Token _cacheToken = new("", "", 0, "");
public TokenProvider(HttpClient client)
{
_client = client;
}
public async Task<Token> GetTokenAsync(CancellationToken cancellationToken = default)
{
// Your code to get a token....
// You probably want to cache the token and handle expiration
System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler handler = new();
System.IdentityModel.Tokens.Jwt.JwtSecurityToken securityToken = handler.ReadJwtToken(_cachedToken.AccessToken);
object? tokenExp = null;
DateTime expDateTime = DateTime.Now.AddDays(1);
if (securityToken.Payload.TryGetValue("exp", out tokenExp))
{
expDateTime = DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(tokenExp)).LocalDateTime;
bool isValid = expDateTime < DateTime.Now.AddSeconds(-10);
if(isValid)
{
// Token is still valid, return cached token
return _cacheToken;
}
}
// You may want to make an API call
Dictionary<string, string?> formUrlContent = new Dictionary<string, string?>
{
{ "grant_type", "client_credentials" },
{ "client_id", "client-id" },
{ "client_secret", "client-secret" },
{ "scope", "your-scope" }
};
var response = await _client.PostAsJsonAsync("https://api.example.com/fusion", new FormUrlEncodedContent(formUrlContent), cancellationToken);
if (response.IsSuccessStatusCode)
{
Token token = await response.Content.ReadFromJsonAsync<Token>();
_cacheToken = token;
return token;
}
throw new TokenException(response.StatusCode, response.ReasonPhrase, await response.Content.ReadAsStringAsync());
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.6)
- Microsoft.Extensions.Http (>= 9.0.6)
- Newtonsoft.Json (>= 13.0.3)
- System.IdentityModel.Tokens.Jwt (>= 8.12.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Goffo.OracleFusion.Api.Core:
Package | Downloads |
---|---|
Goffo.OracleFusion.Api.OAuth2
Provides helper method for OAuth2 |
GitHub repositories
This package is not used by any popular GitHub repositories.
Added endpoint configuration through dependency injection