{"id":18149283,"url":"https://github.com/jongio/azidext","last_synced_at":"2025-04-24T04:45:50.582Z","repository":{"id":39575644,"uuid":"233182626","full_name":"jongio/azidext","owner":"jongio","description":"Extensions to the Azure.Identity libraries","archived":false,"fork":false,"pushed_at":"2023-06-15T15:18:16.000Z","size":89,"stargazers_count":28,"open_issues_count":5,"forks_count":15,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-24T04:45:43.340Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/jongio.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,"publiccode":null,"codemeta":null}},"created_at":"2020-01-11T05:41:44.000Z","updated_at":"2025-04-14T04:25:59.000Z","dependencies_parsed_at":"2024-06-18T15:27:21.090Z","dependency_job_id":"ac268cf3-72df-4d0f-a648-c39b3ee9b035","html_url":"https://github.com/jongio/azidext","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongio%2Fazidext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongio%2Fazidext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongio%2Fazidext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongio%2Fazidext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jongio","download_url":"https://codeload.github.com/jongio/azidext/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250566442,"owners_count":21451229,"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":[],"created_at":"2024-11-01T23:12:32.848Z","updated_at":"2025-04-24T04:45:50.563Z","avatar_url":"https://github.com/jongio.png","language":"C#","funding_links":[],"categories":["others"],"sub_categories":[],"readme":"# Azure Identity Extensions\n\nThis repo is a place for us to share ideas and extensions to the Azure Identity libraries.\n\n\u003e **DISCLAIMER**: The code in this repo is not officially supported or intended for production use. The intention of this repo it to unblock customers who would like to use the Azure.Identity capabilities in the Fluent, Resource Management, and Service Bus SDKs before they have been migrated to the new SDK Azure.Core and officially support TokenCredential. We have included minimal tests in this repo, so please take it upon yourself to fully test this code to ensure it works in your environment.\n\n## Languages\n\nWe currently have included examples for [.NET](#.NET), [Java](#Java), [JavaScript/TypeScript](#TypeScript), [Golang](#Golang), and [Python](#Python). Please file an issue if you would like examples for other languages as well.\n\n## Usage\n\nThe classes contained in this repo are only meant to be a temporary stopgap between now and when the Resource Management, Fluent, and Service Bus SDKs support Azure.Core.  Since those efforts are currently underway, we think it would be best for you to copy the classes in this project to your class instead of releasing them via a package manager.\n\n1. Clone the repo `git clone https://github.com/jongio/azidext`\n1. Either reference the project or copy the classes you need into your solution.\n\n## .NET\n\n### AzureIdentityCredentialAdapter.cs\n\nThe `AzureIdentityCredentialAdapter` class allows you to use all the goodness of `Azure.Identity.DefaultAzureCredential` in the Azure Management libraries. You can use it in place of `ServiceClientCredential` when calling your Azure Management APIs. The Azure Management libraries will be updated to support Azure Identity and Azure Core in early 2020, so this should just be used a a stopgap between now and then.\n\n```cmd\ndotnet add package Microsoft.Azure.Management.ApplicationInsights --version 0.2.0-preview\n```\n\nUse `AzureIdentityCredentialAdapter` in place of `ServiceClientCredential`:\n\n```csharp\nusing Azure.Identity.Extensions;\nusing Microsoft.Azure.Management.ApplicationInsights.Management;\n\nvar appInsightsClient = new ApplicationInsightsManagementClient(new AzureIdentityCredentialAdapter());\n```\n\n### AzureIdentityFluentCredentialAdapter.cs\n\nThe `AzureIdentityFluentCredentialAdapter` class allows you to use all the goodness of `Azure.Identity.DefaultAzureCredential` in the [Azure Management **Fluent** libraries](https://github.com/Azure/azure-libraries-for-net). You can use it in place of `AzureCredentials` when calling your Azure Management Fluent APIs.\n\n```cmd\ndotnet add package Microsoft.Azure.Management.Fluent --version 1.30.0\n```\n\nUse `AzureIdentityFluentCredentialAdapter` in place of `AzureCredentials`:\n\n```csharp\nusing Azure.Identity.Extensions;\nusing Microsoft.Azure.Management.ResourceManager.Fluent;\n\nvar creds = new AzureIdentityFluentCredentialAdapter(tenantId, AzureEnvironment.AzureGlobalCloud);\n\nvar resourceGroup = Azure.Authenticate(creds)\n                        .WithSubscription(subId)\n                        .ResourceGroups\n                        .Define(name)\n                        .WithRegion(region)\n                        .Create();\n```\n\n### AzureIdentityServiceBusCredentialAdapter.cs\n\nThe `AzureIdentityServiceBusCredentialAdapter` class allows you to use all of the goodness of `DefaultAzureCredential` from [azure-identity](https://mvnrepository.com/artifact/com.azure/azure-identity) with the Service Bus SDKs.  Service Bus will officially be supported by the new SDKs soon, this is a stopgap that enables you to use the same credential flow throughout your application.\n\n```cmd\ndotnet add package Microsoft.Azure.ServiceBus --version 4.1.1\n```\n\n```csharp\nusing Azure.Identity.Extensions;\nusing Microsoft.Azure.ServiceBus;\n\nvar client = new TopicClient(\"sbendpoint\", \"entitypath\", new AzureIdentityServiceBusCredentialAdapter());\n```\n\n## Testing .NET\n\n1. Setup test resources with \"Test Setup\" section below.\n2. Open the .Tests project and run dotnet build.\n\n## Java\n\n### AzureIdentityCredentialAdapter.java\n\nThe `AzureIdentityCredentialAdapter` class provides a simple bridge to use `DefaultAzureCredential` from `com.azure` namespace in `com.microsoft.azure` SDKs. This is a convenient mechanism to authenticate all fluent Azure Management Resources and a some data plane SDKs that use `ServiceClientCredential` family of credentials.\n\nTo use this type, just copy `AzureIdentityCredentialAdapter.java` file located in `java/src/main/java/com/azure/identity/extensions` directory into your application and make necessary package name updates.\n\nAfter you have created this type, you can reference it in your code as shown below:\n\n```java\nAzure azure = Azure.authenticate(new AzureIdentityCredentialAdapter(tenantId)).withDefaultSubscription();\n```\n\nAbove code will provide an instance of `Azure` fluent type from which you can access all Azure Resource Managers.\n\n### AzureIdentityServiceBusCredential.java\n\nThe `AzureIdentityServiceBusCredential` class allows you to use all of the goodness of `DefaultAzureCredential` from [azure-identity](https://mvnrepository.com/artifact/com.azure/azure-identity) with the Service Bus SDKs.  Service Bus will officially be supported by the new SDKs soon, this is a stopgap that enables you to use the same credential flow throughout your application.\n\nTo use this type, just copy `AzureIdentityServiceBusCredential.java` file located in `java/src/main/java/com/azure/identity/extensions` directory into your application and make necessary package name updates.\n\nSample code to create a new topic client:\n\n```java\nClientSettings clientSettings = new ClientSettings(new AzureIdentityServiceBusCredential());\nTopicClient topicClient = new TopicClient(\"servicebus-endpoint\", \"servicebus-entitypath\", clientSettings);\n```\n\n#### Testing AzureIdentityCredentialAdapter\n\nThis repository has a test class called `AzureIdentityCredentialAdapterTest` that tests creation of a storage account, listing all storage accounts in a resource group to validate successful creation, then deleting the account created earlier in this test and listing again to ensure successful deletion.\n\nTo run `AzureIdentityCredentialAdapterTest`, ensure you have `.env` file created and accessible from your classpath. Your `.env` file should have the following properties set:\n\n- AZURE_TENANT_ID\n- AZURE_STORAGE_ACCOUNT_NAME\n- AZURE_RESOURCE_GROUP\n\nOnce you have the `.env` file configured, run the test using JUnit 5 runner.\n\n## TypeScript\n\n### AzureIdentityCredentialAdapter\n\nThe `AzureIdentityCredentialAdapter` class provides a simple adapter to use TokenCredential from [@azure/identity](https://www.npmjs.com/package/@azure/identity) with any SDK\nthat accepts ServiceClientCredentials from packages like `@azure/arm-*` or `@azure/ms-rest-*`. \n\nTo use this type, just copy `azureIdentityCredentialAdapter.ts`, `package.json`, and `tsconfig.json` file located in `js` directory into your application and install packages in `package.json`.\n\nAfter you have created this type, you can reference it in your code as shown below:\n\n```TypeScript\n# Example for azure-mgmt-resource client\nconst cred = new AzureIdentityCredentialAdapter();\nconst client = new ResourceManagementClient(cred, subscriptionId);\n```\n\nThe above code will instantiate an Azure.Identity compatible TokenCredential object based on DefaultAzureCredential and pass that to the ResourceManagementClient instance.\n\n#### Testing AzureIdentityCredentialAdapter\n\nThis repository has a test that creates a resource group in a given subscription.\n\nTo run this test, ensure you have `.env` file created and accessible from the root of your repo. Your `.env` file should have the following properties set:\n\n- AZURE_SUBSCRIPTION_ID\n- AZURE_TENANT_ID\n- AZURE_CLIENT_ID\n- AZURE_CLIENT_SECRET\n\nInstall the test dependencies using npm under the path of `package.json`.\n\n```\nnpm i\n```\nThen install mocha.\n\n```\nnpm i -g mocha\n```\ncompile ts to js using tsc. \n\n```\ntsc azureIdentityCredentialAdapter.spec.ts --esModuleInterop\n```\n\nOnce you have the `.env` file configured and js compiled, run the test simply calling `mocha azureIdentityCredentialAdapter.spec.js --timeout 10000`.\n\n## Golang\n\n### NewAzureIdentityCredentialAdapter\n\nThe `NewAzureIdentityCredentialAdapter` function allows you to use all the goodness of `azidentity` in the Azure Management libraries. You can use it in place of `Authorizer` when calling your Azure Management APIs.\n\nTo use this type, just import package github.com/jongio/azidext/go/azidext and using follow command to get package.\n\n```\ngo get -u github.com/jongio/azidext/go/azidext\n```\n\nUse `NewAzureIdentityCredentialAdapter` in place of `Authorizer`:\n\n```go\nimport \"github.com/jongio/azidext/go/azidext\"\n\ngroupsClient := resources.NewGroupsClient(subscriptionID)\n\ta, err := NewDefaultAzureCredentialAdapter(nil)\n\tif err != nil {\n\t}\n\tgroupsClient.Authorizer = a\n```\n\n#### Testing NewAzureIdentityCredentialAdapter\n\nThis repository has a test that creates a resource group in a given subscription.\n\nTo run this test, ensure you have `.env` file created and accessible from the root of your repo. Your `.env` file should have the following properties set:\n\n- AZURE_SUBSCRIPTION_ID\n- AZURE_TENANT_ID\n- AZURE_CLIENT_ID\n- AZURE_CLIENT_SECRET\n\nOnce you have the `.env` file configured, run the test simply calling `go test`.\n\n## Python\n\n### AzureIdentityCredentialAdapter\n\nThe `AzureIdentityCredentialAdapter` class provides a simple adapter to use any credential from [azure-identity](https://pypi.org/project/azure-identity/) with any SDK\nthat accepts credentials from `azure.common.credentials` or `msrestazure.azure_active_directory`.\n\nTo use this type, just copy the `azure_identity_credential_adapter.py` file located in the `python` directory into your application and make necessary package name updates.\n\nAfter you have created this type, you can reference it in your code as shown below:\n\n```python\n# Example for azure-mgmt-resource client\nfrom azure_identity_credential_adapter import AzureIdentityCredentialAdapter\ncredentials = AzureIdentityCredentialAdapter()\n\nfrom azure.mgmt.resource import ResourceManagementClient\nclient = ResourceManagementClient(credentials, subscription_id)\n```\n\nThe above code will provide an instance of `ResourceManagementClient` from which you can access ARM resources. You can use any type of client, like `ComputeManagementClient`, etc.\n\n#### Testing AzureIdentityCredentialAdapter\n\nThis repository has a test that list the resource groups in a given subscription.\n\nTo run this test, ensure you have `.env` file created and accessible from the root of your repo. Your `.env` file should have the following properties set:\n\n- AZURE_SUBSCRIPTION_ID\n- AZURE_TENANT_ID\n- AZURE_CLIENT_ID\n- AZURE_CLIENT_SECRET\n\nGeneral recommendation for Python development is to use a Virtual Environment. For more information, see https://docs.python.org/3/tutorial/venv.html\n\nInstall and initialize the virtual environment with the \"venv\" module on Python 3 (you must install [virtualenv](https://pypi.python.org/pypi/virtualenv) for Python 2.7):\n\n```\npython -m venv venv # Might be \"python3\" or \"py -3.6\" depending on your Python installation\nsource venv/bin/activate      # Linux shell (Bash, ZSH, etc.) only\n./venv/scripts/activate       # PowerShell only\n./venv/scripts/activate.bat   # Windows CMD only\n```\n\nInstall the test dependencies using pip\n\n```\npip install -r python\\dev_requirements.txt\n```\n\nOnce you have the `.env` file configured and the venv loaded, run the tests simply calling `pytest`\n\n\nMore to come soon.  Please file a GitHub issue with any questions/suggestions.\n\n\n## Test Setup\n\n1. Create a service principal with `az ad sp create-for-rbac`\n2. Rename .env.tmp to .env and update the the following values from the SP\n\n    `AZURE_CLIENT_ID=appId`\n\n    `AZURE_CLIENT_SECRET=password`\n\n    `AZURE_TENANT_ID=tenantId`\n\n3. Run `az account show` to get your subscription id and update the .env file with that.\n\n    `AZURE_SUBSCRIPTION_ID=`\n\n4. Deploy the Service Bus resources with terraform files in iac/terraform\n\n    - Open variables.tf and change the basename value to something unique.\n    - Run the following commands:\n        - `terraform init`\n        - `terraform plan --out tf.plan`\n        - `terraform apply tf.plan`\n\n5. Update AZURE_BASE_NAME in .env file to the base name you used for terraform deployment\n\n    - AZURE_BASE_NAME=azidexttest1\n\n\n6. See each language \"Test\" section above for instructions on how to run the tests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjongio%2Fazidext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjongio%2Fazidext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjongio%2Fazidext/lists"}