У меня angular веб-приложение в качестве клиента. В моем приложении у меня есть 2 роли admin, member. Angular запрос на страницу входа в систему путем отправки роли (admin, member) в параметре запроса на идентификационный сервер 4. (Тип предоставления - неявный)
Членский вход выполняется из БД (на нашем сторона) идентификационный сервер проверяет действительные учетные данные, чем генерирует токен и куки, но для администратора у меня есть API, который возвращает true или false после проверки учетных данных.
Теперь мне нужно сгенерировать токен и файлы cookie с самого сервера идентификации 4, чтобы он возвращал имя пользователя, введенное пользователем, а также роль в утверждениях. как я могу это сделать?
Ниже приведен код для входа в систему, который я хочу заменить администратору. Должен ли я использовать ResourceOwnerPasswordValidator и где, как он будет генерировать Cook ie и токен?
if (_users.ValidateCredentials(model.Username, model.Password))
{
var user = _users.FindByUsername(model.Username);
await _events.RaiseAsync(new UserLoginSuccessEvent(user.Username, user.SubjectId, user.Username, clientId: context?.ClientId));
// only set explicit expiration here if user chooses "remember me".
// otherwise we rely upon expiration configured in cookie middleware.
AuthenticationProperties props = null;
if (AccountOptions.AllowRememberLogin && model.RememberLogin)
{
props = new AuthenticationProperties
{
IsPersistent = true,
ExpiresUtc = DateTimeOffset.UtcNow.Add(AccountOptions.RememberMeLoginDuration)
};
};
// issue authentication cookie with subject ID and username
await HttpContext.SignInAsync(user.SubjectId, user.Username, props);
if (context != null)
{
if (await _clientStore.IsPkceClientAsync(context.ClientId))
{
// if the client is PKCE then we assume it's native, so this change in how to
// return the response is for better UX for the end user.
return View("Redirect", new RedirectViewModel { RedirectUrl = model.ReturnUrl });
}
// we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null
return Redirect(model.ReturnUrl);
}
// request for a local page
if (Url.IsLocalUrl(model.ReturnUrl))
{
return Redirect(model.ReturnUrl);
}
else if (string.IsNullOrEmpty(model.ReturnUrl))
{
return Redirect("~/");
}
else
{
// user might have clicked on a malicious link - should be logged
throw new Exception("invalid return URL");
}
}