{"id":21500980,"url":"https://github.com/tksh164/cpprest-azure-rest-api-sample","last_synced_at":"2026-05-20T02:42:11.068Z","repository":{"id":230832286,"uuid":"780192742","full_name":"tksh164/cpprest-azure-rest-api-sample","owner":"tksh164","description":"This repo contains Azure REST API samples using C++ REST SDK (cpprestsdk).","archived":false,"fork":false,"pushed_at":"2024-04-02T05:22:13.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-23T22:49:29.274Z","etag":null,"topics":["azure","cpp","rest-api"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tksh164.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-04-01T00:14:17.000Z","updated_at":"2024-04-03T17:14:12.000Z","dependencies_parsed_at":"2024-04-01T06:27:55.762Z","dependency_job_id":"efd8c121-a244-49c5-8f0f-293731606f79","html_url":"https://github.com/tksh164/cpprest-azure-rest-api-sample","commit_stats":null,"previous_names":["tksh164/cpprest-azure-rest-api-sample"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tksh164%2Fcpprest-azure-rest-api-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tksh164%2Fcpprest-azure-rest-api-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tksh164%2Fcpprest-azure-rest-api-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tksh164%2Fcpprest-azure-rest-api-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tksh164","download_url":"https://codeload.github.com/tksh164/cpprest-azure-rest-api-sample/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244039202,"owners_count":20387835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure","cpp","rest-api"],"created_at":"2024-11-23T17:48:42.514Z","updated_at":"2026-05-20T02:42:11.017Z","avatar_url":"https://github.com/tksh164.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Azure REST API samples using C++ REST SDK (cpprestsdk)\n\nThis repo contains Azure REST API samples using C++ REST SDK (cpprestsdk).\n\n- [OAuth 2.0 client credentials flow sample](#oauth-20-client-credentials-flow-sample)\n- [OAuth 2.0 device authorization grant flow sample](#oauth-20-device-authorization-grant-flow-sample)\n\n## OAuth 2.0 client credentials flow sample\n\nThis sample do the following:\n\n1. Get an access token from Microsoft Entra ID with your service principal using the [OAuth 2.0 client credentials flow](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-client-creds-grant-flow).\n2. Call Azure REST API using the access token to [list virtual machines in your specified resource group](https://learn.microsoft.com/en-us/rest/api/compute/virtual-machines/list).\n\n### How to run\n\n1. Create a service principal for this sample.\n\n    ```powershell\n    $params = @{\n        DisplayName = 'CppRest Azure REST API sample [SP]'\n        Note        = 'For Azure REST API sample using C++ REST SDK (cpprestsdk).'\n        Verbose     = $true\n    }\n    $sp = New-AzADServicePrincipal @params\n    $sp | Format-List @{ Name = 'SP App ID'; Expression = { $_.AppId }}, @{ Name = 'SP Secret'; Expression = { $_.PasswordCredentials.SecretText }}\n    ```\n\n2. Assign required roles such as **Reader** to the service principal on your Azure subscription.\n\n    ```powershell\n    $params = @{\n        Scope         = '/subscriptions/{0}' -f (Get-AzContext).Subscription.Id\n        ApplicationId = $sp.AppId\n        ObjectType    = 'ServicePrincipal'\n        Description   = 'For Azure REST API sample using C++ REST SDK (cpprestsdk).'\n    }\n    @(\n        'Reader'\n        # Appropriate roles depend on the Azure REST API that you want to call.\n    ) | ForEach-Object -Process { New-AzRoleAssignment @params -RoleDefinitionName $_ }\n    ```\n\n3. Run the following command in the **Developer PowerShell** to MSBuild will be able to find vcpkg if you have not run the following command before. See [Tutorial: Install and use packages with MSBuild in Visual Studio](https://learn.microsoft.com/en-us/vcpkg/get_started/get-started-msbuild?pivots=shell-powershell) for more details.\n\n    ```powershell\n    vcpkg integrate install\n    ```\n\n4. Open the **cpprest-azure-rest-api-sample** solution then set the **oauth2-client-creds-flow** project as startup project.\n\n5. Replace the placeholder text such as `TENANT_ID` to your configuration in the **main.cpp**.\n\n    ```cpp\n    // Config for Microsoft Entra ID\n    const utility::string_t tenantId = U(\"TENANT_ID\");                     // Tenant ID (GUID) or tenant domain\n    const utility::string_t clientId = U(\"SP_APP_ID\");                     // Application (client) ID\n    const utility::string_t clientSecret = U(\"SP_SECRET\");                 // Client secret\n\n    // Config for VM info.\n    const utility::string_t subscriptionId = U(\"SUBSCRIPTION_ID\");         // Azure subscription ID\n    const utility::string_t resourceGroupName = U(\"RESOURCE_GROUP_NAME\");  // Target resource group name\n    ```\n\n6. Run the sample from **Debug** - **Start Debugging (F5)**.\n\n\n## OAuth 2.0 device authorization grant flow sample\n\nThis sample do the following:\n\n1. Get an access token from Microsoft Entra ID with your service principal using the [OAuth 2.0 device authorization grant flow](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-device-code).\n2. Call Azure REST API using the access token to [list resource groups](https://learn.microsoft.com/en-us/rest/api/resources/resource-groups/list).\n\n### How to run\n\n1. Create a service principal for this sample.\n\n    ```powershell\n    $params = @{\n        DisplayName = 'CppRest Azure REST API sample [SP]'\n        Note        = 'For Azure REST API sample using C++ REST SDK (cpprestsdk).'\n        Verbose     = $true\n    }\n    $sp = New-AzADServicePrincipal @params\n    $sp | Format-List @{ Name = 'SP App ID'; Expression = { $_.AppId }}, @{ Name = 'SP Secret'; Expression = { $_.PasswordCredentials.SecretText }}\n    ```\n\n2. Add permission to the service principal for call Azure REST API.\n\n    ```powershell\n    $params = @{\n        ApplicationId = $sp.AppId\n        Type          = 'Scope'\n        ApiId         = '797f4846-ba00-4fd7-ba43-dac1f8f63013'  # Microsoft Azure Management\n        PermissionId  = '41094075-9dad-400e-a0bd-54e686782033'  # user_impersonation\n    }\n    Add-AzADAppPermission @params\n    ```\n\n3. Allow public client flows on the service principal. See [Desktop app that calls web APIs: App registration](https://learn.microsoft.com/en-us/entra/identity-platform/scenario-desktop-app-registration) and  [Public client and confidential client applications](https://learn.microsoft.com/en-us/entra/identity-platform/msal-client-applications) for details.\n\n    ```powershell\n    Update-AzADApplication -ApplicationId $sp.AppId -IsFallbackPublicClient\n    ```\n\n4. Assign required roles such as **Reader** to the service principal on your Azure subscription.\n\n    ```powershell\n    $params = @{\n        Scope         = '/subscriptions/{0}' -f (Get-AzContext).Subscription.Id\n        ApplicationId = $sp.AppId\n        ObjectType    = 'ServicePrincipal'\n        Description   = 'For Azure REST API sample using C++ REST SDK (cpprestsdk).'\n    }\n    @(\n        'Reader'\n        # Appropriate roles depend on the Azure REST API that you want to call.\n    ) | ForEach-Object -Process { New-AzRoleAssignment @params -RoleDefinitionName $_ }\n    ```\n\n5. Run the following command in the **Developer PowerShell for Visual Studio** to MSBuild will be able to find vcpkg if you have not run the following command before. See [Tutorial: Install and use packages with MSBuild in Visual Studio](https://learn.microsoft.com/en-us/vcpkg/get_started/get-started-msbuild?pivots=shell-powershell) for details.\n\n    ```powershell\n    vcpkg integrate install\n    ```\n\n6. Open the **cpprest-azure-rest-api-sample** solution then set the **oauth2-device-authz-grant-flow** project as startup project.\n\n7. This sample takes three command-line parameters. You need to set these parameters in the project properties if you want to run this sample within Visual Studio. You can set the command-line parameters from **Project** - **Properties** - **Debugging** - **Command Arguments** in Visual Studio.\n\n    ```\n    cpprestsample.exe \u003ctenant\u003e \u003cclient_id\u003e \u003csubscription_id\u003e\n    ```\n\n    Example of **Command Arguments**:\n\n    ```\n    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb cccccccc-cccc-cccc-cccc-cccccccccccc\n    ```\n\n8. Run the sample from **Debug** - **Start Debugging (F5)**.\n\n\n## Notes\n\n- The cpprestsdk is in maintenance mode.\n    - [C++ REST SDK](https://github.com/microsoft/cpprestsdk)\n        \u003e cpprestsdk is in maintenance mode and we do not recommend its use in new projects. We will continue to fix critical bugs and address security issues.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftksh164%2Fcpprest-azure-rest-api-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftksh164%2Fcpprest-azure-rest-api-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftksh164%2Fcpprest-azure-rest-api-sample/lists"}