admin管理员组文章数量:1405908
I need to store a username and password in my .http
file in Visual Studio in a secure and easy way so that it is not checked into source control accidentally.
@MyAuth.Auth_HostAddress = http://localhost:5085
POST {{MyAuth.Auth_HostAddress}}/api/v1/auth/login
Content-Type: application/json
{
"username": "myusername",
"password": "mypassword"
}
I need to store a username and password in my .http
file in Visual Studio in a secure and easy way so that it is not checked into source control accidentally.
@MyAuth.Auth_HostAddress = http://localhost:5085
POST {{MyAuth.Auth_HostAddress}}/api/v1/auth/login
Content-Type: application/json
{
"username": "myusername",
"password": "mypassword"
}
Share
Improve this question
asked Mar 7 at 6:38
Rizan ZakyRizan Zaky
4,6925 gold badges29 silver badges41 bronze badges
1 Answer
Reset to default 0In Visual Studio you can achieve this using environment files, specifically user-specific environment files.
To start with,
Add a file called
http-client.env.json
in the same directory as the.http
file. By default, this file is set to check into source control.
This file can be left blank, if you don't have any values checked in.{ }
Add another file called
http-client.env.json.user
in the same directory. This is where the secret values go in. By default, this file is set not to check into source control.
In this file you can set the secrets under an environment root,{ "dev": { "Username": "myusername1", "Password": "mypassword1" }, "prod": { "Username": "myusername2", "Password": "mypassword2" } }
Now in the
.http
file access the defined variable using{{ }}
,
In this example, the environment variable file values are read into.http
file variables,@UsernameVar = {{Username}} @PasswordVar = {{Password}}
then used as needed,
POST {{MyAuth.Auth_HostAddress}}/api/v1/auth/login Content-Type: application/json { "username": "{{UsernameVar}}", "password": "{{PasswordVar}}" }
Finally you can switch environments from the defined list of environemnts in the top right corner of Visual Studio
.http
file editor,
本文标签: How to store secure variable values in http files in Visual StudioStack Overflow
版权声明:本文标题:How to store secure variable values in .http files in Visual Studio? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744944824a2633709.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论