Skip to content

403 errors when authenticating with service principle with Azure Functions #74

@moizhraj

Description

@moizhraj

Hi Team, I have a sample functions app (dotnet-isolated) and I am using an app (client id, client secret) to authenticate to a twin instance. When I run my function locally it works just fine but once deployed it just fails with a 403 error. I have verified that my client has the required access control as per this doc.

here is the sample code I use for authentication

string adtInstanceUrl = Environment.GetEnvironmentVariable("clientConfig:digitalTwins:instanceUrl");
string tenantId = Environment.GetEnvironmentVariable("clientConfig:servicePrinciple:tenantId");
string clientId = Environment.GetEnvironmentVariable("clientConfig.servicePrinciple.clientId");
string clientSecret = Environment.GetEnvironmentVariable("clientConfig:servicePrinciple:clientSecret");

Environment.SetEnvironmentVariable("AZURE_CLIENT_SECRET", clientSecret);
Environment.SetEnvironmentVariable("AZURE_CLIENT_ID", clientId);
Environment.SetEnvironmentVariable("AZURE_TENANT_ID", tenantId);

TokenCredential tokenCredential = new DefaultAzureCredential();

var client = new DigitalTwinsClient(new Uri(adtInstanceUrl),
                tokenCredential);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions