• Document: CHAPTER 13 Getting Started with Identity
  • Size: 3.7 MB
  • Uploaded: 2018-10-11 18:27:53
  • Status: Successfully converted


Some snippets from your converted document:

ASP.NET Identity In Pro ASP.NET MVC 5, I describe the basic MVC framework authentication and authorization features and explain that Apress has agreed to distribute the relevant chapters from my Pro ASP.NET MVC 5 Platform book when it is published. The three chapters that follow introduce version 2.0 of ASP.NET Identity, which is the new Microsoft platform for managing users. I explain how to create a basic Identity installation, how to authenticate and authorize users, and how you can apply claims-based authorization in your applications. I also demonstrate how you can delegate authentication to third parties. I use Google in these chapters, but the same technique can also be used to authenticate users with accounts managed by Microsoft, Twitter, and Facebook. These chapters are taken as-is from Pro ASP.NET MVC 5 Platform. You don’t need a copy of the Platform book to follow the examples in these chapters, but you will see references to chapters that are not included here. You can download the source code for the example project from www.apress.com/9781430265412. I hope you find these chapters helpful, and I wish you every success in your ASP.NET projects. Adam Freeman, London April 2014 1 CHAPTER 13 Getting Started with Identity Identity is a new API from Microsoft to manage users in ASP.NET applications. The mainstay for user management in recent years has been ASP.NET Membership, which has suffered from design choices that were reasonable when it was introduced in 2005 but that have aged badly. The biggest limitation is that the schema used to store the data worked only with SQL Server and was difficult to extend without re-implementing a lot of provider classes. The schema itself was overly complex, which made it harder to implement changes than it should have been. Microsoft made a couple of attempts to improve Membership prior to releasing Identity. The first was known as simple membership, which reduced the complexity of the schema and made it easier to customize user data but still needed a relational storage model. The second attempt was the ASP.NET universal providers, which I used in Chapter 10 when I set up SQL Server storage for session data. The advantage of the universal providers is that they use the Entity Framework Code First feature to automatically create the database schema, which made it possible to create databases where access to schema management tools wasn’t possible, such as the Azure cloud service. But even with the improvements, the fundamental issues of depending on relational data and difficult customizations remained. To address both problems and to provide a more modern user management platform, Microsoft has replaced Membership with Identity. As you’ll learn in this chapter and Chapters 14 and 15, ASP.NET Identity is flexible and extensible, but it is immature, and features that you might take for granted in a more mature system can require a surprising amount of work. Microsoft has over-compensated for the inflexibility of Membership and made Identity so open and so adaptable that it can be used in just about any way—just as long as you have the time and energy to implement what you require. In this chapter, I demonstrate the process of setting up ASP.NET Identity and creating a simple user administration tool that manages individual user accounts that are stored in a database. ASP.NET Identity supports other kinds of user accounts, such as those stored using Active Directory, but I don’t describe them since they are not used that often outside corporations (where Active Directive implementations tend to be so convoluted that it would be difficult for me to provide useful general examples). In Chapter 14, I show you how to perform authentication and authorization using those user accounts, and in Chapter 15, I show you how to move beyond the basics and apply some advanced techniques. Table 13-1 summarizes this chapter. 1 CHAPTER 13 ■ GETTING STARTED WITH IDENTITY Table 13-1. Chapter Summary Problem Solution Listing Install ASP.NET Identity. Add the NuGet packages and define a connection string 1–4 and an OWIN start class in the Web.config file. Prepare to use ASP.NET Identity. Create classes that represent the user, the user manager, 5–8 the database context, and the OWIN start class. Enumerate user accounts. Use the Users property defined by the user mana

Recently converted files (publicly available):