6

Javascript İstemci Uygulamdan Identity Server uygulamasına bir istekte bulunurken aşağıdaki hatayı alıyorum.Kapsam Başlarken asp.net çekirdeğinde JavaScript İstemcisi'ni kullanarak Identity Server 4'te doğrulanma hatası

başarısız: IdentityServer4.Validation.ScopeValidator [0] geçersiz kapsam: Openid

benim Kimlik Sunucusu uygulamasında kapsam eklemek emin yaptık. Aşağıda kodum.

IdentityServer Uygulaması (Sunucu) Config.cs

public class Config 
{ 
    public static IEnumerable<ApiResource> GetApiResources() 
    { 
     return new List<ApiResource> 
     { 
      new ApiResource("api1","My API") 
     }; 
    } 

    public static IEnumerable<Client> GetClients() 
    { 
     return new List<Client> 
     { 
      new Client 
      { 
       ClientId = "js", 
       ClientName = "javaScript Client", 
       AllowedGrantTypes = GrantTypes.Implicit, 
       AllowAccessTokensViaBrowser = true, 
       RedirectUris = { "http://localhost:5003/callback.html" }, 
       PostLogoutRedirectUris = { "http://localhost:5003/index.html" }, 
       AllowedCorsOrigins = { "http://localhost:5003" }, 
       AllowedScopes = 
        { 
         IdentityServerConstants.StandardScopes.OpenId, 
         IdentityServerConstants.StandardScopes.Profile, 
         "api1" 
        } 
      } 
     }; 
    } 
} 

Startup.cs

public class Startup 
{ 
    // This method gets called by the runtime. Use this method to add services to the container. 
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 
    public void ConfigureServices(IServiceCollection services) 
    { 

     services.AddIdentityServer() 
      .AddTemporarySigningCredential() 
      .AddInMemoryApiResources(Config.GetApiResources()) 
      .AddInMemoryClients(Config.GetClients()); 
    } 

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
    { 
     loggerFactory.AddConsole(); 

     if (env.IsDevelopment()) 
     { 
      app.UseDeveloperExceptionPage(); 
      app.UseIdentityServer(); 
     } 

     app.Run(async (context) => 
     { 
      await context.Response.WriteAsync("Hello World!"); 
     }); 
    } 
} 

Web API Startup.cs

istemci (uygulama) yapılandırılmış veya Openid kaynak (veya kapsamı) istemek için izin verilir iken
+0

im karşılaşmadan Kısacası

şuna benzer senin Config.cs için yeni bir yöntem eklemek aynı örnek belgeleri izlerken aynı hata. şansın var mı – alessalessio

cevap

17

, kimlik sunucu

Sen benzer bir kimlik kaynağı olarak eklemek gerekir Openid kimlik kaynak için yapılandırılmamış Nasıl yapılır here ve bitmiş gibi kullanmak istediğiniz tüm kimlik kaynaklarınızı döndüren bir yönteme sahip here. Servis kabı böyle Kimlik kaynak yapılandırması eklemek için identityservers sonra

public static List<IdentityResource> GetIdentityResources() 
{ 
    return new List<IdentityResource> 
    { 
     new IdentityResources.OpenId() 
     new IdentityResources.Profile() // <-- usefull 
    } 
} 

Ve:

services.AddIdentityServer() 
    .AddTemporarySigningCredential() 
    .AddInMemoryApiResources(Config.GetApiResources()) 
    .AddInMemoryClients(Config.GetClients()); 
    .AddInMemoryIdentityResources(Config.GetIdentityResources()) // <-- adding identity resources/scopes 
+0

Onun şimdi çalışıyor, Ama şimdi onun gösteriliyor Gösterilen giriş: Kullanıcı kimliği doğrulanmamış – maxspan

+0

Günlükler arkadaşınız, konsolunuz izleme düzeyinde oturum açıyor mu? – Lutando

+0

evet. IdentityServer4.ResponseHandling.AuthorizeInteractionResponseGenerator [0] Kullanıcı kimliği doğrulanmamıştır. Kullanıcı kimliğini nasıl doğrularım? – maxspan