Browse Source

Update the Mvc.Server sample to use the default entity key type

pull/237/head
Kévin Chalet 10 years ago
parent
commit
dde3dc1aca
  1. 5
      samples/Mvc.Server/Controllers/AuthorizationController.cs
  2. 2
      samples/Mvc.Server/Models/ApplicationDbContext.cs
  3. 2
      samples/Mvc.Server/Models/ApplicationUser.cs
  4. 10
      samples/Mvc.Server/Startup.cs

5
samples/Mvc.Server/Controllers/AuthorizationController.cs

@ -4,7 +4,6 @@
* the license and the contributors participating to this project. * the license and the contributors participating to this project.
*/ */
using System;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -22,12 +21,12 @@ using OpenIddict;
namespace Mvc.Server { namespace Mvc.Server {
public class AuthorizationController : Controller { public class AuthorizationController : Controller {
private readonly OpenIddictApplicationManager<OpenIddictApplication<Guid>> _applicationManager; private readonly OpenIddictApplicationManager<OpenIddictApplication> _applicationManager;
private readonly SignInManager<ApplicationUser> _signInManager; private readonly SignInManager<ApplicationUser> _signInManager;
private readonly UserManager<ApplicationUser> _userManager; private readonly UserManager<ApplicationUser> _userManager;
public AuthorizationController( public AuthorizationController(
OpenIddictApplicationManager<OpenIddictApplication<Guid>> applicationManager, OpenIddictApplicationManager<OpenIddictApplication> applicationManager,
SignInManager<ApplicationUser> signInManager, SignInManager<ApplicationUser> signInManager,
UserManager<ApplicationUser> userManager) { UserManager<ApplicationUser> userManager) {
_applicationManager = applicationManager; _applicationManager = applicationManager;

2
samples/Mvc.Server/Models/ApplicationDbContext.cs

@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using OpenIddict; using OpenIddict;
namespace Mvc.Server.Models { namespace Mvc.Server.Models {
public class ApplicationDbContext : OpenIddictDbContext<ApplicationUser, IdentityRole<Guid>, Guid> { public class ApplicationDbContext : OpenIddictDbContext<ApplicationUser, IdentityRole> {
public ApplicationDbContext(DbContextOptions options) public ApplicationDbContext(DbContextOptions options)
: base(options) { } : base(options) { }

2
samples/Mvc.Server/Models/ApplicationUser.cs

@ -3,5 +3,5 @@ using OpenIddict;
namespace Mvc.Server.Models { namespace Mvc.Server.Models {
// Add profile data for application users by adding properties to the ApplicationUser class // Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : OpenIddictUser<Guid> { } public class ApplicationUser : OpenIddictUser { }
} }

10
samples/Mvc.Server/Startup.cs

@ -25,12 +25,12 @@ namespace Mvc.Server {
options.UseSqlServer(configuration["Data:DefaultConnection:ConnectionString"])); options.UseSqlServer(configuration["Data:DefaultConnection:ConnectionString"]));
// Register the Identity services. // Register the Identity services.
services.AddIdentity<ApplicationUser, IdentityRole<Guid>>() services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext, Guid>() .AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders(); .AddDefaultTokenProviders();
// Register the OpenIddict services, including the default Entity Framework stores. // Register the OpenIddict services, including the default Entity Framework stores.
services.AddOpenIddict<ApplicationDbContext, Guid>() services.AddOpenIddict<ApplicationDbContext>()
// Register the ASP.NET Core MVC binder used by OpenIddict. // Register the ASP.NET Core MVC binder used by OpenIddict.
// Note: if you don't call this method, you won't be able to // Note: if you don't call this method, you won't be able to
// bind OpenIdConnectRequest or OpenIdConnectResponse parameters. // bind OpenIdConnectRequest or OpenIdConnectResponse parameters.
@ -149,7 +149,7 @@ namespace Mvc.Server {
// Type = OpenIddictConstants.ClientTypes.Confidential // Type = OpenIddictConstants.ClientTypes.Confidential
// }); // });
context.Applications.Add(new OpenIddictApplication<Guid> { context.Applications.Add(new OpenIddictApplication {
ClientId = "myClient", ClientId = "myClient",
ClientSecret = Crypto.HashPassword("secret_secret_secret"), ClientSecret = Crypto.HashPassword("secret_secret_secret"),
DisplayName = "My client application", DisplayName = "My client application",
@ -167,7 +167,7 @@ namespace Mvc.Server {
// * Scope: openid email profile roles // * Scope: openid email profile roles
// * Grant type: authorization code // * Grant type: authorization code
// * Request access token locally: yes // * Request access token locally: yes
context.Applications.Add(new OpenIddictApplication<Guid> { context.Applications.Add(new OpenIddictApplication {
ClientId = "postman", ClientId = "postman",
DisplayName = "Postman", DisplayName = "Postman",
RedirectUri = "https://www.getpostman.com/oauth2/callback", RedirectUri = "https://www.getpostman.com/oauth2/callback",

Loading…
Cancel
Save