Skip to content
Permalink
Browse files

Enable Azure creds passing from Actions

  • Loading branch information
Joonas Westlin
Joonas Westlin committed Dec 29, 2019
1 parent bb015d8 commit ae3414deccb7a6c7c54970a667ac6dc022fbd491
@@ -27,4 +27,4 @@ jobs:
Authentication__AuthorizationUrl: ${{ secrets.API_AUTHORIZATION_URL }}
Authentication__ClientId: ${{ secrets.API_CLIENT_ID }}
Authentication__ApplicationIdUri: ${{ secrets.API_APP_ID_URI }}
AzureServicesAuthConnectionString: ${{ format('RunAs=App;AppId={0};AppKey={1};TenantId={2}', secrets.AZURE_CREDENTIALS.clientId, secrets.AZURE_CREDENTIALS.clientSecret, secrets.AZURE_CREDENTIALS.tenantId) }}
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
@@ -2,6 +2,8 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;

@@ -31,12 +33,23 @@ public AppFixture()
string keyVaultUrl = config["IntegrationTest:KeyVaultUrl"];
if (!string.IsNullOrEmpty(keyVaultUrl))
{
// This will use Managed Identity / local user authentication
// For this to work in a CI pipeline,
// you will need to somehow pass in a client id + client secret
// and use a different overload that takes those.
// Locally doing this is better though.
configBuilder.AddAzureKeyVault(keyVaultUrl);
// CI / CD pipeline sets up a credentials environment variable to use
var credentialsJson = Environment.GetEnvironmentVariable("AZURE_CREDENTIALS");
// If it is not present, we are running locally
if (string.IsNullOrEmpty(credentialsJson))
{
// Use local user authentication
configBuilder.AddAzureKeyVault(keyVaultUrl);
}
else
{
// Use credentials in JSON object
var credentials = (JObject)JsonConvert.DeserializeObject(credentialsJson);
var clientId = credentials?.Value<string>("clientId");
var clientSecret = credentials?.Value<string>("clientSecret");
configBuilder.AddAzureKeyVault(keyVaultUrl, clientId, clientSecret);
}

config = configBuilder.Build();
}

@@ -5,7 +5,12 @@ VisualStudioVersion = 16.0.29418.71
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Joonasw.AadTestingDemo.API", "Joonasw.AadTestingDemo.API\Joonasw.AadTestingDemo.API.csproj", "{EBCAA1CF-FA4A-4A45-BC76-442DE618CC2E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Joonasw.AadTestingDemo.IntegrationTests", "Joonasw.AadTestingDemo.IntegrationTests\Joonasw.AadTestingDemo.IntegrationTests.csproj", "{798D0BFB-30ED-431F-BC6E-1913387D2E46}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Joonasw.AadTestingDemo.IntegrationTests", "Joonasw.AadTestingDemo.IntegrationTests\Joonasw.AadTestingDemo.IntegrationTests.csproj", "{798D0BFB-30ED-431F-BC6E-1913387D2E46}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9BA3751B-DE87-4C20-B3BF-A2259788F8AF}"
ProjectSection(SolutionItems) = preProject
.github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

0 comments on commit ae3414d

Please sign in to comment.
You can’t perform that action at this time.