Tôi đang sử dụngTôi nên xử lý xác thực bằng Identity 2.0 và WebAPI 2.1 và Owin 2 bằng cách nào?
- trình duyệt mới chỉ khách hàng trên cùng một tên miền
- nhận dạng 2.0
- WebAPI 2.1
- Owin 2.1
- AngularJS front-end cho đăng ký, đăng nhập và hiển thị dữ liệu
Trong ứng dụng WebAPI có giao diện người dùng AngularJS.
Tôi đang đọc về xác thực mã thông báo nhưng bây giờ tôi rất bối rối và tôi không thể tìm thấy bất kỳ ví dụ hay nào ngoài đó sử dụng kết hợp của tôi. Những gì tôi muốn biết là tôi nên sử dụng cookie hoặc thẻ để xác thực. Tôi có nên sử dụng Userfactory hoặc CreatePerOwinContext không?
Đây là những gì tôi có trong Startup.Auth.cs tôi
public partial class Startup {
public void ConfigureAuth(IAppBuilder app) {
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions {
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/"),
Provider = new CookieAuthenticationProvider {
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
// Enables the application to remember the second login verification factor such as phone or email.
// Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
// This is similar to the RememberMe option when you log in.
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
}
}
Dưới đây là cấu hình WebAPI tôi:
public static class WebApiConfig
{
public static void CustomizeConfig(HttpConfiguration config)
{
config.Formatters.Remove(config.Formatters.XmlFormatter);
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
json.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
json.SerializerSettings.Converters.Add(new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-ddTHH:mmZ" });
}
tôi thấy một số ví dụ sử dụng mã này, nhưng tôi không chắc chắn làm thế nào tôi có thể gọi này:
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AllowInsecureHttp = true
};
Tôi có thể thay thế xác thực cookie bằng cách này không?