Skip to content

Commit

Permalink
graph demos copied from ms-600
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-kastil committed Sep 25, 2022
1 parent 1ca753e commit 4fe9b82
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 13 deletions.
File renamed without changes
File renamed without changes.
41 changes: 41 additions & 0 deletions Demos/06-Identity/Demo-05/graph-batching.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# @name auth
POST https://login.microsoftonline.com/{{tenantId}}/oauth2/v2.0/token HTTP/1.1
Content-type: application/x-www-form-urlencoded

grant_type=client_credentials
&client_id={{clientId}}
&client_secret={{clientSecret}}
&scope={{scope}}

### get all users
# @name users
GET https://graph.microsoft.com/v1.0/users
Authorization: Bearer {{auth.response.body.access_token}}


### get profile
GET https://graph.microsoft.com/v1.0/users/{{users.response.body.value[0].userPrincipalName }}/
Accept: application/json
Content-Type: application/json
Authorization: Bearer {{auth.response.body.access_token}}

### batch request
POST https://graph.microsoft.com/v1.0/$batch
Accept: application/json
Content-Type: application/json
Authorization: Bearer {{auth.response.body.access_token}}

{
"requests": [
{
"url": "/users/{{users.response.body.value[0].userPrincipalName }}/",
"method": "GET",
"id": "1"
},
{
"url": "/users/{{users.response.body.value[3].userPrincipalName }}/events",
"method": "GET",
"id": "2"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# REST Client
# Graph Samples

- graph-batching.http
- usr-grp-mgmt.http
- use-teamwork.http

## Use REST Client with Microsoft Graph

[REST Client VS Code Extension](https://marketplace.visualstudio.com/items?itemName=humao.rest-client)

To support Auth create an app registration in Azure AD using `create-appreg.azcli`.
To support Auth create an app registration in Azure AD using `setup-rest-client/create-appreg.azcli`.

Persist the output into your VS Code `settings.json`:
Persist the output into `settings.json` of Visual Studio Code:

```json
"rest-client.environmentVariables": {
"$shared": {},
"blogdemo":{
"dev":{
"tenantId":"<<your aad tenant>>",
"clientId":"<<your client id>>",
"clientSecret":"<<your client secret>>",
Expand All @@ -25,7 +31,7 @@ Assign the `User.ReadAll` permissions for out test as an Application Permission

>Note: If you need additional permission you will have to assign them using the app registrations "API Permissions" tab
To test choose "F1" -> "REST Clien: Switch Environment" and execute `get-token.http`.
To test choose "F1" -> "REST Clien: Switch Environment", chose environment `dev` and execute `get-auth-token.http`.

```json
# @name auth
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
app=vscode-rest-client
id=$(az ad app create --display-name $app --enable-access-token-issuance true --enable-id-token-issuance true --query appId -o tsv)

az ad app credential reset --id $id --append
109 changes: 109 additions & 0 deletions Demos/06-Identity/Demo-05/use-teamwork.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
### Set the graph base url
@graph=https://graph.microsoft.com/v1.0
@tenanat=integrationsonline
@splistapp=6a04eb4c-afa8-4673-829a-19ca38640abb

# Autenticate User
# @name auth
POST https://login.microsoftonline.com/{{tenantId}}/oauth2/v2.0/token HTTP/1.1
Content-type: application/x-www-form-urlencoded

grant_type=client_credentials
&client_id={{clientId}}
&client_secret={{clientSecret}}
&scope={{scope}}

### get a specific user
# @name user
GET {{graph}}/users/[email protected]
Authorization: Bearer {{auth.response.body.access_token}}


### Create group
# @name m365grp
POST {{graph}}/groups
Accept: application/json
Content-Type: application/json
Authorization: Bearer {{auth.response.body.access_token}}

{
"displayName":"graph-teams",
"mailNickname":"graph-teams",
"description":"a group for teams development",
"visibility":"Private",
"groupTypes":["Unified"],
"mailEnabled":true,
"securityEnabled":false,
"[email protected]":[
"{{graph}}/users/{{user.response.body.id }}",
],
"[email protected]":[
"{{graph}}/users/{{user.response.body.id }}"
]
}

### List groups
GET {{graph}}/groups
Accept: application/json
Authorization: Bearer {{auth.response.body.access_token}}

### Convert it to a Microsoft Teams
# @name team
POST {{graph}}/teams
Accept: application/json
Content-Type: application/json
Authorization: Bearer {{auth.response.body.access_token}}

{
"[email protected]": "{{graph}}/teamsTemplates('standard')",
"[email protected]": "{{graph}}/groups('{{m365grp.response.body.id}}')"
}

### List Teams
GET {{graph}}/groups?$select=id,displayName,resourceProvisioningOptions
Accept: application/json
Authorization: Bearer {{auth.response.body.access_token}}

### List all teams the current user has joined:
GET {{graph}}/users/{{user.response.body.id }}/joinedTeams
Accept: application/json
Authorization: Bearer {{auth.response.body.access_token}}

### Get channel id of default channel
# @name channel
GET {{graph}}/teams/{{m365grp.response.body.id}}/channels
Accept: application/json
Authorization: Bearer {{auth.response.body.access_token}}

### todo install app https://docs.microsoft.com/en-us/graph/api/team-list-installedapps?view=graph-rest-1.0&tabs=http
### Get installed apps
GET {{graph}}/teams/{{m365grp.response.body.id}}/installedApps
Accept: application/json
Authorization: Bearer {{auth.response.body.access_token}}

### Install app
POST {{graph}}/teams/{{m365grp.response.body.id}}/installedApps
Content-Type: application/json
Accept: application/json
Authorization: Bearer {{auth.response.body.access_token}}

{
"[email protected]":"{{graph}}/appCatalogs/teamsApps/{{splistapp}}"
}

### Add a tab to a teams default channel
POST {{graph}}/teams/{{m365grp.response.body.id}}/channels/{channelId}/tabs
Content-Type: application/json
Accept: application/json
Authorization: Bearer {{auth.response.body.access_token}}

{
"displayName": "Skills",
"[email protected]" : "{{graph}}//appCatalogs/teamsApps/{{m365grp.response.body.id}}",
"configuration": {
"entityId": "2a527703-1f6f-4559-a332-d8a7d288cd88",
"contentUrl": "https://{tenant}.sharepoint.com/sites/m365-dev/skills",
"removeUrl": null,
"websiteUrl": null
}
}
68 changes: 68 additions & 0 deletions Demos/06-Identity/Demo-05/usr-grp-mgmt.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
### Set base vars
@graph=https://graph.microsoft.com/v1.0

### Authenticate
# @name auth
POST https://login.microsoftonline.com/{{tenantId}}/oauth2/v2.0/token HTTP/1.1
Content-type: application/x-www-form-urlencoded

grant_type=client_credentials
&client_id={{clientId}}
&client_secret={{clientSecret}}
&scope={{scope}}

### get a specific user
# @name user
GET {{graph}}/users/[email protected]
Authorization: Bearer {{auth.response.body.access_token}}

### get a specific user photo
# @name photo
GET {{graph}}/users/{{user.response.body.id}}/photo/$value
Authorization: Bearer {{auth.response.body.access_token}}

### Get groups
# @name grps
GET {{graph}}/groups
Authorization: Bearer {{auth.response.body.access_token}}

### Get group owner
GET {{graph}}/groups/{{grps.response.body.value[0].id}}/owners
Authorization: Bearer {{auth.response.body.access_token}}

### Get the list of groups where a user is an owner
GET {{graph}}/users/{{user.response.body.id}}/ownedObjects
Authorization: Bearer {{auth.response.body.access_token}}

### list groups
# @name grps
GET {{graph}}/groups
Authorization: Bearer {{auth.response.body.access_token}}

### create grp
# @name grp
POST {{graph}}/groups/
Content-type: application/json
Authorization: Bearer {{auth.response.body.access_token}}

{
"description": "a dynamic group for ms-600",
"displayName": "ms600-dynamic",
"groupTypes": [
"Unified"
],
"mailEnabled": false,
"mailNickname": "ms600-dynamic",
"securityEnabled": true
}

### add dynamic members - requires Azure AD Premium P1 or higher
PATCH https://graph.microsoft.com/v1.0/groups/{{grp.response.body.id}}
Content-type: application/json
Authorization: Bearer {{auth.response.body.access_token}}

{
"groupTypes":
["Unified", "DynamicMembership"],
"membershipRule": "user.department -eq 'IT'","membershipRuleProcessingState": "on"
}
2 changes: 1 addition & 1 deletion Demos/06-Identity/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- Managing App Registrations & Understanding Microsoft Identity Authentication Flows
- MSAL secured Mail Daemon Service with Microsoft Graph
- MSAL secured .NET 6 Api consumed by Angular App using `@azure/msal-angular`

- Graph Samples
## Readings

[Microsoft Identity Platform Docs](https://docs.microsoft.com/en-us/azure/active-directory/develop/)
Expand Down
7 changes: 0 additions & 7 deletions Tooling/07-REST-Client/create-appreg.azcli

This file was deleted.

0 comments on commit 4fe9b82

Please sign in to comment.