Skip to content

Instantly share code, notes, and snippets.

Avatar

Lee Ford leeford

View GitHub Profile
@leeford
leeford / index.ts
Last active October 5, 2020 20:49
Sample Graph SDK using client credential auth provider
View index.ts
import { config } from 'dotenv';
import * as path from 'path';
import "isomorphic-fetch";
import { Client, ClientOptions } from "@microsoft/microsoft-graph-client";
import { ClientCredentialAuthenticationProvider } from "./AuthenticationProvider"
// Read environment variables from .env file
const ENV_FILE = path.join(__dirname, '.env');
config({ path: ENV_FILE });
@leeford
leeford / AuthenticationProvider.ts
Last active October 5, 2020 20:42
Sample Graph SDK Client Credential Auth Provider
View AuthenticationProvider.ts
import { AuthenticationProvider } from "@microsoft/microsoft-graph-client";
import * as qs from "qs";
import axios from "axios"
export class ClientCredentialAuthenticationProvider implements AuthenticationProvider {
public async getAccessToken(): Promise<string> {
const url: string = "https://login.microsoftonline.com/" + process.env.MicrosoftAppTenantId + "/oauth2/v2.0/token";
@leeford
leeford / TeamsNetworkUsageWorkbook.json
Created June 18, 2020 16:31
Teams Network Usage Workbook
View TeamsNetworkUsageWorkbook.json
{
"version": "Notebook/1.0",
"items": [
{
"type": 1,
"content": {
"json": "## Teams Client Network Usage\n"
},
"name": "text - 2"
},
@leeford
leeford / TeamsAdaptiveCardTweet.json
Created February 23, 2020 20:28
Teams Adaptive Card Tweet - used with a Flow
View TeamsAdaptiveCardTweet.json
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"body": [
{
"type": "TextBlock",
"text": "@{triggerBody()?['UserDetails']?['FullName']} has mentioned you on Twitter",
"weight": "Bolder",
"size": "Large"
@leeford
leeford / SampleAdaptiveCard.json
Created February 23, 2020 20:14
Sample Adaptive Card
View SampleAdaptiveCard.json
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"body": [
{
"type": "TextBlock",
"text": "Publish Adaptive Card schema",
"weight": "bolder",
"size": "large"
@leeford
leeford / GraphAPIDeviceCode.ps1
Created September 23, 2019 09:16
GraphAPIDeviceCode.ps1 - Sample PowerShell (Core and Windows) script for authenticating with Graph API using device codes. See https://www.lee-ford.co.uk/graph-api-device-code/ for more information.
View GraphAPIDeviceCode.ps1
# Application (client) ID, tenant ID, resource and scope
$clientId = ""
$tenantId = ""
$resource = "https://graph.microsoft.com/"
$scope = "Group.Read.All"
$codeBody = @{
resource = $resource
client_id = $clientId
@leeford
leeford / Get-ChannelWebpageTabs.ps1
Last active October 11, 2019 20:53
Example script to list all web page Tabs in Teams Channels
View Get-ChannelWebpageTabs.ps1
# Get-ChannelWebpageTabs.ps1
# Example script to list all webpage Tabs in Teams Channels
function GraphAPICall {
param (
[Parameter(mandatory = $true)][uri]$URI
)
$Headers = @{"Authorization" = "Bearer $script:token" }
@leeford
leeford / GraphAPIPaging.ps1
Created August 4, 2019 21:05
Example script on paging with Graph API
View GraphAPIPaging.ps1
# GraphAPIPaging.ps1
# Example script on paging with Graph API
### Authenticate ###
# Application (client) ID, tenant ID and secret
$clientId = ""
$tenantId = ""
$clientSecret = ''
# Construct URI
@leeford
leeford / New-Team.ps1
Created April 9, 2019 19:39
Create a new Team using Graph API
View New-Team.ps1
# New-Team.ps1
# Create a new Team using Graph API
# Application (client) ID, tenant ID and secret
$clientId = "clientid"
$tenantId = "tenantid"
$clientSecret = 'secret'
# Contruct URI
$uri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"
@leeford
leeford / Get-Me.ps1
Created April 9, 2019 19:35
Get logged in user using Graph API
View Get-Me.ps1
# Get-Me.ps1
# Get logged in user using Graph API
# Add required assemblies
Add-Type -AssemblyName System.Web, PresentationFramework, PresentationCore
# Application (client) ID, tenant ID and redirect URI
$clientId = "clientid"
$tenantId = "tenantid"
$redirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient"