Настраиваемый контроллер входа MVC.NET core 2 - PullRequest
0 голосов
/ 09 октября 2018

Можно ли создать настраиваемую форму входа в систему в "клиенте" MVC (.net core 2), выдав токен с сервера аутентификации (Identity server 4) и присвоив токену / учетным данным конвейер MVC для авторизации?

Сервер аутентификации:

new Client{
ClientId = "MVC",
ClientName = "MVC",
RequireClientSecret = true,

AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
 ClientSecrets = {
    new Secret("secret".Sha256())
},

 AllowedScopes = {
    IdentityServerConstants.StandardScopes.OpenId,
    IdentityServerConstants.StandardScopes.Profile,
    "roles",
    configuration["AUTHENTICATION_SCOPE:SCOPE_ID"],
},

AllowOfflineAccess = true,
AlwaysSendClientClaims = true,
AlwaysIncludeUserClaimsInIdToken = true,
AccessTokenType = AccessTokenType.Reference,
AccessTokenLifetime = int.Parse(configuration["AccessTokenLifetime"]), 
AbsoluteRefreshTokenLifetime = int.Parse(configuration["AbsoluteRefreshTokenLifetime"])}

Клиент MVC:

Startup.cs

public void ConfigureServices(IServiceCollection services){
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();


services.AddAuthentication(options =>
{
    options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;

}).AddOpenIdConnect("oidc", options =>
{
    options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;

    options.Authority = "...";
    options.RequireHttpsMetadata = false;

    options.GetClaimsFromUserInfoEndpoint = true;

    options.ClientId = "MVC";
    options.ClientSecret = "secret";
    options.ResponseType = "code id_token";

    options.SaveTokens = true;
}).AddCookie(options =>
{
    options.LoginPath = new PathString("/Account/Login/");
    options.LogoutPath = new PathString("/Account/Logout/");
    options.AccessDeniedPath = new PathString("/Account/Login/");
});}

AccountController.cs

[HttpPost, ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginViewModel vm, string button){
if (!ModelState.IsValid)
    return View(vm);

//HOW TO CONTINUE FROM HERE?    
//Issue token from auth server and set it in the HttpContext.Authentication?}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...