Identity Server 4 CORS not configured












0















I have put my IS4 on a server and lets call it http://test.myis4.com. Now I am trying to login with an angular application against it, however I keep getting blocked by CORS. The angular client is being served with an MVC Core application and it runs on http://localhost:5002 port. I have tried to do this from my localhost by running it on that port.



On the IS4 server I have tried adding on the client the following:



new Client {
// code is omitted
AllowedCorsOrigins = new List<string>() { "http://localhost:5002" }
}


With the above I still get the CORS error, then I have tried adding it to the services direclty:



var cors = new DefaultCorsPolicyService(null)
{
AllowedOrigins = { "http://localhost:5002" }
};
services.AddSingleton<ICorsPolicyService>(cors);
services.AddIdentityServer()
//rest omitted


The above still gave me the same CORS error, my last attempt was to add it through application builder as such:



app.UseCors(builder => builder.WithOrigins("http://localhost:5002").AllowAnyHeader());
app.UseIdentityServer();
//rest omitted


With this last attempt it still did not work. I'm not quire sure what I'm doing wrong at this point. Any suggestions?










share|improve this question





























    0















    I have put my IS4 on a server and lets call it http://test.myis4.com. Now I am trying to login with an angular application against it, however I keep getting blocked by CORS. The angular client is being served with an MVC Core application and it runs on http://localhost:5002 port. I have tried to do this from my localhost by running it on that port.



    On the IS4 server I have tried adding on the client the following:



    new Client {
    // code is omitted
    AllowedCorsOrigins = new List<string>() { "http://localhost:5002" }
    }


    With the above I still get the CORS error, then I have tried adding it to the services direclty:



    var cors = new DefaultCorsPolicyService(null)
    {
    AllowedOrigins = { "http://localhost:5002" }
    };
    services.AddSingleton<ICorsPolicyService>(cors);
    services.AddIdentityServer()
    //rest omitted


    The above still gave me the same CORS error, my last attempt was to add it through application builder as such:



    app.UseCors(builder => builder.WithOrigins("http://localhost:5002").AllowAnyHeader());
    app.UseIdentityServer();
    //rest omitted


    With this last attempt it still did not work. I'm not quire sure what I'm doing wrong at this point. Any suggestions?










    share|improve this question



























      0












      0








      0








      I have put my IS4 on a server and lets call it http://test.myis4.com. Now I am trying to login with an angular application against it, however I keep getting blocked by CORS. The angular client is being served with an MVC Core application and it runs on http://localhost:5002 port. I have tried to do this from my localhost by running it on that port.



      On the IS4 server I have tried adding on the client the following:



      new Client {
      // code is omitted
      AllowedCorsOrigins = new List<string>() { "http://localhost:5002" }
      }


      With the above I still get the CORS error, then I have tried adding it to the services direclty:



      var cors = new DefaultCorsPolicyService(null)
      {
      AllowedOrigins = { "http://localhost:5002" }
      };
      services.AddSingleton<ICorsPolicyService>(cors);
      services.AddIdentityServer()
      //rest omitted


      The above still gave me the same CORS error, my last attempt was to add it through application builder as such:



      app.UseCors(builder => builder.WithOrigins("http://localhost:5002").AllowAnyHeader());
      app.UseIdentityServer();
      //rest omitted


      With this last attempt it still did not work. I'm not quire sure what I'm doing wrong at this point. Any suggestions?










      share|improve this question
















      I have put my IS4 on a server and lets call it http://test.myis4.com. Now I am trying to login with an angular application against it, however I keep getting blocked by CORS. The angular client is being served with an MVC Core application and it runs on http://localhost:5002 port. I have tried to do this from my localhost by running it on that port.



      On the IS4 server I have tried adding on the client the following:



      new Client {
      // code is omitted
      AllowedCorsOrigins = new List<string>() { "http://localhost:5002" }
      }


      With the above I still get the CORS error, then I have tried adding it to the services direclty:



      var cors = new DefaultCorsPolicyService(null)
      {
      AllowedOrigins = { "http://localhost:5002" }
      };
      services.AddSingleton<ICorsPolicyService>(cors);
      services.AddIdentityServer()
      //rest omitted


      The above still gave me the same CORS error, my last attempt was to add it through application builder as such:



      app.UseCors(builder => builder.WithOrigins("http://localhost:5002").AllowAnyHeader());
      app.UseIdentityServer();
      //rest omitted


      With this last attempt it still did not work. I'm not quire sure what I'm doing wrong at this point. Any suggestions?







      c# cors asp.net-core-mvc identityserver4






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 15:36







      Bojan

















      asked Nov 23 '18 at 15:23









      BojanBojan

      2,092102773




      2,092102773
























          1 Answer
          1






          active

          oldest

          votes


















          0














          On the second code block, that you've shown - you need to first AddIdentityServer() and then add the Cors Policy service and you can also do it straight after adding Identity server to the services. Something like:



          services.AddIdentityServer(options =>
          {
          // .. if you need something in general (can go without the options)
          })
          .AddCorsPolicyService<YOUR_IMPLEMENTATION_OF_ICorsPolicyService>()
          // rest omitted


          This is because the AddIdentitiyServer() overwrites the adding of the CORS service - Code.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449261%2fidentity-server-4-cors-not-configured%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            On the second code block, that you've shown - you need to first AddIdentityServer() and then add the Cors Policy service and you can also do it straight after adding Identity server to the services. Something like:



            services.AddIdentityServer(options =>
            {
            // .. if you need something in general (can go without the options)
            })
            .AddCorsPolicyService<YOUR_IMPLEMENTATION_OF_ICorsPolicyService>()
            // rest omitted


            This is because the AddIdentitiyServer() overwrites the adding of the CORS service - Code.






            share|improve this answer




























              0














              On the second code block, that you've shown - you need to first AddIdentityServer() and then add the Cors Policy service and you can also do it straight after adding Identity server to the services. Something like:



              services.AddIdentityServer(options =>
              {
              // .. if you need something in general (can go without the options)
              })
              .AddCorsPolicyService<YOUR_IMPLEMENTATION_OF_ICorsPolicyService>()
              // rest omitted


              This is because the AddIdentitiyServer() overwrites the adding of the CORS service - Code.






              share|improve this answer


























                0












                0








                0







                On the second code block, that you've shown - you need to first AddIdentityServer() and then add the Cors Policy service and you can also do it straight after adding Identity server to the services. Something like:



                services.AddIdentityServer(options =>
                {
                // .. if you need something in general (can go without the options)
                })
                .AddCorsPolicyService<YOUR_IMPLEMENTATION_OF_ICorsPolicyService>()
                // rest omitted


                This is because the AddIdentitiyServer() overwrites the adding of the CORS service - Code.






                share|improve this answer













                On the second code block, that you've shown - you need to first AddIdentityServer() and then add the Cors Policy service and you can also do it straight after adding Identity server to the services. Something like:



                services.AddIdentityServer(options =>
                {
                // .. if you need something in general (can go without the options)
                })
                .AddCorsPolicyService<YOUR_IMPLEMENTATION_OF_ICorsPolicyService>()
                // rest omitted


                This is because the AddIdentitiyServer() overwrites the adding of the CORS service - Code.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 26 '18 at 21:08









                m3n7alsnak3m3n7alsnak3

                1,6481515




                1,6481515






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449261%2fidentity-server-4-cors-not-configured%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    TypeError: fit_transform() missing 1 required positional argument: 'X'