Skip to content

Latest commit

 

History

History
95 lines (69 loc) · 3.97 KB

README.md

File metadata and controls

95 lines (69 loc) · 3.97 KB

ODataClientManager

NuGet .NET Core Quality Gate Status Coverage

Purpose

This repository provides a C# based OData client manager library. The Manager uses the IODataClient implementation of Simple.OData.Client to communicate with OData APIs and is able to handle authorization and versioning requirements.

Getting started

The easiest way to start using the ODataManager is to install the Nuget package:

Install-Package OData.Client.Manager

In the source file where you will be using ODataManager import the namespace:

using OData.Client.Manager;

Quickstart

The following code snipped shows an example of how to use the IODataManger implementation.

// Create the manager
var odataEndpoint = new Uri("http://localhost:12345/api");
var manager = new ODataManager(odataEndpoint);

// Use the client of the manager (example of the typed fluent API syntax)
IEnumerable<Product> entities = await manager.Client
    .For<Product>()
    .FindEntriesAsync();

// Use the client of the manager (example of the dynamic fluent API syntax)
var dx = ODataDynamic.Expression;
IEnumerable<dynamic> entities = await manager.Client
    .For(dx.Products)
    .FindEntriesAsync();

For more information about how to use the Odata client, please read the Simple.OData.Client documentation.

Make use of autenticated and versioned requests

  • To make use of authentication use one of the existing authenticators in the OData.Client.Manager.Authenticators namespace, or create your own by implementing the IAuthenticator interface.
  • To make use of authentication, just use one of the existing managers in the OData.Client.Manager.Versioning namespace or create your own by implementing the IVersioningManager interface.
// Setup the configuration
var config = new ODataManagerConfiguration(new Uri("http://localhost:12345/api"))
{
    // Authenticated requests
    Authenticator = new OidcAuthenticator(new OidcSettings
    {
        AuthUri = new Uri("http://localhost:5000"),
        ClientId = "ClientAppX",
        ClientSecret = "Secret",
        Username = "User",
        Password = "Password",
        Scope = "api1",

        GrantType = "Password", // Default
        DiscoveryPolicy = new DiscoveryPolicy { RequireHttps = false },
    }),

    // Versioned requests
    VersioningManager = new QueryParamVersioningManager("1.2", "api-version")
};

// Use the configuration in the ctor of the manager
var manager = new ODataManager(config);

FAQ

  1. Why do I get the error Https required?
    • OIDC endpoints must provide an encrypted connection (https) by default (except URIs of localhost). To disable this requirement, make use of the OidcSettings and set RequireHttps of the DiscoveryPolicy property to false: settings.DiscoveryPolicy = new DiscoveryPolicy { RequireHttps = requireHttps };.

Links

Open Source License Acknowledgements and Third-Party Copyrights