Что является альтернативой федеративной аутентификации в ASP.Net Core? - PullRequest
0 голосов
/ 31 декабря 2018

У меня есть веб-API (.Net 4.6), который аутентифицирует моих пользователей с помощью FederatedAuthentication (System.IdentityModel.Services), и теперь я пытаюсь перенести его на ASP.Net Core 2.2 Web API.

Вот мой существующий код для генерации cookie токена FedAuth:1. AuthController.cs

//... Create new Identity and Claims Principal.
ClaimsIdentity claimsIdentity = new ClaimsIdentity(User.Identity);
ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(claimsIdentity);

claimsIdentity.AddClaims(__getClaims());
claimsPrincipal.AddIdentity(claimsIdentity);

//... Create a new Session Security Token. 
  var token = FederatedAuthentication.SessionAuthenticationModule.CreateSessionSecurityToken(
claimsPrincipal, "MyAPP", DateTime.UtcNow, DateTime.UtcNow.AddMinutes(expirationTime), false);

//... Write a cookie.
FederatedAuthentication.SessionAuthenticationModule.
AuthenticateSessionSecurityToken(token, true);

И в Web.config:

<configSections>
    <!--WIF 4.5 sections -->
    <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</configSections>

<modules>
  <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</modules>

<system.identityModel>
    <identityConfiguration>
      <securityTokenHandlers>
        <remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </securityTokenHandlers>
    </identityConfiguration>
  </system.identityModel>

Так как идентификация утверждений и принципал утверждений используются всеми моими проверяющими приложениями, я хочу продолжить использовать то же самое в ядре ASP.net.

Итак, мой вопрос здесьчто такое способ создания токена безопасности сеанса (cookie) с утверждениями Identity в основном веб-API ASP.net?

Большое спасибо !!

1 Ответ

0 голосов
/ 31 декабря 2018

Я верю, что получил то, что искал;Вот две хорошие статьи, с которых я начал знакомство:

  1. https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-2.2

  2. https://jonhilton.net/2017/10/11/secure-your-asp.net-core-2.0-api-part-1---issuing-a-jwt/

...