Контекст: Я использую ASP.NET MVC с собственным хостом OWIN. Ниже приведены остальные настройки/настройки.IdentityServer3: Некоторые претензии не возвращаются с сервера идентификации
В моих клиента с в сервере личных данных (обратите внимание на AllowedScopes комплект):
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
}
}
};
}
}
Вот Прицелы:
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();
}
}
В Сервер идентификации, вот как настроен сервер. (Обратите внимание на клиентов и SCOPES являются те, приведенных выше):
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);
Наконец, на стороне клиента веб-приложений, это как авторизация устанавливается:
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"
});
У меня есть реализован пользовательский класс 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);
}
}
Как вы видите, требования передаются в этой строке:
context.AuthenticateResult = new AuthenticateResult(user.Id.ToString(), user.EmailAddress, claims);
Когда я пытаюсь войти в систему IdentityServer3, я могу успешно выполнить вход в клиентское веб-приложение. HOWEVER, когда я получаю претензии пользователей, я не вижу никаких претензий в отношении личности. № имя_источника, фамилия и электронная почта претензии. Снимок экрана ниже:
Все, что я мог пропустить? Заранее спасибо!
Ваша конфигурация выглядит отлично. Глупый я знаю, но вы уверены, что у аутентифицированного пользователя есть эти претензии? –
Эй, @ScottBrady, я предполагаю, что они уже есть, потому что я добавил эти утверждения в контекст. AtthenticateResult (как вы видите на примере кода выше для пользовательской реализации UserService). – jerbersoft