-
Notifications
You must be signed in to change notification settings - Fork 1k
Enhancing multi tenant sample #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
0b36d99
Onboarding process for multi-tenant
e065eea
Create List and Delete TodoItem
c334116
Edit TodoItem
1b4959a
Refactor and new readme
bc0612c
Readme changes
48cb05a
app creation ps1
e93616b
missing commit
db56d5a
Merge branch 'master' into tibre/multiTenantSample
2a8b724
Readme enhancements
0f791af
Comments to run it inmemory
385d671
Moving sample to another folder
9a13b34
Rollback previous sample as is
ffb4b67
Renaming folder
4504f35
License
91d8ccb
update git ignore
3f3c202
Removing files that should have been ignored
3d07a5f
Replacing old Readme
c471ba2
missing commit file
764e654
AppCreationScripts update
ca3aa52
Update readme
407f48d
Minor fixes
331d482
Fix missing reply url
dde2533
MIT license
535087d
Changed user-flow so the home page allows anonymous access.
8ccb827
Minor UI changes
b768dd5
README improvement
2074945
Switched to User.Read.All so only admin can consent
6d3510c
review in progress
1663817
new sign-in diagram
22e8928
diagram update
305659b
diagram update
7511453
Adding code comments
436192c
review complete
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
using Microsoft.Graph; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace WebApp_OpenIDConnect_DotNet.BLL | ||
{ | ||
public interface IMSGraphService | ||
{ | ||
Task<IEnumerable<User>> GetUsersAsync(string accessToken); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
using WebApp_OpenIDConnect_DotNet.Models; | ||
|
||
namespace WebApp_OpenIDConnect_DotNet.BLL | ||
{ | ||
public interface ITodoItemService | ||
{ | ||
Task<TodoItem> Create(string text, ClaimsPrincipal user); | ||
Task<IEnumerable<TodoItem>> List(bool showAll, ClaimsPrincipal user); | ||
Task<TodoItem> Get(int id, ClaimsPrincipal user); | ||
Task Delete(int id, ClaimsPrincipal user); | ||
Task<TodoItem> Edit(TodoItem todoItem, ClaimsPrincipal user); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
using Microsoft.Graph; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Net.Http.Headers; | ||
using System.Threading.Tasks; | ||
|
||
namespace WebApp_OpenIDConnect_DotNet.BLL | ||
{ | ||
public class MSGraphService : IMSGraphService | ||
{ | ||
// the Graph SDK's GraphServiceClient | ||
private GraphServiceClient graphServiceClient; | ||
|
||
/// <summary> | ||
/// Gets the users in a tenant. | ||
/// </summary> | ||
/// <param name="accessToken">The access token for MS Graph.</param> | ||
/// <returns> | ||
/// A list of users | ||
/// </returns> | ||
public async Task<IEnumerable<User>> GetUsersAsync(string accessToken) | ||
{ | ||
IGraphServiceUsersCollectionPage users = null; | ||
|
||
try | ||
{ | ||
PrepareAuthenticatedClient(accessToken); | ||
users = await graphServiceClient.Users.Request() | ||
.Filter($"accountEnabled eq true") | ||
.Select("id, userPrincipalName") | ||
.GetAsync(); | ||
|
||
if (users?.CurrentPage.Count > 0) | ||
{ | ||
return users; | ||
} | ||
} | ||
catch (ServiceException e) | ||
{ | ||
Debug.WriteLine("We could not retrieve the user's list: " + $"{e}"); | ||
return null; | ||
} | ||
|
||
return users; | ||
} | ||
|
||
/// <summary> | ||
/// Prepares the authenticated client. | ||
/// </summary> | ||
/// <param name="accessToken">The access token.</param> | ||
private void PrepareAuthenticatedClient(string accessToken) | ||
{ | ||
try | ||
{ | ||
graphServiceClient = new GraphServiceClient("https://graph.microsoft.com/beta", | ||
new DelegateAuthenticationProvider( | ||
async (requestMessage) => | ||
{ | ||
await Task.Run(() => | ||
{ | ||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken); | ||
}); | ||
})); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine($"Could not create a graph client {ex}"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The chapter 1 is about signing-in to a web app? not calling graph?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmprieur are you sure you have the latest version? I reverted this change already.