Код: Выделить всё
Microsoft.Owin -Version 4.2.2
Microsoft.Owin.Host.SystemWeb -Version 4.2.2
Microsoft.Owin.Security -Version 4.2.2
Microsoft.Owin.Security.Cookies -Version 4.2.2
Microsoft.Owin.Security.OpenIdConnect -Version 4.2.2
Microsoft.IdentityModel.Protocols.OpenIdConnect -Version 8.3.0
Microsoft.IdentityModel.Tokens -Version 8.3.0
using System;
using System.Configuration;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using Microsoft.Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.Google;
using Owin;
using TorquexMediaPlayer.Models;
namespace TorquexMediaPlayer
{
public partial class Startup
{
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// These values can be stored in Web.config or appSettings.json
string clientId = ConfigurationManager.AppSettings["ClientId"];
string clientSecret = ConfigurationManager.AppSettings["ClientSecret"];
string tenantId = ConfigurationManager.AppSettings["TenantId"];
// e.g., "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or "mytenant.onmicrosoft.com"
// Authority format: "https://login.microsoftonline.com/{tenantId}/v2.0"
string authority = $"https://login.microsoftonline.com/{tenantId}/v2.0";
// CookieAuthentication must be enabled for OWIN to store user information after sign-in
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
// Configure the OpenIdConnect middleware
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
RedirectUri = "https://localhost:44300/signin-oidc",
PostLogoutRedirectUri = "https://localhost:44300/",
Scope = OpenIdConnectScope.OpenIdProfile,
ResponseType = OpenIdConnectResponseType.CodeIdToken,
// Use the client secret to authenticate your app
ClientSecret = clientSecret,
// Token validation parameters
TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
// For single-tenant apps, validate the issuer to be your specific tenant
ValidIssuer = $"https://login.microsoftonline.com/{tenantId}/v2.0"
},
// Notification handlers
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
// Handle authentication failures
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return System.Threading.Tasks.Task.FromResult(0);
}
}
});
}
}
< /code>
Но когда я добавляю все пакеты в класс, я получил эти ошибки < /p>
'iappbuilder' не содержит определения для «UseOpenidConnectAuthateTentication», и нет доступного растяжения «useOpenidnectauthate» Использование директивы или ссылки на сборку?) < /p>
< /blockquote>
Тип или имя пространства имен 'openIdConnectAuthenticationOptions' не может быть найдено (вам не хватает указания директивы или ссылки на сборку?) 'OpenIdConnectAuthenticationNotifications' нельзя найти (вам не хватает использования директивы или ссылки на сборку?) /> Как решить эту проблему? < /p>
Подробнее здесь: https://stackoverflow.com/questions/793 ... entication
Мобильная версия