顯示具有 ASP.NET Identity 標籤的文章。 顯示所有文章
顯示具有 ASP.NET Identity 標籤的文章。 顯示所有文章

2014年6月4日 星期三

OAuth Authentication by external sign in

OAuth authentication by Google Login

image

 

1. Use CookieAuthentication, passing in different CookieAuthenticationOptions

2. Use ExternalSignInCookie, for example, GoogleAuthentication

image

3. Locate to ExternalLoginCallback() in AccountController.cs

4. await AuthenticationManager.AuthenticateAsync()

5. Put break-point and run the application, to see the result and email from google login

image

Microsoft.AspNet.Identity in MVC 5

Microsoft.AspNet.Identity.Core

image

image

 

Microsoft.AspNet.Identity.EntityFramework

image

image

 

AccountController.cs

new UserManager<ApplicationUser>(…)

image

 

IdentityModel.cs

class ApplicationUser and ApplicationDbContext

image

 

1. Add customize field, FavoriteBook, into IdentityUser table

2. Add customize table, Movie, into IdentityDbContext

image

3. Don’t forget to add textbox of customize field on related Views

4. Don’t forget to do DB Migration to apply schema changes in database, otherwise we will see following error

image

Configuration.cs in Migration folder

5. new ApplicationUser{}

6. new PasswordHasher()

image

7. Or the other way to create default user in Seed method

image

8. Run command, update-database, in Package Manager Console

image

9. If want to add default Role to defaut user

image