Supported platforms: netstandard14, desktop .NET, UWP, .NET Core, Xamarin iOS & Android. Nuget.
Certified OpenID Connect relying party implementation.
OidcClient is an implementation of the OIDC/OAuth 2 for native apps specification for C#.
In manual mode, OidcClient helps you with creating the necessary start URL and state parameters, but you need to coordinate with whatever browser you want to use, e.g.
var options = new OidcClientOptions
{
Authority = _authority,
ClientId = "native.hybrid",
RedirectUri = redirectUri,
Scope = "openid profile api"
};
var client = new OidcClient(options);
// generate start URL, state, nonce, code challenge
var state = await client.PrepareLoginAsync();
When the browser work is done, OidcClient can take over to process the response, get the access/refresh tokens, contact userinfo endpoint etc..
var result = await client.ProcessResponseAsync(data, state);
The result will contain the tokens and the claims of the user.
In automatic mode, you can encapsulate all browser interactions by implementing the IBrowser
interface.
var options = new OidcClientOptions
{
Authority = _authority,
ClientId = "native.hybrid",
RedirectUri = redirectUri,
Scope = "openid profile api",
Browser = new SystemBrowser(port: 7890)
};
var client = new OidcClient(options);
Once that is done, authentication and token requests become one line of code:
var result = await client.LoginAsync();
OidcClient has support for the standard .NET logging facilities, e.g. using Serilog:
var serilog = new LoggerConfiguration()
.MinimumLevel.Verbose()
.Enrich.FromLogContext()
.WriteTo.LiterateConsole(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message}{NewLine}{Exception}{NewLine}")
.CreateLogger();
options.LoggerFactory.AddSerilog(serilog);
See here for samples using WinForms, Console and Xamarin iOS/Android.