Bối cảnh: Tôi đang sử dụng ASP.NET MVC với máy chủ riêng. Dưới đây là phần còn lại của cấu hình/thiết lập.IdentityServer3: Một số Xác nhận quyền sở hữu không được trả về từ máy chủ định danh
Trong Khách hàng s của tôi trong máy chủ danh tính (chú ý AllowedScopes bộ):
public static class InMemoryClientSource
{
public static List<Client> GetClientList()
{
return new List<Client>()
{
new Client()
{
ClientName = "Admin website",
ClientId = "admin",
Enabled = true,
Flow = Flows.Hybrid,
ClientSecrets = new List<Secret>()
{
new Secret("admin".Sha256())
},
RedirectUris = new List<string>()
{
"https://admin.localhost.com/"
},
PostLogoutRedirectUris = new List<string>()
{
"https://admin.localhost.com/"
},
AllowedScopes = new List<string> {
Constants.StandardScopes.OpenId,
Constants.StandardScopes.Profile,
Constants.StandardScopes.Email,
Constants.StandardScopes.Roles
}
}
};
}
}
Sau đây là các Scopes:
public static class InMemoryScopeSource
{
public static List<Scope> GetScopeList()
{
var scopes = new List<Scope>();
scopes.Add(StandardScopes.OpenId);
scopes.Add(StandardScopes.Profile);
scopes.Add(StandardScopes.Email);
scopes.Add(StandardScopes.Roles);
return scopes.ToList();
}
}
Trong nhận dạng máy chủ, đây là cách cấu hình máy chủ. (Chú ý Clients và Scopes được những người cung cấp ở trên):
var userService = new UsersService(.... repository passed here ....);
var factory = new IdentityServerServiceFactory()
.UseInMemoryClients(InMemoryClientSource.GetClientList())
.UseInMemoryScopes(InMemoryScopeSource.GetScopeList());
factory.UserService = new Registration<IUserService>(resolver => userService);
var options = new IdentityServerOptions()
{
Factory = factory,
SigningCertificate = Certificates.Load(), // certificates blah blah
SiteName = "Identity"
};
app.UseIdentityServer(options);
Cuối cùng, ở phía bên ứng dụng web của khách hàng, đây là cách auth được thiết lập:
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions()
{
Authority = "https://id.localhost.com",
ClientId = "admin",
RedirectUri = "https://admin.localhost.com/",
PostLogoutRedirectUri = "https://admin.localhost.com/",
ResponseType = "code id_token token",
Scope = "openid profile email roles",
ClientSecret = "admin",
SignInAsAuthenticationType = "Cookies"
});
Tôi có triển khai lớp tùy chỉnh cho IUserService:
public class UsersService : UserServiceBase
{
public UsersService(.... repository passed here ....)
{
//.... ctor stuff
}
public override Task AuthenticateLocalAsync(LocalAuthenticationContext context)
{
// var user = .... retrieved from database .....
// ... auth logic ...
if (isAuthenticated)
{
var claims = new List<Claim>();
claims.Add(new Claim(Constants.ClaimTypes.GivenName, user.FirstName));
claims.Add(new Claim(Constants.ClaimTypes.FamilyName, user.LastName));
claims.Add(new Claim(Constants.ClaimTypes.Email, user.EmailAddress));
context.AuthenticateResult = new AuthenticateResult(user.Id.ToString(), user.EmailAddress, claims);
}
return Task.FromResult(0);
}
}
Như bạn thấy, các xác nhận quyền sở hữu được chuyển vào dòng này:
context.AuthenticateResult = new AuthenticateResult(user.Id.ToString(), user.EmailAddress, claims);
Khi tôi thử đăng nhập vào IdentityServer3, tôi có thể đăng nhập thành công vào ứng dụng web của ứng dụng khách. HOWEVER, khi tôi nhận được xác nhận quyền sở hữu của người dùng, tôi không thấy bất kỳ xác nhận quyền sở hữu danh tính nào. Không given_name, family_name và email khiếu nại. Ảnh chụp màn hình bên dưới:
Bất cứ điều gì tôi có thể đã bỏ lỡ? Cảm ơn trước!
cấu hình của bạn trông tốt. Tôi biết, nhưng bạn có chắc chắn rằng người dùng được xác thực có những tuyên bố đó không? –
Hey @ScottBrady, tôi cho rằng họ đã có bởi vì tôi đã thêm những yêu cầu đó vào context.AuthenticateResult (như bạn thấy trên mã mẫu ở trên để triển khai thực hiện UsersService tùy chỉnh). – jerbersoft