{"id":1416,"date":"2020-10-13T09:07:49","date_gmt":"2020-10-13T01:07:49","guid":{"rendered":"https:\/\/jrblog.pentaidea.com\/john\/2020\/10\/13\/build-identityserver3-with-netcore3-1\/"},"modified":"2020-10-13T09:07:49","modified_gmt":"2020-10-13T01:07:49","slug":"build-identityserver3-with-netcore3-1","status":"publish","type":"post","link":"https:\/\/john.pentaidea.com\/?p=1416","title":{"rendered":"Build IdentityServer3 with NetCore3.1"},"content":{"rendered":"<ul>\n<li>\n<p><span style=\"font-weight: bold\">IdentityServer3.1.6 &#8211;&nbsp;<\/span><span style=\"font-weight: bold\">Add KeySet&nbsp;<\/span><\/p>\n<\/li>\n<ul>\n<li>\n<p><span style=\"font-weight: bold\">Generate cert.pfx<\/span><\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<pre><code># cd to project root\n&quot;C:\\Program Files\\Git\\usr\\bin\\openssl.exe&quot; genrsa 2048 &gt; private.pem\n&quot;C:\\Program Files\\Git\\usr\\bin\\openssl.exe&quot; req -x509 -days 1000 -new -key private.pem -out public.pem\n&quot;C:\\Program Files\\Git\\usr\\bin\\openssl.exe&quot; pkcs12 -export -in public.pem -inkey private.pem -out mycert.pfx\n<\/code><\/pre>\n<ul>\n<ul>\n<li>\n<p><span style=\"font-weight: bold\">Add to startup.cs<\/span><\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<pre><code>using System.IO;\nusing System.Security.Cryptography;\nusing System.Security.Cryptography.X509Certificates;\n\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;X509Certificate2 cert = new X509Certificate2(Path.Combine(Directory.GetCurrentDirectory(), &quot;mycert.pfx&quot;), &quot;&quot;);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(&quot;cert private key: &quot; + cert.PrivateKey);\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;services.AddIdentityServer()\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;.AddSigningCredential(cert)\n<\/code><\/pre>\n<ul>\n<ul>\n<li>\n<p><span style=\"font-weight: bold\">Add to appsettings.json<\/span><\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<pre><code>&quot;IdentityServer&quot;: {\n&nbsp;&nbsp;&nbsp;&nbsp;&quot;Key&quot;: {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;Type&quot;: &quot;File&quot;,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;FilePath&quot;: &quot;mycert.pfx&quot;,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;Password&quot;: &quot;password123&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;}\n<\/code><\/pre>\n<ul>\n<ul>\n<li>\n<p>Include file to project: *.csproj<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<pre><code>&nbsp;&nbsp;&lt;ItemGroup&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;None Update=&quot;mycert.pfx&quot; CopyToOutputDirectory=&quot;PreserveNewest&quot; ExcludeFromSingleFile=&quot;true&quot; \/&gt;\n&nbsp;&nbsp;&lt;\/ItemGroup&gt;\n<\/code><\/pre>\n<p><b><\/b><\/p>\n<p><b><\/b><\/p>\n<ul>\n<li>\n<p><b>FAQ&nbsp;<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>fix http url issue in startup.cs<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<pre><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#region Fix idSrv3 keep http:\/\/ issue\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var forwardOptions = new ForwardedHeadersOptions\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Needed because of mixing http and https.\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RequireHeaderSymmetry = false,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};\n\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Accept X-Forwarded-* headers from all sources.\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;forwardOptions.KnownNetworks.Clear();\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;forwardOptions.KnownProxies.Clear();\n\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;app.UseForwardedHeaders(forwardOptions);&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#endregion&nbsp;&nbsp;&nbsp;&nbsp;\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>IdentityServer3.1.6 &#8211;&nbsp;Add KeySet&nbsp;<\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1416","post","type-post","status-publish","format-standard","hentry","category-tech"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Build IdentityServer3 with NetCore3.1 - John&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/john.pentaidea.com\/?p=1416\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Build IdentityServer3 with NetCore3.1 - John&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"IdentityServer3.1.6 -&nbsp;Add KeySet&nbsp;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/john.pentaidea.com\/?p=1416\" \/>\n<meta property=\"og:site_name\" content=\"John&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-13T01:07:49+00:00\" \/>\n<meta name=\"author\" content=\"jj\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"jj\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/john.pentaidea.com\/?p=1416\",\"url\":\"https:\/\/john.pentaidea.com\/?p=1416\",\"name\":\"Build IdentityServer3 with NetCore3.1 - John&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/john.pentaidea.com\/#website\"},\"datePublished\":\"2020-10-13T01:07:49+00:00\",\"dateModified\":\"2020-10-13T01:07:49+00:00\",\"author\":{\"@id\":\"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f\"},\"breadcrumb\":{\"@id\":\"https:\/\/john.pentaidea.com\/?p=1416#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/john.pentaidea.com\/?p=1416\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/john.pentaidea.com\/?p=1416#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/john.pentaidea.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Build IdentityServer3 with NetCore3.1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/john.pentaidea.com\/#website\",\"url\":\"https:\/\/john.pentaidea.com\/\",\"name\":\"John's Blog\",\"description\":\"\u4e16\u754c\u56e0\u601d\u7dd2\u800c\u8907\u96dc, \u4eba\u56e0\u5922\u60f3\u800c\u5049\u5927\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/john.pentaidea.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f\",\"name\":\"jj\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/john.pentaidea.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g\",\"caption\":\"jj\"},\"sameAs\":[\"https:\/\/john.pentaidea.com\"],\"url\":\"https:\/\/john.pentaidea.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Build IdentityServer3 with NetCore3.1 - John&#039;s Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/john.pentaidea.com\/?p=1416","og_locale":"en_US","og_type":"article","og_title":"Build IdentityServer3 with NetCore3.1 - John&#039;s Blog","og_description":"IdentityServer3.1.6 -&nbsp;Add KeySet&nbsp;","og_url":"https:\/\/john.pentaidea.com\/?p=1416","og_site_name":"John&#039;s Blog","article_published_time":"2020-10-13T01:07:49+00:00","author":"jj","twitter_card":"summary_large_image","twitter_misc":{"Written by":"jj","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/john.pentaidea.com\/?p=1416","url":"https:\/\/john.pentaidea.com\/?p=1416","name":"Build IdentityServer3 with NetCore3.1 - John&#039;s Blog","isPartOf":{"@id":"https:\/\/john.pentaidea.com\/#website"},"datePublished":"2020-10-13T01:07:49+00:00","dateModified":"2020-10-13T01:07:49+00:00","author":{"@id":"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f"},"breadcrumb":{"@id":"https:\/\/john.pentaidea.com\/?p=1416#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/john.pentaidea.com\/?p=1416"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/john.pentaidea.com\/?p=1416#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/john.pentaidea.com\/"},{"@type":"ListItem","position":2,"name":"Build IdentityServer3 with NetCore3.1"}]},{"@type":"WebSite","@id":"https:\/\/john.pentaidea.com\/#website","url":"https:\/\/john.pentaidea.com\/","name":"John's Blog","description":"\u4e16\u754c\u56e0\u601d\u7dd2\u800c\u8907\u96dc, \u4eba\u56e0\u5922\u60f3\u800c\u5049\u5927","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/john.pentaidea.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f","name":"jj","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/john.pentaidea.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g","caption":"jj"},"sameAs":["https:\/\/john.pentaidea.com"],"url":"https:\/\/john.pentaidea.com\/?author=1"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/posts\/1416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1416"}],"version-history":[{"count":0,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/posts\/1416\/revisions"}],"wp:attachment":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}