forked from d-titusgicheru/microsoft-graph-explorer-api
-
Notifications
You must be signed in to change notification settings - Fork 0
AB#38712 Check user resource ownership #14
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
omersayshi
merged 50 commits into
interns/feature/ge-app-mode-proxy-endpoint
from
interns/omersayshi/38712-check-ownership
Aug 4, 2021
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
b8845d6
Merge pull request #598 from microsoftgraph/dev
MaggieKimani1 dae70db
Merge pull request #606 from microsoftgraph/dev
irvinesunday 19fdb7c
Merges dev into master (#617)
MaggieKimani1 ab21557
Use null-conditionals when capturing count of enumerables
irvinesunday 8d8da95
Subtle change to trigger build
irvinesunday 7fe617a
Merge pull request #623 from microsoftgraph/fix/is/include-null-condi…
irvinesunday 39f44e7
Revert metadata source
irvinesunday 3828ef3
Merge pull request #624 from microsoftgraph/fix/is/revert-metadata-so…
irvinesunday a49e17a
Merges dev into master (#617) (#626)
irvinesunday c17c1c7
Merge branch 'master' into dev
andrueastman 359b96e
Merge pull request #625 from microsoftgraph/dev
irvinesunday 357bd80
Fix: Revert explode value to false in operation parameters (#621)
irvinesunday f28bb50
Merge branch 'master' into dev
irvinesunday 86727cf
Merge pull request #627 from microsoftgraph/dev
irvinesunday 1b0eb8b
Update PermissionsStore class (#622)
MaggieKimani1 a8eed5b
Merge branch 'master' into dev
irvinesunday ed4b4c1
Task: add GitHub templates (#634)
thewahome c0317db
Added .yml file for CI/CD pipeline on interns' fork
jerryxihe ac2f1ee
Set up CI with Azure Pipelines
jerryxihe 512e5d9
Merge pull request #1 from LokiLabs/interns/jerryxihe/38984-added-azu…
jerryxihe 58023a9
Bump Microsoft.AspNetCore.Authorization from 5.0.7 to 5.0.8
dependabot[bot] 0003a64
Merge pull request #639 from microsoftgraph/dependabot/nuget/Microsof…
baywet 3022c38
Bump Microsoft.AspNetCore.Mvc.NewtonsoftJson from 5.0.7 to 5.0.8
dependabot[bot] 0d3174a
Merge pull request #640 from microsoftgraph/dependabot/nuget/Microsof…
baywet e8a133c
Bump Microsoft.AspNetCore.Authentication.JwtBearer from 5.0.7 to 5.0.8
dependabot[bot] b245bf7
Revert "Set up CI with Azure Pipelines"
jerryxihe fb6c6b4
Merge pull request #642 from microsoftgraph/dependabot/nuget/Microsof…
baywet 959a7b5
Fix: Get all distinct permissions (#636)
irvinesunday e4935ca
Bump Microsoft.Extensions.DependencyInjection from 5.0.1 to 5.0.2
dependabot[bot] 78ec6b8
Merge pull request #641 from microsoftgraph/dependabot/nuget/Microsof…
baywet 9136d0f
Merge pull request #2 from LokiLabs/interns/38984-add-pipeline-for-in…
jerryxihe 84a1f36
Merge branch 'microsoftgraph:dev' into interns/dev
acchiang ba95e6c
Renamed interns .yml
jerryxihe 16444e2
Renamed interns pipeline .yml to accurately reflect its use
jerryxihe 779ce91
Merge pull request #5 from LokiLabs/revert-1-interns/jerryxihe/38984-…
jerryxihe eca9e45
Merge pull request #7 from LokiLabs/interns/jerryxihe/38984-change-in…
jerryxihe 4b402c6
AB#38984 Merging interns pipeline .yml into LokiLabs/dev (#8)
jerryxihe 151fc60
Added `master` and `dev` to interns pipeline triggers
jerryxihe 4ac9ef9
Merge branch 'dev' into interns/dev
jerryxihe 5f0f758
d60609a
Fixed small error
omersayshi e99db79
Merge branch 'interns/dev' into interns/omersayshi/39171-app-mode-sam…
omersayshi 44611b2
Fixed another small typo
omersayshi 9474f45
Merge pull request #13 from LokiLabs/interns/omersayshi/39171-app-mod…
omersayshi a924fc0
Added ownership check functions
omersayshi 79c0986
Finalized tenant and client id retrieval from token
omersayshi 9d70e8f
Cleanup
omersayshi da84f62
Merge remote-tracking branch 'origin/interns/dev' into interns/omersa…
omersayshi 0e43543
294cdbd
Added PR changes and fixed error to return JSON
omersayshi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| --- | ||
| name: Bug report | ||
| about: Create a report to help us improve | ||
| title: '' | ||
| labels: '' | ||
| assignees: '' | ||
|
|
||
| --- | ||
|
|
||
| **Describe the bug** | ||
| A clear and concise description of what the bug is. | ||
|
|
||
| **To Reproduce** | ||
| Steps to reproduce the behavior: | ||
| 1. Go to '...' | ||
| 2. Click on '....' | ||
| 3. Scroll down to '....' | ||
| 4. See error | ||
|
|
||
| **Expected behavior** | ||
| A clear and concise description of what you expected to happen. | ||
|
|
||
| **Screenshots** | ||
| If applicable, add screenshots to help explain your problem. | ||
|
|
||
| **Desktop (please complete the following information):** | ||
| - OS: [e.g. iOS] | ||
| - Browser [e.g. chrome, safari] | ||
| - Version [e.g. 22] | ||
|
|
||
| **Smartphone (please complete the following information):** | ||
| - Device: [e.g. iPhone6] | ||
| - OS: [e.g. iOS8.1] | ||
| - Browser [e.g. stock browser, safari] | ||
| - Version [e.g. 22] | ||
|
|
||
| **Additional context** | ||
| Add any other context about the problem here. | ||
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,20 @@ | ||
| --- | ||
| name: Feature request | ||
| about: Suggest an idea for this project | ||
| title: '' | ||
| labels: '' | ||
| assignees: '' | ||
|
|
||
| --- | ||
|
|
||
| **Is your feature request related to a problem? Please describe.** | ||
| A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
|
|
||
| **Describe the solution you'd like** | ||
| A clear and concise description of what you want to happen. | ||
|
|
||
| **Describe alternatives you've considered** | ||
| A clear and concise description of any alternative solutions or features you've considered. | ||
|
|
||
| **Additional context** | ||
| Add any other context or screenshots about the feature request here. |
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,20 @@ | ||
|
|
||
| ## Overview | ||
|
|
||
| Brief description of what this PR does, and why it is needed. | ||
|
|
||
| ### Demo | ||
|
|
||
| Optional. Screenshots, `curl` examples, etc. | ||
|
|
||
| ### Notes | ||
|
|
||
| Optional. Ancillary topics, caveats, alternative strategies that didn't work out, anything else. | ||
|
|
||
| ## Testing Instructions | ||
|
|
||
| * How to test this PR | ||
| * Prefer bulleted description | ||
| * Start after checking out this branch | ||
| * Include any setup required, such as bundling scripts, restarting services, etc. | ||
| * Include test case, and expected output |
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,22 @@ | ||
| using Microsoft.Graph; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace GraphExplorerAppModeService.Interfaces | ||
| { | ||
| /// <summary> | ||
| /// This class is for functions that call Microsoft Graph to check if the client owns the Teams resource they are trying to call against. | ||
| /// </summary> | ||
| public interface IGraphService | ||
|
omersayshi marked this conversation as resolved.
|
||
| { | ||
| /// <summary> | ||
| /// ErrorMessage will contain the error message from the Graph Client call. | ||
| /// </summary> | ||
| string ErrorMessage { get; set; } | ||
|
omersayshi marked this conversation as resolved.
|
||
|
|
||
| Task<bool> VerifyOwnership(GraphServiceClient graphClient, string query, string clientId); | ||
| } | ||
| } | ||
12 changes: 0 additions & 12 deletions
12
GraphExplorerAppModeService/Interfaces/IGraphServiceClient.cs
This file was deleted.
Oops, something went wrong.
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
18 changes: 0 additions & 18 deletions
18
GraphExplorerAppModeService/Services/GraphClientService.cs
This file was deleted.
Oops, something went wrong.
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,77 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using GraphExplorerAppModeService.Interfaces; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Graph; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace GraphExplorerAppModeService.Services | ||
| { | ||
| public class GraphService : IGraphService | ||
| { | ||
| private string errorMessage; | ||
|
|
||
| // Docs defined in IGraphService | ||
| public string ErrorMessage { get; set; } | ||
|
omersayshi marked this conversation as resolved.
|
||
|
|
||
| public async Task<bool> VerifyOwnership(GraphServiceClient graphClient, string query, string clientId) | ||
| { | ||
| string[] queryList = query.Split("/"); | ||
|
|
||
| for (int i=0; i < queryList.Length; i++) | ||
| { | ||
| if (queryList[i] == "teams" && i + 1 < queryList.Length) | ||
| { | ||
| return await VerifyTeamsOwnership(graphClient, queryList[i + 1], clientId); | ||
|
omersayshi marked this conversation as resolved.
|
||
| } else if (queryList[i] == "chats" && i + 1 < queryList.Length) | ||
| { | ||
| return await VerifyChatOwnership(graphClient, queryList[i + 1], clientId); | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private async Task<bool> VerifyTeamsOwnership(GraphServiceClient graphClient, string teamId, string clientId) | ||
| { | ||
| try | ||
| { | ||
| var owners = await graphClient.Groups[teamId].Owners.Request().GetAsync(); | ||
|
|
||
| foreach (var owner in owners) | ||
| { | ||
| if (clientId == owner.Id) return true; | ||
|
csyan5 marked this conversation as resolved.
|
||
| } | ||
| } | ||
| catch (ServiceException e) | ||
| { | ||
| ErrorMessage = e.Message; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private async Task<bool> VerifyChatOwnership(GraphServiceClient graphClient, string chatId, string clientId) | ||
| { | ||
| try | ||
| { | ||
| var members = await graphClient.Chats[chatId].Members.Request().GetAsync(); | ||
|
|
||
| foreach (AadUserConversationMember member in members) | ||
| { | ||
| if (clientId == member.UserId && member.Roles.Contains("owner")) return true; | ||
| } | ||
| } | ||
| catch (ServiceException e) | ||
| { | ||
| ErrorMessage = e.Message; | ||
|
omersayshi marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| } | ||
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.
you can also add a section called
actual behaviorto understand the bug more easily and clearlyThere 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.
These changes are from an upstream merge and not mine, so I cant change it.