<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Faizaan Shaikh on Medium]]></title>
        <description><![CDATA[Stories by Faizaan Shaikh on Medium]]></description>
        <link>https://medium.com/@s.faizaan7?source=rss-f60f81cab6e4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LxrOgItnwJAnKLnh-zhFfg.png</url>
            <title>Stories by Faizaan Shaikh on Medium</title>
            <link>https://medium.com/@s.faizaan7?source=rss-f60f81cab6e4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 19:53:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@s.faizaan7/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Manage the secrets using ASP.NET Core secret manager with Visual Studio]]></title>
            <link>https://medium.com/@s.faizaan7/manage-the-secrets-using-asp-net-core-secret-manager-with-visual-studio-f254bb0bab91?source=rss-f60f81cab6e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f254bb0bab91</guid>
            <category><![CDATA[visual-studio]]></category>
            <category><![CDATA[application-configuration]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[aspnetcore]]></category>
            <category><![CDATA[secrets]]></category>
            <dc:creator><![CDATA[Faizaan Shaikh]]></dc:creator>
            <pubDate>Sat, 20 Jun 2020 21:58:50 GMT</pubDate>
            <atom:updated>2020-07-30T14:42:22.334Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AJVEPBcSqa-vab8NMadb-A.jpeg" /><figcaption>Photo by Elizabeth Porto on <a href="https://www.wallpaperflare.com/computer-security-technology-hack-hacker-hacking-lock-locks-wallpaper-aabzf">WallpaperFlare</a></figcaption></figure><h3>The Problem With Secrets…</h3><p>When working on a project, it&#39;s common that your <em>appsettings.json</em> contains sensitive configurations like connection strings, credentials, passwords, etc. called secrets. Developers need to be extra cautious to exclude these secrets from committing to version control systems which otherwise can <a href="https://alexanderpaterson.com/posts/this-is-what-happened-when-i-leaked-my-aws-secret-key">cause a disaster and cost a fortune.</a></p><p>Ideally, these secrets should be stored outside of the project tree. Some obvious paths a developer ends up with is either</p><ul><li>Keep the secrets in some Textpad/Notepad and use it whenever needed</li><li>Stash the secrets in local and apply it when needed</li><li>Add the local version of <em>appsettings.json</em> to git ignore list (although the secrets stay in the project)</li></ul><h3>Secret Manager To The Rescue!!</h3><p>ASP.NET Core provides a tool called Secret Manager that allows us to store the app secrets in a JSON configuration file outside the project. This file sits in the user profile folder on the local machine.</p><pre><strong>Windows<br></strong><em>%APPDATA%\Microsoft\UserSecrets\&lt;user_secrets_id&gt;\secrets.json</em></pre><pre><strong>Mac/Linux<br></strong><em>~/.microsoft/usersecrets/&lt;user_secrets_id&gt;/secrets.json</em></pre><p>The following GIF shows how to create secrets using the Secret Manager</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3i6CEQPm68cH_NX5B9DQeQ.gif" /><figcaption>Secret Manager in action</figcaption></figure><p>When the Secret Manager is initialized for a project, it creates a file called <em>secrets.json</em> at the location mentioned above. The <em>user_secrets_id</em> in the file location is usually a GUID. The same <em>user_secrets_id</em> is added to the <em>csproj</em> file of the project under <em>UserSecretsId</em>. This id can be changed to a meaningful name for better readability.</p><p>The ASP.NET Core framework uses one of the <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1">Configuration API</a> to load the secrets. By default, the secrets are read after <em>appsettings.json</em> and <em>appsettings.environment.json.</em></p><p>The secrets would be loaded automatically in the Development mode if the project is calling <em>CreateDefaultBuilder.</em></p><pre>public static IHostBuilder CreateHostBuilder(string[] args) =&gt;<br>Host.<strong>CreateDefaultBuilder</strong>(args)<br>    .ConfigureWebHostDefaults(webBuilder =&gt;<br>{<br>   webBuilder.UseStartup&lt;Startup&gt;();<br>});</pre><p>If <em>CreateDefaultBuilder</em> is not used, then you have to load it by explicitly calling <em>AddUserSecrets.</em></p><pre>var host = new HostBuilder()     .ConfigureAppConfiguration((hostContext, builder) =&gt;<br>{<br>   // Other providers</pre><pre>   if (hostContext.HostingEnvironment.IsDevelopment())         <br>   {             <br>      builder.<strong>AddUserSecrets</strong>&lt;Program&gt;();         <br>   }     <br>})     <br>.Build();</pre><p>You can further extend this functionality to load the secrets in a POCO. The Configuration API will bind the secrets to the custom properties of the POCO which can be accessed by the <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-3.1">Options pattern</a>.</p><pre>public void ConfigureServices(IServiceCollection services)<br>{<br>   services<strong>.</strong>Configure&lt;UserCredentials&gt;(<br>            configuration<strong>.</strong>GetSection(nameof(UserCredentials)))<br>           .AddSingleton(env)<strong>;</strong><br>}</pre><pre>//POCO<br>public class UserCredentials<br>{<br>   public string UserName { get; set; }<br>   public string Password { get; set; }<br>}</pre><h4>Few things to note</h4><ul><li>Secret Manager doesn’t encrypt the secrets and it should be used only for development purposes</li><li>It&#39;s a good practice to have the secret attributes in <em>appsettings.json </em>with values like <em>INVALID-{PropName}</em> which can act as failover and help in troubleshooting issues related to loading secrets.</li></ul><h3>Conclusion</h3><p>Secret Manager makes it really easy to work with secrets on the local machine and definitely makes the developer’s life easy!!</p><h3>References</h3><ul><li><a href="https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets">https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f254bb0bab91" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>