我必須定製UserManager
類來查找和認證公司結構中的用戶(將Active Directory身份驗證與另一個Oracle身份驗證混合)。儘管我已經實施了FindAsync
和CreateIdentityAsync
,但用戶並未被設置爲已通過身份驗證。OWIN - 定製UserManager
我UserManager
實現:
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Security.Claims;
using System.Web;
using MyProject.Common;
using MyProject.Models;
using Microsoft.AspNet.Identity;
using System.Threading.Tasks;
namespace MyProject.Infrastructure
{
public class GNUserManager : UserManager<ApplicationUser>
{
public GNUserManager(IUserStore<ApplicationUser> store) : base(store)
{
}
public override async Task<ApplicationUser> FindAsync(string userName, string password)
{
/* Performs some logic here that returns true */
if (foundUser) {
return await Task.Run(() => new ApplicationUser
{
UserName = userName,
Id = userName
});
}
throw new Exception("User not found.");
}
public override async Task<ClaimsIdentity> CreateIdentityAsync(ApplicationUser user, string authenticationType)
{
IList<Claim> claimCollection = new List<Claim>
{
new Claim(ClaimTypes.Name, user.UserName),
new Claim(ClaimTypes.Country, "Brazil"),
new Claim(ClaimTypes.Email, user.UserName)
};
var claimsIdentity = new ClaimsIdentity(claimCollection, "Company Portal");
return await Task.Run(() => claimsIdentity);
}
}
}
目前缺乏已我的用戶身份驗證?
我昨天看到了這個網站,但它只是一瞥我正在尋找的東西。這正是我感興趣的cookie一代。 –