Hello @chamith rasintha , Thanks for the question and using MS Q&A platform.
To create a Xero linked service in Azure Data Factory with OAuth 2.0 authentication using Azure Fluent library, you can follow these steps:
- Add the necessary dependencies to your project. You will need the following NuGet packages:
- Microsoft.Azure.Management.DataFactory.Fluent
- Microsoft.Azure.Management.ResourceManager.Fluent
- Microsoft.IdentityModel.Clients.ActiveDirectory
- Create an instance of the
Azure
class and authenticate to your Azure account using your credentials.
var credentials = SdkContext.AzureCredentialsFactory
.FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);
var azure = Azure.Authenticate(credentials).WithDefaultSubscription();
Create a new Xero linked service using the DefineLinkedService()
method of the DataFactory
class. Set the AuthenticationType
to OAuth2
.
var linkedService = azure.DataFactories
.DefineLinkedService("xeroLinkedService")
.WithType("Xero")
.WithDescription("Xero linked service")
.WithJsonDefinition(@"{
""type"": ""Xero"",
""typeProperties"": {
""authenticationType"": ""OAuth2"",
""clientId"": ""<your-client-id>"",
""clientSecret"": {
""type"": ""SecureString"",
""value"": ""<your-client-secret>""
},
""authorizationEndpoint"": ""https://login.xero.com/identity/connect/authorize"",
""tokenEndpoint"": ""https://identity.xero.com/connect/token"",
""resource"": ""https://api.xero.com"",
""redirectUri"": ""urn:ietf:wg:oauth:2.0:oob:auto"",
""scope"": ""openid profile email accounting.contacts accounting.settings accounting.transactions offline_access""
}
}")
.Create();
Note: Replace <your-client-id>
and <your-client-secret>
with your Xero OAuth 2.0 client ID and secret.
Use the Create()
method to create the linked service in Azure Data Factory.
linkedService.Create();
That's it! You have now created a Xero linked service in Azure Data Factory with OAuth 2.0 authentication using Azure Fluent library.
Thanks
Himanshu
Please accept as "Yes" if the answer provided is useful , so that you can help others in the community looking for remediation for similar issues.