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
function TrapInvalidAuth { | |
Trap { | |
if($_ -like "*InvalidAuthenticationToken*"){ | |
$authheader = GetAuthHeaders;Invoke-RestMethod -Uri $uri –Headers $authHeader –Method Get | |
} | |
} | |
Invoke-RestMethod -Uri $uri –Headers $authHeader –Method Get | |
} | |
function GetAuthHeaders |
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
#Require an AzureAD App with Microsoft Graph API and | |
# App Permission | |
# - Read mail in all mailboxes | |
# Impersonation Permission | |
# - Read user and shared mail | |
# Don't forget to grant permission | |
#Pre-reqs for REST API calls | |
$ClientID = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" | |
$ClientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=" |
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
#Create an Web Azure AD Application + Key | |
#Permission - Office 365 Management APIs (both App and Impersonation) | |
# - Read service health information for your organization | |
# - Read activity data for your organization | |
# Don't forget to click on Grant Permission | |
# Based on https://github.com/OfficeDev/O365-InvestigationTooling/blob/master/O365InvestigationDataAcquisition.ps1 | |
#Pre-reqs for REST API calls | |
$ClientID = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" | |
$ClientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" |
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
#You need AzureAD Module (Save-Module AzureAD -Path C:\temp) | |
function GetAuthHeaders | |
{ | |
[cmdletbinding()] | |
param( | |
[Parameter(Mandatory = $true)] | |
[string]$Tenant = "", | |
[Parameter(Mandatory = $true)] | |
[string]$UserPrincipalName = "" | |
) |
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
#Ref : https://www.michev.info/Blog/Post/1771/hacking-your-way-around-modern-authentication-and-the-powershell-modules-for-office-365 | |
$TenantName = "TENANTNAME.onmicrosoft.com" | |
$UserPrincipalName = "[email protected]" | |
$resourceUri = "https://outlook.office365.com" | |
$redirectUri = "urn:ietf:wg:oauth:2.0:oob" | |
$clientid = "a0c73c16-a7e3-4564-9a95-2bdf47383716" | |
#You need AzureAD Module (Save-Module AzureAD -Path C:\temp) | |
Add-Type -Path C:\Temp\AzureAD\Microsoft.IdentityModel.Clients.ActiveDirectory.dll |
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
#For this example you need an Azure App registered with a Self Sign Cert and a user with EWS Access to grab email. | |
#You need AzureAD Module (Save-Module AzureAD -Path C:\temp) | |
#You need EWS API 2.2 (www.microsoft.com/en-us/download/details.aspx?id=35371) | |
#App need to have Office 365 API access to read email. | |
# Permission under Office 365 Exchange Online: | |
# Admin : Use Exchange Web Services with full access to all mailboxes | |
# Delegate : Delegated permissions: full_access_as_user – Access mailbox as signed in user via Exc… | |
# Cert : https://github.com/Azure-Samples/active-directory-dotnet-daemon-certificate-credential/blob/master/Manual-Configuration-Steps.md | |
<# | |
$cert=New-SelfSignedCertificate -Subject "CN=Office365APIDemo" -CertStoreLocation "Cert:\CurrentUser\My" -KeyExportPolicy Exportable -KeySpec Signature |
NewerOlder