{"id":100879,"date":"2019-09-23T18:25:20","date_gmt":"2019-09-23T18:25:20","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/aspnet\/?p=22570"},"modified":"2019-09-23T18:25:20","modified_gmt":"2019-09-23T18:25:20","slug":"setting-http-header-attributes-to-enable-azure-authentication-authorization-using-httprepl","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2019\/09\/23\/setting-http-header-attributes-to-enable-azure-authentication-authorization-using-httprepl\/","title":{"rendered":"Setting HTTP header attributes to enable Azure authentication\/authorization using HTTPRepl"},"content":{"rendered":"<div class=\"row justify-content-center\">\n<div class=\"col-md-4\">\n<div><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2019\/09\/setting-http-header-attributes-to-enable-azure-authentication-authorization-using-httprepl.jpg\" width=\"58\" height=\"58\" alt=\"Angelos Petropoulos\" class=\"avatar avatar-58 wp-user-avatar wp-user-avatar-58 alignnone photo\"><\/p>\n<p>Angelos<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"entry-meta\">\n<p>September 23rd, 2019<\/p>\n<\/p><\/div>\n<p><!-- .entry-meta --> <\/p>\n<h5>Posted on behalf of Ahmed Metwally<\/h5>\n<p> The HTTP Read-Eval-Print Loop (REPL) is a lightweight, cross-platform command-line tool that\u2019s supported everywhere .NET Core is supported. It\u2019s used for making HTTP requests to test ASP.NET Core web APIs and view their results. You can use the HTTPRepl to navigate and interrogate any API in the same manner that you would navigate a set of folders on a file system. If the service that you are testing has a <em>swagger.json<\/em> file, specifying that file to HTTPRepl will enable auto-completion.\n<\/p>\n<p> To install the HTTP REPL, run the following command:\n<\/p>\n<pre><code>&gt;dotnet tool install -g Microsoft.dotnet-httprepl\n<\/code><\/pre>\n<p>\n<br \/>For more information on how to use HTTPRepl, read Angelos\u2019 post on the ASP.NET blog. As we continue to improve the tool, we look to add new commands to facilitate the use of HTTPRepl with different types of secure API services. As of this release, HTTPRepl supports authentication and authorization schemes achievable through header manipulation, like basic, bearer token, and digest authentication. For example, to use a bearer token to authenticate to a service, use the command \u201cset header\u201d. Set the \u201cAuthorization\u201d header to the bearer token value using the following command:\n<\/p>\n<pre><code>&gt;set header Authorization \u201cbearer &lt;token_value&gt;\u201d\n<\/code><\/pre>\n<p>And replace <em>&lt;token_value&gt;<\/em> with your authorization bearer token for the service. Don\u2019t forget to use the quotation marks to wrap the word <em>bearer<\/em> along with the <em>&lt;token_value&gt;<\/em> in the same literal string. Otherwise, the tool will treat them as two different values and will fail to set the header properly. To ensure that the header in the HTTP request is being formatted as expected, enable echoing using the \u201cecho on\u201d command.\n<\/p>\n<p> Using the \u201cset header\u201d command, you can leverage HTTPRepl to test and navigate any secure REST API service including your Azure-hosted API services or the Azure Management API. To access a secure service hosted on Azure, you need a bearer token. Get a bearer token for your Azure subscription, <a href=\"https:\/\/docs.microsoft.com\/cli\/azure\/authenticate-azure-cli?view=azure-cli-latest\">using the Azure CLI to get an access token for the required Azure subscription<\/a>:\n<\/p>\n<pre><code>&gt;az login\n<\/code><\/pre>\n<p>Copy your subscription ID from the <a href=\"https:\/\/portal.azure.com\">Azure portal<\/a> and paste it in the \u201caz account set\u201d command:\n<\/p>\n<pre><code>&gt;az account set --subscription \"&lt;subscription ID&gt;\" &gt;az account get-access-token { \"accessToken\": \"&lt;access_token_will_be_displayed_here&gt;\", \"expiresOn\": \"&lt;expiry date\/time will be displayed here&gt;\", \"subscription\": \"&lt;subscription ID&gt;\", \"tenant\": \"&lt;tenant ID&gt;\", \"tokenType\": \"Bearer\" } <\/code><\/pre>\n<p>Copy the text that appears in place of <strong>&lt;access_token_will_be_displayed_here&gt;.<\/strong> This is your access token. Finally, run HTTPRepl:\n<\/p>\n<pre><code>&gt;httprepl\n(disconnected)~ connect https:\/\/management.azure.com\nUsing a base address of https:\/\/management.azure.com\/\nUnable to find a swagger definition\nhttps:\/\/management.azure.com\/~ set header Authorization \"bearer &lt;em&gt;&amp;lt;paste_token_here&amp;gt;&lt;\/em&gt;\"\nhttps:\/\/management.azure.com\/~ cd subscriptions\nhttps:\/\/management.azure.com\/subscriptions\/~ cd &lt;subscription_ID&gt;\n<\/code><\/pre>\n<p>For example, to search for a <a href=\"https:\/\/docs.microsoft.com\/rest\/api\/appservice\/WebApps\/List\">list of your Azure app services<\/a>, issue the \u201cget\u201d command for the list of sites through the Microsoft web provider:\n<\/p>\n<pre><code> https:\/\/management.azure.com\/subscriptions\/&lt;subscription_ID&gt;\/~ get providers\/Microsoft.Web\/sites?api-version=2016-08-01 HTTP\/1.1 200 OK Cache-Control: no-cache Content-Length: 35948 Content-Type: application\/json; charset=utf-8 Date: Thu, 19 Sep 2019 23:04:03 GMT Expires: -1 Pragma: no-cache Strict-Transport-Security: max-age=31536000; includeSubDomains X-Content-Type-Options: nosniff x-ms-correlation-request-id: &lt;em&gt;xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&lt;\/em&gt; x-ms-original-request-ids: &lt;em&gt;xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&lt;\/em&gt; x-ms-ratelimit-remaining-subscription-reads: 11999 x-ms-request-id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx x-ms-routing-request-id: WESTUS:xxxxxxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx { \"value\": [\n&lt;list of azure resources&gt; ] } https:\/\/management.azure.com\/subscriptions\/&lt;subscription_ID&gt;\/~\n<\/code><\/pre>\n<p> You can use the full list of Azure REST APIs to browse and manage services in your Azure subscriptions. For more details on how HTTPRepl works, please check the ASPNET blog. To use HTTPRepl, download and install the global tool from the .NET Core CLI.\n<\/p>\n<h2>Give us feedback<\/h2>\n<p> It\u2019s not HTTPie, it\u2019s not Curl, but it\u2019s also not PostMan. It\u2019s something that you run and stays running and its aware of its current context. We find this experience valuable, but ultimately what matters the most is what you think. Please let us know your opinion by leaving comments below or on <a href=\"https:\/\/github.com\/aspnet\/HttpRepl\">GitHub<\/a>.\n<\/p>\n<hr>\n<p> Ahmed Metwally, Sr. Program Manager, .NET dev tools <a href=\"https:\/\/twitter.com\/AhmedMsft\">@ahmedMsft<\/a>Ahmed is a Program Manager on the .NET tooling team focused on improving web development for .NET developers.<\/p>\n<div class=\"authorinfoarea\">\n<div><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2019\/09\/setting-http-header-attributes-to-enable-azure-authentication-authorization-using-httprepl.jpg\" width=\"96\" height=\"96\" alt=\"Angelos Petropoulos\" class=\"avatar avatar-96 wp-user-avatar wp-user-avatar-96 alignnone photo\"><\/div>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Angelos September 23rd, 2019 Posted on behalf of Ahmed Metwally The HTTP Read-Eval-Print Loop (REPL) is a lightweight, cross-platform command-line tool that\u2019s supported everywhere .NET Core is supported. It\u2019s used for making HTTP requests to test ASP.NET Core web APIs and view their results. You can use the HTTPRepl to navigate and interrogate any API [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":100880,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66,1],"tags":[102],"class_list":["post-100879","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-webdev","category-uncategorized","tag-uncategorized"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/100879","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=100879"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/100879\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media\/100880"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=100879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=100879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=100879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}