This file contains 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
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1); | |
String ClientId = "111111-52b3-4102-aeff-aad2292ab01c"; | |
String MailboxName = "gscales@datarumble.com"; | |
HttpClient httpClient = new HttpClient(); | |
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (compatible; AcmeInc/1.0)"); | |
StringContent RealmRequest = new StringContent("{\"username\":\"" + MailboxName + "\"}"); | |
String DiscoveryURL = "https://login.microsoftonline.com/common/GetCredentialType"; | |
dynamic RealmDiscover = JsonConvert.DeserializeObject(httpClient.PostAsync(DiscoveryURL, RealmRequest).Result.Content.ReadAsStringAsync().Result); | |
if((Int32)RealmDiscover.EstsProperties.DomainType == 1 || (Int32)RealmDiscover.EstsProperties.DomainType == 2) | |
{ |
This file contains 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
$MailboxName = "user@domain.com"; | |
$body = @{ | |
"username" = $MailboxName | |
} | |
$RealmDiscover = Invoke-RestMethod -Uri ("https://login.microsoftonline.com/common/GetCredentialType") -ContentType "application/json; charset=UTF-8" -Method POST -Body ($body | ConvertTo-Json) | |
if ([Int]$RealmDiscover.EstsProperties.DomainType -eq 1 -bor [Int32]$RealmDiscover.EstsProperties.DomainType -eq 2) { | |
throw "Not Office365 or hybrid" | |
} | |
else { | |
$AutoDiscoverURI = "https://outlook.office365.com/autodiscover/autodiscover.json/v1.0/" + $MailboxName + "?Protocol=EWS" |
This file contains 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 Show-OAuthWindow { | |
[CmdletBinding()] | |
param ( | |
[System.Uri] | |
$Url | |
) | |
## Start Code Attribution | |
## Show-AuthWindow function is the work of the following Authors and should remain with the function if copied into other scripts | |
## https://foxdeploy.com/2015/11/02/using-powershell-and-oauth/ |
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApp23 | |
{ | |
class OAuthExchangeServiceBinding : com.office365.outlook.ExchangeServiceBinding | |
{ |
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Net; | |
using System.Threading.Tasks; | |
using System.Net.Http; | |
using Microsoft.Identity.Client; | |
using Newtonsoft.Json; | |
using EWSWSDLoAuthExample.com.office365.outlook; |
This file contains 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
Import-Module CredentialManager | |
Import-Module ./AzureMFAOTPv2.ps1 | |
$Cred = Get-Credential | |
$token = Get-AccessTokenMFA -OTP (Get-TimeBasedOneTimePassword -SharedSecret (Get-StoredCredential -Target Auth.GS -AsCredentialObject).Password) -Credential $Cred -ClientId 'a0c73c16-a7e3-4564-9a95-2bdf47383716' -Scopes 'https://outlook.office365.com/.default' | |
$domain = $Cred.UserName.Split('@')[1] | |
$tokenValue = ConvertTo-SecureString "Bearer $($token.access_token)" -AsPlainText -Force | |
$credential = New-Object System.Management.Automation.PSCredential($Cred.UserName, $tokenValue) | |
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid?DelegatedOrg=$($domain)&BasicAuthToOAuthConversion=true" -Credential $credential -Authentication Basic -AllowRedirection | |
Import-PSSession $session |
This file contains 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
System.Security.SecureString secureString = new System.Security.SecureString(); | |
string myPassword = "password"; | |
foreach (char c in myPassword) | |
secureString.AppendChar(c); | |
PSCredential credential = new PSCredential("glen@domain.com", secureString); | |
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("https://ps.outlook.com/PowerShell-LiveID?PSVersion=2.0"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential); | |
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic; | |
connectionInfo.SkipCACheck = true; | |
connectionInfo.SkipCNCheck = true; |
This file contains 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
string MailboxName = "gscales@datarumble.com"; | |
string scope = "https://outlook.office365.com/.default"; | |
string ClientId = "a0c73c16-a7e3-4564-9a95-2bdf47383716"; | |
PublicClientApplicationBuilder pcaConfig = PublicClientApplicationBuilder.Create(ClientId); | |
pcaConfig.WithAuthority(AadAuthorityAudience.AzureAdMultipleOrgs, false); | |
var TokenResult = pcaConfig.Build().AcquireTokenInteractive(new[] { scope }) |
This file contains 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
PSCredential pSCredential = new PSCredential("user@blah.onmicrosoft.com", new NetworkCredential("", "pass##").SecurePassword); | |
string MailboxName = pSCredential.UserName; | |
string scope = "https://outlook.office365.com/.default"; | |
string ClientId = "a0c73c16-a7e3-4564-9a95-2bdf47383716"; | |
HttpClient Client = new HttpClient(); | |
var TenantId = ((dynamic)JsonConvert.DeserializeObject(Client.GetAsync("https://login.microsoftonline.com/" + MailboxName.Split('@')[1] + "/v2.0/.well-known/openid-configuration").Result.Content.ReadAsStringAsync().Result)).authorization_endpoint.ToString().Split('/')[3]; | |
PublicClientApplicationBuilder pcaConfig = PublicClientApplicationBuilder.Create(ClientId); | |
pcaConfig.WithTenantId(TenantId); |
This file contains 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 Get-GraphUserPhoto { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Position = 0, Mandatory = $true)] | |
[String] | |
$Filename, | |
[Parameter(Position = 1, Mandatory = $true)] | |
[String] | |
$MailboxName, | |
[Parameter(Position = 2, Mandatory = $false)] |