Skip to content

Commit 9d75f26

Browse files
authored
Update SWA settings (#3)
1 parent 2075bdd commit 9d75f26

File tree

7 files changed

+31
-18
lines changed

7 files changed

+31
-18
lines changed

.github/workflows/azure-dev.yml

+2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ jobs:
5656
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
5757

5858
- name: Provision Infrastructure
59+
if: ${{ env.AZURE_ENV_NAME != '' }}
5960
run: azd provision --no-prompt
6061
env:
6162
AZD_INITIAL_ENVIRONMENT_CONFIG: ${{ secrets.AZD_INITIAL_ENVIRONMENT_CONFIG }}
6263

6364
- name: Deploy Application
65+
if: ${{ env.AZURE_ENV_NAME != '' }}
6466
run: azd deploy --no-prompt

src/EasyAuth.ContainerApp/Services/RequestService.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,22 @@ public async Task<string> GetPayload()
4949

5050
public async Task<string> GetAuthMe()
5151
{
52+
var context = accessor.HttpContext;
53+
var request = context!.Request;
54+
var headers = request.Headers;
5255
var authMe = default(string);
5356
try
5457
{
55-
authMe = await http.GetStringAsync("/.auth/me");
58+
http.DefaultRequestHeaders.Clear();
59+
foreach (var header in headers)
60+
{
61+
http.DefaultRequestHeaders.Add(header.Key, header.Value.ToArray());
62+
}
63+
authMe = JsonSerializer.Serialize(await http.GetFromJsonAsync<object>("/.auth/me"), options);
5664
}
57-
catch
65+
catch (Exception ex)
5866
{
59-
authMe = "Not authenticated";
67+
authMe = ex.Message;
6068
}
6169

6270
return authMe;

src/EasyAuth.FunctionApp/EasyAuth.FunctionApp.csproj

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<!-- <TargetFrameworks>net8.0;net9.0</TargetFrameworks> -->
4-
<!-- <TargetFramework>net9.0</TargetFramework> -->
5-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net9.0</TargetFramework>
64
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
75
<OutputType>Exe</OutputType>
86
<ImplicitUsings>enable</ImplicitUsings>

src/EasyAuth.SwaApp/Properties/launchSettings.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dotnetRunMessages": true,
77
"launchBrowser": true,
88
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
9-
"applicationUrl": "http://localhost:5000",
9+
"applicationUrl": "http://localhost:8080",
1010
"environmentVariables": {
1111
"ASPNETCORE_ENVIRONMENT": "Development"
1212
}
@@ -16,7 +16,7 @@
1616
"dotnetRunMessages": true,
1717
"launchBrowser": true,
1818
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
19-
"applicationUrl": "https://localhost:5050;http://localhost:5000",
19+
"applicationUrl": "https://localhost:8081;http://localhost:8080",
2020
"environmentVariables": {
2121
"ASPNETCORE_ENVIRONMENT": "Development"
2222
}

src/EasyAuth.SwaApp/staticwebapp.config.json

-5
This file was deleted.

src/EasyAuth.WebApp/Services/RequestService.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,22 @@ public async Task<string> GetPayload()
4949

5050
public async Task<string> GetAuthMe()
5151
{
52+
var context = accessor.HttpContext;
53+
var request = context!.Request;
54+
var headers = request.Headers;
5255
var authMe = default(string);
5356
try
5457
{
55-
authMe = await http.GetStringAsync("/.auth/me");
58+
http.DefaultRequestHeaders.Clear();
59+
foreach (var header in headers)
60+
{
61+
http.DefaultRequestHeaders.Add(header.Key, header.Value.ToArray());
62+
}
63+
authMe = JsonSerializer.Serialize(await http.GetFromJsonAsync<object>("/.auth/me"), options);
5664
}
57-
catch
65+
catch (Exception ex)
5866
{
59-
authMe = "Not authenticated";
67+
authMe = ex.Message;
6068
}
6169

6270
return authMe;

swa-cli.config.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
"configurations": {
44
"azure-easyauth-sample": {
55
"appLocation": "src/EasyAuth.SwaApp",
6-
"apiLocation": "src/EasyAuth.FunctionApp/bin/Release/net8.0/publish",
6+
"apiLocation": "src/EasyAuth.FunctionApp/bin/Release/net9.0",
77
"outputLocation": "bin/wwwroot",
8+
"apiLanguage": "dotnetisolated",
9+
"apiVersion": "9.0",
810
"appBuildCommand": "dotnet publish -c Release -o bin",
911
"apiBuildCommand": "dotnet publish -c Release",
1012
"run": "dotnet watch run",
11-
"appDevserverUrl": "http://localhost:5000"
13+
"appDevserverUrl": "http://localhost:8080"
1214
}
1315
}
1416
}

0 commit comments

Comments
 (0)