I am having a .NET Core 2.1 Web API project using OpenIddict.
TLDR: Following the example given here, I need the sample for performing the logout request to invalidate/logout the refresh token and the access token for one user.
LONG VERSION:
It is about several API users that retrieve an access token + refresh token with username and password. I am searching for a possibility to invalidate/logout both tokens for one specific API user having a valid access/refresh token.
I am lost trying to write a route for "logging out" the access token and the refresh token with the current refresh token a single user.
We do not use a SignInManager. I see several examples for that on the net. But I did not find anything that matches our simple in-memory-approach. The TokenManager has no SignOut methods.
The ConfigureServices() part on Startup.cs looks like this:
services.AddDbContext<DbContext>(options =>
{
options.UseInMemoryDatabase(nameof(DbContext));
options.UseOpenIddict();
});
services.AddOpenIddict().AddCore(options =>
{
options.UseEntityFrameworkCore().UseDbContext<DbContext>();
});
services.AddOpenIddict().AddServer(options =>
{
options.UseMvc();
options.EnableTokenEndpoint("/api/token").EnableLogoutEndpoint("/api/logout");
options.AllowPasswordFlow();
options.AllowRefreshTokenFlow();
options.SetAccessTokenLifetime(TimeSpan.FromSeconds(60 * 60));
options.SetRefreshTokenLifetime(TimeSpan.FromSeconds(7 * 24 * 60 * 60));
options.RegisterScopes(OpenIdConnectConstants.Scopes.OfflineAccess);
options.DisableHttpsRequirement();
options.UseRollingTokens();
options.AcceptAnonymousClients();
});
services.AddOpenIddict().AddValidation();
services.AddAuthentication(options =>
{
options.DefaultScheme = OAuthValidationDefaults.AuthenticationScheme;
});
Retrieving access tokens and using the refresh tokens works perfectly fine.
But what do I use in the logout-route?
[HttpGet]
[Route("/api/logout")]
public async Task<IActionResult> LogoutAsync(OpenIdConnectRequest logoutRequest)
{
// ???
}
Trying sth. like the following shows me an almost empty logoutRequest parameter (everything is null and has only the Properties filled with the information that we have a logout_request.
[HttpGet]
[Route("/api/logout")]
public async Task<IActionResult> LogoutAsync(OpenIdConnectRequest logoutRequest)
{
var result = SignOut(OpenIdConnectServerDefaults.AuthenticationScheme);
return result;
}