ManiaAPI.ManiaPlanetAPI.Extensions.Hosting
2.2.0
dotnet add package ManiaAPI.ManiaPlanetAPI.Extensions.Hosting --version 2.2.0
NuGet\Install-Package ManiaAPI.ManiaPlanetAPI.Extensions.Hosting -Version 2.2.0
<PackageReference Include="ManiaAPI.ManiaPlanetAPI.Extensions.Hosting" Version="2.2.0" />
<PackageVersion Include="ManiaAPI.ManiaPlanetAPI.Extensions.Hosting" Version="2.2.0" />
<PackageReference Include="ManiaAPI.ManiaPlanetAPI.Extensions.Hosting" />
paket add ManiaAPI.ManiaPlanetAPI.Extensions.Hosting --version 2.2.0
#r "nuget: ManiaAPI.ManiaPlanetAPI.Extensions.Hosting, 2.2.0"
#addin nuget:?package=ManiaAPI.ManiaPlanetAPI.Extensions.Hosting&version=2.2.0
#tool nuget:?package=ManiaAPI.ManiaPlanetAPI.Extensions.Hosting&version=2.2.0
ManiaAPI.ManiaPlanetAPI.Extensions.Hosting
Provides ManiaPlanet OAuth2 authorization for ASP.NET Core applications and an efficient way to inject ManiaPlanetAPI
into your application.
Setup ManiaPlanetAPI
injection
ManiaPlanetAPI
will be available as a transient, with a singleton handling of credentials. This will make sure the HttpClient
beneath is handled properly.
Providing options.Credentials
is optional, but setting it will automatically authorize on the first request and maintain that connection, so you don't have to call AuthorizeAsync
.
using ManiaAPI.ManiaPlanetAPI.Extensions.Hosting;
builder.Services.AddManiaPlanetAPI(options =>
{
options.Credentials = new ManiaPlanetAPICredentials(
builder.Configuration["ManiaPlanet:ClientId"]!,
builder.Configuration["ManiaPlanet:ClientSecret"]!);
});
Setup OAuth2
For the list of scopes, see here at the bottom. Generate your credentials here. The redirect URL is the /signin-maniaplanet
relative to the web root, for example: https://localhost:7864/signin-maniaplanet
.
using ManiaAPI.ManiaPlanetAPI.Extensions.Hosting;
using ManiaAPI.ManiaPlanetAPI.Extensions.Hosting.Authentication;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie()
.AddManiaPlanet(options =>
{
options.ClientId = builder.Configuration["OAuth2:ManiaPlanet:ClientId"]!;
options.ClientSecret = builder.Configuration["OAuth2:ManiaPlanet:ClientSecret"]!;
Array.ForEach(["basic", "dedicated", "titles"], options.Scope.Add);
});
var app = builder.Build();
app.MapGet("/login", () =>
{
return TypedResults.Challenge(new() { RedirectUri = "/" }, [ManiaPlanetAuthenticationDefaults.AuthenticationScheme]);
});
app.Run();
You can inject ManiaPlanetAPI
if you create a special HTTP client handler to provide the token from HttpContext.GetTokenAsync("access_token")
and use that to get more information from the authorized user. Don't forget to set SaveTokens = true
in options.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. 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. |
-
net8.0
- ManiaAPI.ManiaPlanetAPI (>= 2.2.0)
-
net9.0
- ManiaAPI.ManiaPlanetAPI (>= 2.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.