Skip to content

Commit 0347730

Browse files
committed
Removed ProcessUserGroupsForOverage From Readme
1 parent 7b3ecd8 commit 0347730

File tree

2 files changed

+0
-138
lines changed

2 files changed

+0
-138
lines changed

5-WebApp-AuthZ/5-2-Groups/README-incremental-instructions.md

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -305,75 +305,6 @@ The following files have the code that would be of interest to you:
305305
}
306306
```
307307

308-
**ProcessClaimsForGroupsOverage** method uses `GraphServiceClient` to retrieve groups for the signed-in user from [/me/memberOf](https://docs.microsoft.com/graph/api/user-list-memberof) endpoint. All the group ids are stored in Session.
309-
310-
```csharp
311-
private static async Task<List<string>> ProcessUserGroupsForOverage(TokenValidatedContext context)
312-
{
313-
List<string> groupClaims = new List<string>();
314-
...
315-
var graphClient = context.HttpContext.RequestServices.GetService<GraphServiceClient>();
316-
if (graphClient == null)
317-
{
318-
Console.WriteLine("No service for type 'Microsoft.Graph.GraphServiceClient' has been registered in the Startup.");
319-
}
320-
else if (context.SecurityToken != null)
321-
{
322-
if (!context.HttpContext.Items.ContainsKey("JwtSecurityTokenUsedToCallWebAPI"))
323-
{
324-
context.HttpContext.Items.Add("JwtSecurityTokenUsedToCallWebAPI", context.SecurityToken as JwtSecurityToken);
325-
}
326-
string select = "id,displayName,onPremisesNetBiosName,onPremisesDomainName,onPremisesSamAccountNameonPremisesSecurityIdentifier";
327-
328-
IUserMemberOfCollectionWithReferencesPage memberPage = new UserMemberOfCollectionWithReferencesPage();
329-
try
330-
{
331-
memberPage = await graphClient.Me.MemberOf.Request().Select(select).GetAsync().ConfigureAwait(false);
332-
}
333-
catch (Exception graphEx)
334-
{
335-
var exMsg = graphEx.InnerException != null ? graphEx.InnerException.Message : graphEx.Message;
336-
Console.WriteLine("Call to Microsoft Graph failed: " + exMsg);
337-
}
338-
if (memberPage?.Count > 0)
339-
{
340-
var allgroups = ProcessIGraphServiceMemberOfCollectionPage(memberPage);
341-
if (allgroups?.Count > 0)
342-
{
343-
var identity = (ClaimsIdentity)context.Principal.Identity;
344-
345-
if (identity != null)
346-
{
347-
if (!IsAccessToken(identity))
348-
{
349-
foreach (Group group in allgroups)
350-
{
351-
groupClaims.Add(group.Id);
352-
}
353-
context.HttpContext.Session.SetAsByteArray("groupClaims", groupClaims);
354-
}
355-
}
356-
}
357-
}
358-
}
359-
}
360-
...
361-
return groupClaims;
362-
}
363-
```
364-
365-
In the app registration, you might want to add other attributes than id to the `groups` claim; For instance if, the required format is `NetBIOSDomain\sAMAccountName` then replace
366-
367-
```csharp
368-
groupClaims.Add(new Claim("groups", group.Id));
369-
```
370-
371-
with
372-
373-
```csharp
374-
groupClaims.Add(group.OnPremisesNetBiosName+"\\"+group.OnPremisesSamAccountName));
375-
```
376-
377308
GraphHelper.cs contains a method **CheckUsersGroupMembership** that is called in `CustomAuthorization.cs` to check if value of GroupName parameter exists in either Session for Overage scenario or in User claims otherwise.
378309

379310
```csharp

5-WebApp-AuthZ/5-2-Groups/README.md

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -423,75 +423,6 @@ The following files have the code that would be of interest to you:
423423
}
424424
```
425425

426-
**ProcessClaimsForGroupsOverage** method uses `GraphServiceClient` to retrieve groups for the signed-in user from [/me/memberOf](https://docs.microsoft.com/graph/api/user-list-memberof) endpoint. All the group ids are stored in Session.
427-
428-
```csharp
429-
private static async Task<List<string>> ProcessUserGroupsForOverage(TokenValidatedContext context)
430-
{
431-
List<string> groupClaims = new List<string>();
432-
...
433-
var graphClient = context.HttpContext.RequestServices.GetService<GraphServiceClient>();
434-
if (graphClient == null)
435-
{
436-
Console.WriteLine("No service for type 'Microsoft.Graph.GraphServiceClient' has been registered in the Startup.");
437-
}
438-
else if (context.SecurityToken != null)
439-
{
440-
if (!context.HttpContext.Items.ContainsKey("JwtSecurityTokenUsedToCallWebAPI"))
441-
{
442-
context.HttpContext.Items.Add("JwtSecurityTokenUsedToCallWebAPI", context.SecurityToken as JwtSecurityToken);
443-
}
444-
string select = "id,displayName,onPremisesNetBiosName,onPremisesDomainName,onPremisesSamAccountNameonPremisesSecurityIdentifier";
445-
446-
IUserMemberOfCollectionWithReferencesPage memberPage = new UserMemberOfCollectionWithReferencesPage();
447-
try
448-
{
449-
memberPage = await graphClient.Me.MemberOf.Request().Select(select).GetAsync().ConfigureAwait(false);
450-
}
451-
catch (Exception graphEx)
452-
{
453-
var exMsg = graphEx.InnerException != null ? graphEx.InnerException.Message : graphEx.Message;
454-
Console.WriteLine("Call to Microsoft Graph failed: " + exMsg);
455-
}
456-
if (memberPage?.Count > 0)
457-
{
458-
var allgroups = ProcessIGraphServiceMemberOfCollectionPage(memberPage);
459-
if (allgroups?.Count > 0)
460-
{
461-
var identity = (ClaimsIdentity)context.Principal.Identity;
462-
463-
if (identity != null)
464-
{
465-
if (!IsAccessToken(identity))
466-
{
467-
foreach (Group group in allgroups)
468-
{
469-
groupClaims.Add(group.Id);
470-
}
471-
context.HttpContext.Session.SetAsByteArray("groupClaims", groupClaims);
472-
}
473-
}
474-
}
475-
}
476-
}
477-
}
478-
...
479-
return groupClaims;
480-
}
481-
```
482-
483-
In the app registration, you might want to add other attributes than id to the `groups` claim; For instance if, the required format is `NetBIOSDomain\sAMAccountName` then replace
484-
485-
```csharp
486-
groupClaims.Add(new Claim("groups", group.Id));
487-
```
488-
489-
with
490-
491-
```csharp
492-
groupClaims.Add(group.OnPremisesNetBiosName+"\\"+group.OnPremisesSamAccountName));
493-
```
494-
495426
GraphHelper.cs contains a method **CheckUsersGroupMembership** that is called in `CustomAuthorization.cs` to check if value of GroupName parameter exists in either Session for Overage scenario or in User claims otherwise.
496427

497428
```csharp

0 commit comments

Comments
 (0)