6

में जावास्क्रिप्ट क्लाइंट का उपयोग करते हुए पहचान सर्वर 4 में त्रुटि को मान्य करना मुझे अपने जावास्क्रिप्ट क्लाइंट एप्लिकेशन से मेरे पहचान सर्वर एप्लिकेशन से अनुरोध करते समय निम्न त्रुटि मिल रही है।स्कोप प्राप्त करना एस्पेन कोर

असफल: IdentityServer4.Validation.ScopeValidator [0] अमान्य गुंजाइश: openid

मुझे यकीन है कि मैं अपने पहचान सर्वर आवेदन में गुंजाइश जोड़ने बना दिया है। नीचे मेरा कोड है।

IdentityServer आवेदन (होस्ट) 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!"); 
     }); 
    } 
} 

वेब एपीआई Startup.cs

public class Startup 
{ 
    public Startup(IHostingEnvironment env) 
    { 
     var builder = new ConfigurationBuilder() 
      .SetBasePath(env.ContentRootPath) 
      .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) 
      .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); 

     if (env.IsEnvironment("Development")) 
     { 
      // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately. 
      builder.AddApplicationInsightsSettings(developerMode: true); 
     } 

     builder.AddEnvironmentVariables(); 
     Configuration = builder.Build(); 
    } 

    public IConfigurationRoot Configuration { get; } 

    // This method gets called by the runtime. Use this method to add services to the container 
    public void ConfigureServices(IServiceCollection services) 
    { 
     // Add framework services. 
     services.AddApplicationInsightsTelemetry(Configuration); 

     services.AddCors(option => 
     { 
      option.AddPolicy("dafault", policy => 
      { 
       policy.WithOrigins("http://localhost:5003") 
         .AllowAnyHeader() 
         .AllowAnyMethod(); 
      }); 
     }); 
     services.AddMvcCore() 
       .AddAuthorization() 
       .AddJsonFormatters(); 
    } 

    // 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(Configuration.GetSection("Logging")); 
     loggerFactory.AddDebug(); 

     //this uses the policy called "default" 
     app.UseCors("default"); 

     app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions 
     { 
      Authority = "http://localhost:5000", 
      AllowedScopes = { "api1" }, 
      RequireHttpsMetadata = false 
     }); 

     app.UseApplicationInsightsRequestTelemetry(); 

     app.UseApplicationInsightsExceptionTelemetry(); 

     app.UseMvc(); 
    } 
} 
+0

im का सामना दस्तावेज में एक ही नमूना का पालन करते समय एक ही त्रुटि। क्या आपके पास कोई भाग्य है? – alessalessio

उत्तर

17

अपने ग्राहक (आवेदन) कॉन्फ़िगर या openid संसाधन (या क्षेत्र) अनुरोध करने की अनुमति है, वहीं अपनी पहचान सर्वर OpenID पहचान संसाधन के लिए कॉन्फ़िगर नहीं है

आप के लिए इसी तरह एक पहचान संसाधन के रूप में जोड़ने की जरूरत यह here कैसे किया गया है और एक ऐसा तरीका है जो आपके सभी पहचान संसाधनों को लौटाता है जिनका उपयोग आप here जैसे करना चाहते हैं।

संक्षेप में अपने Config.cs करने के लिए एक नई विधि जोड़ने लग रहा है कि इस तरह: सेवा कंटेनर इस तरह अपनी पहचान संसाधन विन्यास जोड़ने

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

और फिर अपने identityservers रहे हैं:

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

अब यह काम कर रहा है, लेकिन अब यह दिखा रहा है लॉगिन दिखा रहा है: उपयोगकर्ता प्रमाणीकृत नहीं है – maxspan

+0

लॉग आपके दोस्त हैं, क्या आपका कंसोल ट्रेस स्तर पर लॉगिंग है? – Lutando

+0

हां। यह पहचान Server4 दिखा रहा है। ReesponseHandling.AuthorizeInteractionResponseGenerator [0] उपयोगकर्ता प्रमाणीकृत नहीं है। मैं उपयोगकर्ता को – maxspan

संबंधित मुद्दे