Azure data factroy REST API invocation. RRS feed

  • Question

  • I am invoking rest API for azure data factory and using below script for OAuth token generation required for REST API. However I want to automate this process by invoking powershell in .NET code and calling REST API from .NET. But below script requires manual intervention of login to  with azure credentials . Is there any way automate this login.

    In powershell command window if once I have logged in with Login-AzureRmAccount .Then it does not ask for credentials. is there any way I can pass the azure credentials in the powershell script.

    # Load ADAL Assemblies 

    $adal = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll" 

    $adalforms = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll" 

    # Set Azure AD Tenant name 
    $adTenant = "CitiusTech.onmicrosoft.com"  

    # Set well-known client ID for AzurePowerShell 
    $clientId = "clientID"  
    # Set redirect URI for Azure PowerShell 
    $redirectUri = "urn:ietf:wg:oauth:2.0:oob" 
    # Set Resource URI to Azure Service Management API 
    $resourceAppIdURI = "https://management.core.windows.net/" 
    # Set Authority to Azure AD Tenant 
    $authority = "https://login.windows.net/$adTenantId" 
    # Create Authentication Context tied to Azure AD Tenant 
    $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority 
    # Acquire token ,
    $authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri,"auto") 
    $authHeader = $authResult.CreateAuthorizationHeader() 
    $authHeader | Out-File E:/jwt.txt

    Monday, August 8, 2016 2:05 PM