Я использую IdentityServer3 и получаю сообщение об ошибке «Клиентское приложение неизвестно или не авторизовано».
Я проверил все рекомендуемые решения для Git и других запросов stackoverflow, но все еще не могу разрешить его.
Я создал API, мой Idp и веб-клиент.Веб-клиент вызывает API, используя идентификационный сервер thinktecture.Здесь мои авторизационные конечные точки WebAPI не попадают.Поскольку у меня возникли проблемы, я попытался сделать авторизованные вызовы внутри самого своего idp.
Ниже приведен мой код:
Файл StartUp.cs
public void ConfigureAuth(IAppBuilder app)
{
// Configure Identity Server
// at the identity uri, you are going to find the identity server
app.Map("/identity", idsrvApp =>
{
idsrvApp.UseIdentityServer(new IdentityServerOptions
{
SiteName = "Embedded identity server",
//IssuerUri = "https://identitysrv3/embedded", // in real scenarios make sure this is unique. to uniquely identify users
Factory = new IdentityServerServiceFactory()
.UseInMemoryClients(Clients.Get())
.UseInMemoryScopes(Scopes.Get())
.UseInMemoryUsers(User.Get()),
// this is not for SSL, that will be provided by IIS or Azure where we deploy. This is to sign the tokens
SigningCertificate = LoadCertificate()
});
});
X509Certificate2 LoadCertificate()
{
return new X509Certificate2(
string.Format(@"{0}\bin\identityServer\idsrv3test.pfx", AppDomain.CurrentDomain.BaseDirectory), "idsrv3test");
}
#region test purpose
app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
ClientId = "mvc",
Authority = "https://localhost:44329/identity",//AppConstants.IdSrv,
RedirectUri = "https://localhost:44329/", //AppConstants.IdClient,
SignInAsAuthenticationType = "Cookies",
ResponseType = "code id_token",
Scope = "openid",
Notifications = new OpenIdConnectAuthenticationNotifications()
{
//MessageReceived = async n =>
//{
// EndpointAndTokenHelper.DecodeAndWrite(n.ProtocolMessage.IdToken);
//}
}
});
Мой класс клиента:
public static class Clients
{
public static IEnumerable<Client> Get()
{
return new[]
{
new Client
{
Enabled = true,
ClientName = "Identity Server Web Access",
ClientId = "mvc",
Flow = Flows.Hybrid,
//RequireConsent = true,
RedirectUris=new List<string>
{
"https://localhost:44329/"
}
}
};
}
}
Мой класс Scope:
public static class Scopes
{
public static IEnumerable<Scope> Get()
{
var scopes = new List<Scope>
{
// identity scope. This is the intent
StandardScopes.OpenId,
//StandardScopes.Profile
};
return scopes;
}
}
и мой пользовательский класс:
public static class User
{
public static List<InMemoryUser> Get()
{
return new List<InMemoryUser>()
{
new InMemoryUser
{
Username = "Sidd",
Password = "secret",
Subject = "1",
Claims = new[]
{
new Claim(Constants.ClaimTypes.GivenName, "Sidd"),
new Claim(Constants.ClaimTypes.FamilyName, "Mehta"),
}
},
new InMemoryUser
{
Username = "Humpty",
Password = "secret",
Subject = "1",
Claims = new[]
{
new Claim(Constants.ClaimTypes.GivenName, "Humpty"),
new Claim(Constants.ClaimTypes.FamilyName, "Sharma"),
}
},
new InMemoryUser
{
Username = "Virat",
Password = "secret",
Subject = "1",
Claims = new[]
{
new Claim(Constants.ClaimTypes.GivenName, "Virat"),
new Claim(Constants.ClaimTypes.FamilyName, "Kohli"),
}
}
};
}
}
и мой авторизованный контроллер действий:
[Authorize]
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
Я вызываю URI перенаправления в конце с "/", используя надлежащие https, используя соответствующие типы потока и ответа соответственно, но все еще у меня возникают проблемы.
![enter image description here](https://i.stack.imgur.com/RR98a.png)
Если я смогу разобраться с этим, то я смогу совершать регулярные вызовы из моего проекта веб-клиента вместо API, используя idte thinktecture, и вместо этого изменять перенаправления URI на мой веб-клиент.
Любойпомощь или недостатки или предложения в моем коде выше было бы здорово.
Заранее спасибо !!! ..