{"id":4094,"date":"2023-05-04T19:42:38","date_gmt":"2023-05-04T18:42:38","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=4094"},"modified":"2023-05-04T19:42:38","modified_gmt":"2023-05-04T18:42:38","slug":"easily-get-access-token-for-azure-management-api","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2023\/05\/easily-get-access-token-for-azure-management-api\/","title":{"rendered":"Easily get access token for Azure Management API"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Wrote this little snippet that assumes a logged in session (Connect-AzAccount) and easily\/quickly produces an auth header.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nfunction get-azRMAccessHeader(){\n    $profile = &#x5B;Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile\n    $context = Get-AzContext\n    $client = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($profile)\n\n    $header = @{\n        \"Authorization\" = \"Bearer $($client.AcquireAccessToken((Get-AzContext).Tenant.TenantId).AccessToken)\"\n    }\n    return $header\n}\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Wrote this little snippet that assumes a logged in session (Connect-AzAccount) and easily\/quickly produces an auth header.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[4,5,39,43],"tags":[],"class_list":["post-4094","post","type-post","status-publish","format-standard","hentry","category-automation","category-azure","category-powershell","category-security"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/4094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=4094"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/4094\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=4094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=4094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=4094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}