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
| String ClientId = "20773535-6b8f-4f3d-8f0e-4b7710d79afe"; | |
| string UserName = "[email protected]"; | |
| string scope = "https://outlook.office.com/SMTP.Send"; | |
| string redirectUri = "msal20773535-6b8f-4f3d-8f0e-4b7710d79afe://auth"; | |
| string From = "[email protected]; | |
| String To = "[email protected]"; | |
| String SMTPServer = "smtp.office365.com"; | |
| Int32 SMTPPort = 587; | |
| PublicClientApplicationBuilder pcaConfig = PublicClientApplicationBuilder.Create(ClientId) |
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 Get-GraphUserPhoto { | |
| [CmdletBinding()] | |
| param ( | |
| [Parameter(Position = 0, Mandatory = $true)] | |
| [String] | |
| $Filename, | |
| [Parameter(Position = 1, Mandatory = $true)] | |
| [String] | |
| $MailboxName, | |
| [Parameter(Position = 2, Mandatory = $false)] |
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
| PSCredential pSCredential = new PSCredential("[email protected]", 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 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
| string MailboxName = "[email protected]"; | |
| 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 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
| System.Security.SecureString secureString = new System.Security.SecureString(); | |
| string myPassword = "password"; | |
| foreach (char c in myPassword) | |
| secureString.AppendChar(c); | |
| PSCredential credential = new PSCredential("[email protected]", 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 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
| 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 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
| 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 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
| 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 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 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 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
| $MailboxName = "[email protected]"; | |
| $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" |