Skip to content

Commit 2e3800e

Browse files
committed
review changes
1 parent 29bd59b commit 2e3800e

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

2-WebApp-graph-user/2-6-BFF-Proxy/CallGraphBFF/ClientApp/src/components/FetchGraph.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ export class FetchGraph extends Component {
3737
getGraphProfile = async () => {
3838
try {
3939
const response = await fetch('api/profile');
40+
4041
if (response.ok) {
4142
const data = await response.json();
4243
this.setState({ profile: data, loading: false });
44+
} else if (response.status === 401) {
45+
this.props.login();
4346
}
4447
} catch (error) {
4548
console.log(error);

2-WebApp-graph-user/2-6-BFF-Proxy/CallGraphBFF/Controllers/AuthController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public async Task<ActionResult> Logout()
3838
[HttpGet("account")]
3939
public ActionResult GetAccount()
4040
{
41-
if (User.Identity.IsAuthenticated)
41+
if (User.Identity != null && User.Identity.IsAuthenticated)
4242
{
4343
var claims = ((ClaimsIdentity)this.User.Identity).Claims
4444
.Select(c => new { type = c.Type, value = c.Value })

2-WebApp-graph-user/2-6-BFF-Proxy/CallGraphBFF/Controllers/ProfileController.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
using Microsoft.AspNetCore.Mvc;
22
using Microsoft.AspNetCore.Authorization;
33
using Microsoft.AspNetCore.Authentication.Cookies;
4-
using Microsoft.Identity.Client;
54
using Microsoft.Identity.Web;
65
using Microsoft.Graph;
76

87
namespace TodoListBFF.Controllers;
98

109
[Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)]
11-
[AuthorizeForScopes(Scopes = new string[] { "user.read" })]
1210
[Route("api/[controller]")]
1311
[ApiController]
1412
public class ProfileController : Controller
@@ -32,13 +30,13 @@ public async Task<ActionResult<User>> GetProfile()
3230

3331
return Ok(profile);
3432
}
35-
catch (ServiceException svcex) when (svcex.Message.Contains("Continuous access evaluation"))
33+
catch (ServiceException svcex) when (svcex.InnerException != null && svcex.InnerException.Message.Contains("MsalUiRequiredException"))
3634
{
37-
return Unauthorized("Continuous access evaluation challenge occurred\n" + svcex.Message);
35+
return Unauthorized("MsalUiRequiredException occurred. Please sign-in again.\n" + svcex.Message);
3836
}
39-
catch (MsalUiRequiredException ex)
37+
catch (ServiceException svcex) when (svcex.Message.Contains("Continuous access evaluation"))
4038
{
41-
return Unauthorized("MsalUiRequiredException occurred while calling the downstream API\n" + ex.Message);
39+
return Unauthorized("Continuous access evaluation challenge occurred. Please sign-in again.\n" + svcex.Message);
4240
}
4341
catch (Exception ex)
4442
{

2-WebApp-graph-user/2-6-BFF-Proxy/CallGraphBFF/Program.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@
2424
options.Cookie.IsEssential = true;
2525

2626
options.Events = new RejectSessionCookieWhenAccountNotInCacheEvents();
27-
28-
//options.Events.OnRedirectToLogin = context =>
29-
//{
30-
// context.Response.StatusCode = 401;
31-
// return Task.CompletedTask;
32-
//};
33-
34-
//options.Events.OnRedirectToAccessDenied = context =>
35-
//{
36-
// context.Response.StatusCode = 401;
37-
// return Task.CompletedTask;
38-
//};
3927
});
4028

4129
builder.Services.AddControllersWithViews()

2-WebApp-graph-user/2-6-BFF-Proxy/README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,19 @@ or download and extract the repository *.zip* file.
7171
### Step 2: Navigate to project folder
7272

7373
```console
74-
cd 2-WebApp-graph-user/2-6-BFF-Proxy
74+
cd 2-WebApp-graph-user/2-6-BFF-Proxy/CallGraphBFF
7575
```
7676

77-
### Step 3: Register the sample application(s) in your tenant
77+
### Step 3. Trust development certificates
78+
79+
```console
80+
dotnet dev-certs https --clean
81+
dotnet dev-certs https --trust
82+
```
83+
84+
For more information and potential issues, see: [HTTPS in .NET Core](https://docs.microsoft.com/aspnet/core/security/enforcing-ssl).
85+
86+
### Step 4: Register the sample application(s) in your tenant
7887

7988
There is one project in this sample. To register it, you can:
8089

@@ -166,12 +175,12 @@ Open the project in your IDE (like Visual Studio or Visual Studio Code) to confi
166175
1. Find the key `ClientId` and replace the existing value with the application ID (clientId) of `CallGraphBFF` app copied from the Azure portal.
167176
1. Find the key `ClientSecret` and replace the existing value with the generated secret that you saved during the creation of `CallGraphBFF` copied from the Azure portal.
168177

169-
### Step 4: Running the sample
178+
### Step 5: Running the sample
170179

171180
From your shell or command line, execute the following commands:
172181

173182
```console
174-
cd 2-WebApp-graph-user/2-6-BFF-Proxy
183+
cd 2-WebApp-graph-user/2-6-BFF-Proxy/CallGraphBFF
175184
dotnet run
176185
```
177186

0 commit comments

Comments
 (0)