■ OAuth 인증 구성이란?
Exchange와 Exchange Online 간에 OAuth 인증 구성
Exchange Server에서 Exchange와 Exchange Online 조직 간에 OAuth 인증을 구성하는 방법
learn.microsoft.com
음.. 잘은 모르겠지만 Exchange 서버와 온라인 간 트러스트 관계를 인증해주는 프로토콜인 것 같다!
대리님 말씀으로는 서로의 일정을 조회/공유하려면 이 설정이 필요하다고 한다
그럼 구성을 시작해보자~!

실패했어요
엉엉
여기 문서에 나와있는대로 따라가기만 하면 되는데 외않되....?
Exchange와 Exchange Online 간에 OAuth 인증 구성
Exchange Server에서 Exchange와 Exchange Online 조직 간에 OAuth 인증을 구성하는 방법
learn.microsoft.com
대리님은 이런게 좋은 테스트라고 해주셨으나 으 스트레스다
봐봐요 여러분 테스트하면서 생성한 커넥터 다 지우고 새로 생성해볼게요
태초마을입니다
1단계: Exchange Online 조직에 대한 권한 부여 서버 개체 만들기
New-AuthServer -Name "WindowsAzureACS" -AuthMetadataUrl "https://accounts.accesscontrol.windows.net/hbna.co.kr/metadata/json/1"
New-AuthServer -Name "evoSTS" -Type AzureAD -AuthMetadataUrl "https://login.windows.net/hbna.co.kr/federationmetadata/2007-06/federationmetadata.xml"
<your tenant initial domain> = hbna.co.kr 로 바꿔주고 서버에서 쉘 실행하기
2단계: Exchange Online 조직에 대해 파트너 응용 프로그램을 사용하도록 설정합니다.
Get-PartnerApplication | Where-Object {$_.ApplicationIdentifier -eq "00000002-0000-0ff1-ce00-000000000000" -and $_.Realm -eq ""} | Set-PartnerApplication -Enabled $true
문서에 있는거 그대로 복붙해서 EXO 모듈에서 실행하기
3단계: 온-프레미스 권한 부여 인증서 내보내기
$thumbprint = (Get-AuthConfig).CurrentCertificateThumbprint
if((Test-Path $env:SYSTEMDRIVE\OAuthConfig) -eq $false)
{
New-Item -Path $env:SYSTEMDRIVE\OAuthConfig -Type Directory
}
Set-Location -Path $env:SYSTEMDRIVE\OAuthConfig
$oAuthCert = (dir Cert:\LocalMachine\My) | Where-Object {$_.Thumbprint -match $thumbprint}
$certType = [System.Security.Cryptography.X509Certificates.X509ContentType]::Cert
$certBytes = $oAuthCert.Export($certType)
$CertFile = "$env:SYSTEMDRIVE\OAuthConfig\OAuthCert.cer"
[System.IO.File]::WriteAllBytes($CertFile, $certBytes)
내보내고 가져오기 귀찮으므로 서버 Shell에서 그대로 실행
C: 드라이브에 인증서가 생성되었따
4단계: Microsoft Entra ACS(Access Control Service)에 온-프레미스 권한 부여 인증서 업로드
Connect-MgGraph -Scopes Application.ReadWrite.All
$CertFile = "$env:SYSTEMDRIVE\OAuthConfig\OAuthCert.cer"
$objFSO = New-Object -ComObject Scripting.FileSystemObject
$CertFile = $objFSO.GetAbsolutePathName($CertFile)
$cer = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($CertFile)
$binCert = $cer.GetRawCertData()
$credValue = [System.Convert]::ToBase64String($binCert)
$ServiceName = "00000002-0000-0ff1-ce00-000000000000"
Write-Host "[+] Trying to query the service principals for service: $ServiceName" -ForegroundColor Cyan
$p = Get-MgServicePrincipal -Filter "AppId eq '$ServiceName'"
Write-Host "[+] Trying to query the keyCredentials for service: $ServiceName" -ForegroundColor Cyan
$servicePrincipalKeyInformation = Get-MgServicePrincipal -Filter "AppId eq '$ServiceName'" -Select "keyCredentials"
$keyCredentialsLength = $servicePrincipalKeyInformation.KeyCredentials.Length
if ($keyCredentialsLength -gt 0) {
Write-Host "[+] $keyCredentialsLength existing key(s) found - we keep them if they have not expired" -ForegroundColor Cyan
$newCertAlreadyExists = $false
$servicePrincipalObj = New-Object -TypeName Microsoft.Graph.PowerShell.Models.MicrosoftGraphServicePrincipal
$keyCredentialsArray = @()
foreach ($cred in $servicePrincipalKeyInformation.KeyCredentials) {
$thumbprint = [System.Convert]::ToBase64String($cred.CustomKeyIdentifier)
Write-Host "[+] Processing existing key: $($cred.DisplayName) thumbprint: $thumbprint" -ForegroundColor Cyan
if ($newCertAlreadyExists -ne $true) {
$newCertAlreadyExists = ($cer.Thumbprint).Equals($thumbprint, [System.StringComparison]::OrdinalIgnoreCase)
}
if ($cred.EndDateTime -lt (Get-Date)) {
Write-Host "[+] This key has expired on $($cred.EndDateTime) and will not be retained" -ForegroundColor Yellow
continue
}
$keyCredential = New-Object -TypeName Microsoft.Graph.PowerShell.Models.MicrosoftGraphKeyCredential
$keyCredential.Type = "AsymmetricX509Cert"
$keyCredential.Usage = "Verify"
$keyCredential.Key = $cred.Key
$keyCredentialsArray += $keyCredential
}
if ($newCertAlreadyExists -eq $false) {
Write-Host "[+] New key: $($cer.Subject) thumbprint: $($cer.Thumbprint) will be added" -ForegroundColor Cyan
$keyCredential = New-Object -TypeName Microsoft.Graph.PowerShell.Models.MicrosoftGraphKeyCredential
$keyCredential.Type = "AsymmetricX509Cert"
$keyCredential.Usage = "Verify"
$keyCredential.Key = [System.Text.Encoding]::ASCII.GetBytes($credValue)
$keyCredentialsArray += $keyCredential
$servicePrincipalObj.KeyCredentials = $keyCredentialsArray
Update-MgServicePrincipal -ServicePrincipalId $p.Id -BodyParameter $servicePrincipalObj
} else {
Write-Host "[+] New key: $($cer.Subject) thumbprint: $($cer.Thumbprint) already exists and will not be uploaded again" -ForegroundColor Yellow
}
} else {
$params = @{
type = "AsymmetricX509Cert"
usage = "Verify"
key = [System.Text.Encoding]::ASCII.GetBytes($credValue)
}
Write-Host "[+] This is the first key which will be added to this service principal" -ForegroundColor Cyan
Update-MgServicePrincipal -ServicePrincipalId $p.Id -KeyCredentials $params
}
인증서를 저장한 서버에서 Powershell MgGrah 모듈을 실행해서 위 스크립트를 친다
이전에 테스트할 때 있던 인증 키가 있어서 그대로 놔두겠다는 것 같다.....
이미 불안합니다
5단계: 내부 및 외부 온-프레미스 Exchange HTTP 엔드포인트에 대한 모든 호스트 이름 기관을 Microsoft Entra ID로 등록
$ServiceName = "00000002-0000-0ff1-ce00-000000000000";
$x = Get-MgServicePrincipal -Filter "AppId eq '$ServiceName'"
$x.ServicePrincipalNames += "https://mail.contoso.com/"
$x.ServicePrincipalNames += "https://autodiscover.contoso.com/"
Update-MgServicePrincipal -ServicePrincipalId $x.Id -ServicePrincipalNames $x.ServicePrincipalNames
"https://mail.hbna.co.kr/", "https://autodiscover.hbna.co.kr" 로 바꾸기
MgGrpah 모듈에서 실행
뭘 retry를 계속 했다는지 알 수 없음
빨간색 떴다 망한 징조가 보인다.....

잘 추가되었는지 확인하는 명령어
잘 추가된 것 같다...?
6단계: 온-프레미스 조직에서 Microsoft 365 또는 Office 365로 IntraOrganizationConnector 만들기
$ServiceDomain = (Get-AcceptedDomain | Where-Object {$_.DomainName -like "*.mail.onmicrosoft.com"}).DomainName.Address
New-IntraOrganizationConnector -Name ExchangeHybridOnPremisesToOnline -DiscoveryEndpoint https://outlook.office365.com/autodiscover/autodiscover.svc -TargetAddressDomains $ServiceDomain
문서에 있는 그대로 서버 Shell에서 실행 (온프렘>온라인 커넥터 만들기)
7단계: Microsoft 365 또는 Office 365 조직에서 온-프레미스 Exchange 조직으로 IntraOrganizationConnector 만들기
New-IntraOrganizationConnector -Name ExchangeHybridOnlineToOnPremises -DiscoveryEndpoint <your on-premises AutoDiscover endpoint> -TargetAddressDomains <your on-premises SMTP domain(s)>
<your on-premises AutoDiscover endpoint> = https://outlook.office365.com/autodiscover/autodiscover.svc
<your on-premises SMTP domain(s)> = hbna.co.kr
으로 바꿔서 EXO 모듈에서 실행 (온라인>온프렘 커넥터 만들기)
작동 여부는 어떻게 확인하나요?
자 이제 중요한 작동 여부!!!!!!
온프렘 계정: User1@hbna.co.kr
온라인 계정: AdeleV@hbna.co.kr
■ 온프렘 > 온라인 연결 확인 (서버 Shell)
Test-OAuthConnectivity -Service EWS -TargetUri https://outlook.office365.com/ews/exchange.asmx -Mailbox <On-Premises Mailbox> -Verbose | Format-List
User1 연결 Success
■ 온라인 > 온프렘 연결 확인 (EXO 모듈)
Test-OAuthConnectivity -Service EWS -TargetUri <external hostname authority of your Exchange On-Premises deployment>/metadata/json/1 -Mailbox <Exchange Online Mailbox> -Verbose | Format-List
AdeleV 연결 Error
왤까?
왜?
내가 볼 때 5단계 빨간 에러 때문인 것 같은데 무엇을 Retry를 하는지 알 수가 있어야지...
일단 스킵하고 다른 테스트 하자ㅠ
지피티 선생님과 싸우면서 코드를 계속 트러블슈팅한 결과...
CU 업데이트를 해야한다는 결론이 나왔다
현재 버전: Exchange 2019 CU 14
15로 업데이트 해보고 다시 시도하기!
'업무일지 > Exchange' 카테고리의 다른 글
신입 엔지니어 업무일지 | [완료] AD 2012 R2 + Exchange Server 2010 구축 (0) | 2025.04.16 |
---|---|
신입 엔지니어 업무일지 | [진행중] Exchange에서 IMAP/POP3를 언제써요? (0) | 2025.02.21 |
신입 엔지니어 업무일지 | [완료] Exchange Server DAG 구성 ② 네트워크 설정 및 장애 테스트 (0) | 2025.01.06 |
신입 엔지니어 업무일지 | [완료] Exchange Server DAG 구성 ① DAG 생성하기 (1) | 2025.01.06 |
신입 엔지니어 업무일지 | [완료] Exchange 하이브리드 메일 흐름 테스트 ③ - 중앙집중식 구성 ON/OFF (2) | 2025.01.03 |