Skip to content

Commit

Permalink
Update the samples to use the non-generic OpenIddict managers
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchalet committed Jan 13, 2021
1 parent 8fee0c0 commit d50366c
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using OpenIddict.EntityFrameworkCore.Models;
using OpenIddict.Server.AspNetCore;
using static OpenIddict.Abstractions.OpenIddictConstants;

namespace Aridka.Server.Controllers
{
public class AuthorizationController : Controller
{
private readonly OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication> _applicationManager;
private readonly IOpenIddictApplicationManager _applicationManager;

public AuthorizationController(OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication> applicationManager)
public AuthorizationController(IOpenIddictApplicationManager applicationManager)
=> _applicationManager = applicationManager;

[HttpPost("~/connect/token"), Produces("application/json")]
Expand Down
13 changes: 5 additions & 8 deletions samples/Aridka/Aridka.Server/Controllers/ResourceController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenIddict.Core;
using OpenIddict.EntityFrameworkCore.Models;
using OpenIddict.Abstractions;
using OpenIddict.Validation.AspNetCore;
using static OpenIddict.Abstractions.OpenIddictConstants;

Expand All @@ -11,12 +10,10 @@ namespace Aridka.Server.Controllers
[Route("api")]
public class ResourceController : Controller
{
private readonly OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication> _applicationManager;
private readonly IOpenIddictApplicationManager _applicationManager;

public ResourceController(OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication> applicationManager)
{
_applicationManager = applicationManager;
}
public ResourceController(IOpenIddictApplicationManager applicationManager)
=> _applicationManager = applicationManager;

[Authorize(AuthenticationSchemes = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme)]
[HttpGet("message")]
Expand All @@ -34,7 +31,7 @@ public async Task<IActionResult> GetMessage()
return BadRequest();
}

return Content($"{application.DisplayName} has been successfully authenticated.");
return Content($"{await _applicationManager.GetDisplayNameAsync(application)} has been successfully authenticated.");
}
}
}
4 changes: 1 addition & 3 deletions samples/Aridka/Aridka.Server/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using OpenIddict.EntityFrameworkCore.Models;
using static OpenIddict.Abstractions.OpenIddictConstants;

namespace Aridka.Server
Expand All @@ -25,7 +23,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
await context.Database.EnsureCreatedAsync();

var manager = scope.ServiceProvider.GetRequiredService<OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication>>();
var manager = scope.ServiceProvider.GetRequiredService<IOpenIddictApplicationManager>();

if (await manager.FindByClientIdAsync("console") == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,23 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using OpenIddict.EntityFrameworkCore.Models;
using OpenIddict.Server.AspNetCore;
using static OpenIddict.Abstractions.OpenIddictConstants;

namespace Balosar.Server.Controllers
{
public class AuthorizationController : Controller
{
private readonly OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication> _applicationManager;
private readonly OpenIddictAuthorizationManager<OpenIddictEntityFrameworkCoreAuthorization> _authorizationManager;
private readonly OpenIddictScopeManager<OpenIddictEntityFrameworkCoreScope> _scopeManager;
private readonly IOpenIddictApplicationManager _applicationManager;
private readonly IOpenIddictAuthorizationManager _authorizationManager;
private readonly IOpenIddictScopeManager _scopeManager;
private readonly SignInManager<ApplicationUser> _signInManager;
private readonly UserManager<ApplicationUser> _userManager;

public AuthorizationController(
OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication> applicationManager,
OpenIddictAuthorizationManager<OpenIddictEntityFrameworkCoreAuthorization> authorizationManager,
OpenIddictScopeManager<OpenIddictEntityFrameworkCoreScope> scopeManager,
IOpenIddictApplicationManager applicationManager,
IOpenIddictAuthorizationManager authorizationManager,
IOpenIddictScopeManager scopeManager,
SignInManager<ApplicationUser> signInManager,
UserManager<ApplicationUser> userManager)
{
Expand Down
4 changes: 1 addition & 3 deletions samples/Balosar/Balosar.Server/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using OpenIddict.EntityFrameworkCore.Models;
using static OpenIddict.Abstractions.OpenIddictConstants;

namespace Balosar.Server
Expand All @@ -25,7 +23,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
await context.Database.EnsureCreatedAsync();

var manager = scope.ServiceProvider.GetRequiredService<OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication>>();
var manager = scope.ServiceProvider.GetRequiredService<IOpenIddictApplicationManager>();

if (await manager.FindByClientIdAsync("balosar-blazor-client") is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using OpenIddict.EntityFrameworkCore.Models;
using OpenIddict.Server.AspNetCore;
using Velusia.Server.Helpers;
using Velusia.Server.Models;
Expand All @@ -29,16 +27,16 @@ namespace Velusia.Server.Controllers
{
public class AuthorizationController : Controller
{
private readonly OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication> _applicationManager;
private readonly OpenIddictAuthorizationManager<OpenIddictEntityFrameworkCoreAuthorization> _authorizationManager;
private readonly OpenIddictScopeManager<OpenIddictEntityFrameworkCoreScope> _scopeManager;
private readonly IOpenIddictApplicationManager _applicationManager;
private readonly IOpenIddictAuthorizationManager _authorizationManager;
private readonly IOpenIddictScopeManager _scopeManager;
private readonly SignInManager<ApplicationUser> _signInManager;
private readonly UserManager<ApplicationUser> _userManager;

public AuthorizationController(
OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication> applicationManager,
OpenIddictAuthorizationManager<OpenIddictEntityFrameworkCoreAuthorization> authorizationManager,
OpenIddictScopeManager<OpenIddictEntityFrameworkCoreScope> scopeManager,
IOpenIddictApplicationManager applicationManager,
IOpenIddictAuthorizationManager authorizationManager,
IOpenIddictScopeManager scopeManager,
SignInManager<ApplicationUser> signInManager,
UserManager<ApplicationUser> userManager)
{
Expand Down
4 changes: 1 addition & 3 deletions samples/Velusia/Velusia.Server/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using OpenIddict.EntityFrameworkCore.Models;
using Velusia.Server.Models;
using static OpenIddict.Abstractions.OpenIddictConstants;

Expand All @@ -25,7 +23,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
await context.Database.EnsureCreatedAsync();

var manager = scope.ServiceProvider.GetRequiredService<OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication>>();
var manager = scope.ServiceProvider.GetRequiredService<IOpenIddictApplicationManager>();

if (await manager.FindByClientIdAsync("mvc") == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using OpenIddict.EntityFrameworkCore.Models;
using OpenIddict.Server.AspNetCore;
using Zirku.Server.Helpers;
using Zirku.Server.Models;
Expand All @@ -24,12 +22,12 @@ namespace Zirku.Server.Controllers
{
public class AuthorizationController : Controller
{
private readonly OpenIddictScopeManager<OpenIddictEntityFrameworkCoreScope> _scopeManager;
private readonly IOpenIddictScopeManager _scopeManager;
private readonly SignInManager<ApplicationUser> _signInManager;
private readonly UserManager<ApplicationUser> _userManager;

public AuthorizationController(
OpenIddictScopeManager<OpenIddictEntityFrameworkCoreScope> scopeManager,
IOpenIddictScopeManager scopeManager,
SignInManager<ApplicationUser> signInManager,
UserManager<ApplicationUser> userManager)
{
Expand Down
6 changes: 2 additions & 4 deletions samples/Zirku/Zirku.Server/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using OpenIddict.EntityFrameworkCore.Models;
using Zirku.Server.Models;
using static OpenIddict.Abstractions.OpenIddictConstants;

Expand All @@ -30,7 +28,7 @@ public async Task StartAsync(CancellationToken cancellationToken)

async Task CreateApplicationsAsync()
{
var manager = scope.ServiceProvider.GetRequiredService<OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication>>();
var manager = scope.ServiceProvider.GetRequiredService<IOpenIddictApplicationManager>();

if (await manager.FindByClientIdAsync("aurelia") == null)
{
Expand Down Expand Up @@ -86,7 +84,7 @@ async Task CreateApplicationsAsync()

async Task CreateScopesAsync()
{
var manager = scope.ServiceProvider.GetRequiredService<OpenIddictScopeManager<OpenIddictEntityFrameworkCoreScope>>();
var manager = scope.ServiceProvider.GetRequiredService<IOpenIddictScopeManager>();

if (await manager.FindByNameAsync("api1") == null)
{
Expand Down

0 comments on commit d50366c

Please sign in to comment.