Skip to content

Instantly share code, notes, and snippets.

@peteraritchie
Last active February 16, 2024 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peteraritchie/79e6d840f47ba8d6ae80da9fe09fe0ae to your computer and use it in GitHub Desktop.
Save peteraritchie/79e6d840f47ba8d6ae80da9fe09fe0ae to your computer and use it in GitHub Desktop.

Visual Studio HTTP Files

env

{
  "dev": {
    "ClientSecret": {
      "provider": "AzureKeyVault",
      "secretName": "clientSecret",
      "resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-resource-group/providers/Microsoft.KeyVault/vaults/my-keyvault"
    },
    "ClientId": {
      "provider": "AzureKeyVault",
      "secretName": "clientId",
      "resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-resource-group/providers/Microsoft.KeyVault/vaults/my-keyvault"
    }
}

Requests

POST https://example.com/oauth2/v1/token
Content-Type: application/json
Accept-Language: en-US,en;q=0.5

{
  "client_id": "{{clientId}}",
  "client_secret": "{{clientSecret}}",
  "grant_type": "client_credentials"
}
###

GET https://example.com/api/v1/health
Authorization: Bearer {{AccessToken}}
Accept: application/json

###

Set user-secret

$r = Invoke-RestMethod -Method Post -URI "https://example.com/oauth2/v1/token" -ContentType 'application/json' -Body (ConvertTo-Json @{'grant_type'='client_credentials'; 'client_id' = $clientId; 'client_secret' = $clientSecret});
dotnet user-secrets set AccessToken $r.access_token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment