Recently I was advised there were a lot of events being generated from a customers Lync server where they had recently migrated all their mailboxes to Office 365 but were using Enterprise Voice on premise. The event being generated was as follows:
Event ID – 32053 from the LS Storage Service – Storage Service had an EWS Autodiscovery failure.
I won’t past the whole error here but the crux of the error was as follows:
“ExchangeAutodiscoverException: code=ErrorEwsAutodiscover, reason=GetUserSettings failed, smtpAddressemail@example.com, Autodiscover Uri=http://autodiscover.domain.com/autodiscover/autodiscover.svc, Autodiscover WebProxy=<NULL> —> Microsoft.Exchange.WebServices.Data.ServiceRequestException: The request failed. The request was aborted: The request was canceled. —> System.Net.WebException: The request was aborted: The request was canceled. —> “
Now looking into this the Lync server could not create the connection to Office 365. I could see Autodiscover is working and the server could get a logon prompt if they hit the URL.
So I decided to check the OAuth Configuration – get-csoauthconfiguration and could see the URL for Exchange Autodiscover was set correctly however the clientauthorizationoauthserveridentity was still pointing at the hybrid exchange management server. So it lead me onto how do you setup an OAuth trust between a cloud service and on premise servers?
Well luckily enough help is at hand and I will try to guide you through the process…
First of all you must connect to PowerShell for the MSOL service in O365 and run the following get command:
- get-cstenant and then grab the displayname of your Office 365 tenancy.
- Fire up a Lync/SfB On Premise PowerShell Management Session – and then run the following command –
New-CsOAuthServer microsoft.sts -MetadataUrl "https://accounts.accesscontrol.windows.net/"Displayname"/metadata/json/1" where "Displayname" is the name you got from step one
- Then run Get-CsPartnerApplication “microsoft.exchange” – If you get a result then carry out step 4 if not move onto 5
- Remove-cspartnerapplication “Microsoft.Exchange”
New-CsPartnerApplication -Identity microsoft.exchange -ApplicationIdentifier 00000002-0000-0ff1-ce00-000000000000 -ApplicationTrustLevel Full -UseOAuthServer
Once this is complete you have configured Lync/SfB to use the Office 365 OAuth servers and you will start to see the following errors in the Event Log
Event ID 32054 – LS Storage Service – Storage Service had an OAuth authentication failure. CreateAppActAsToken failed, ex=OAuthConfigException: code=ErrorOAuthSts, reason=Recv RST response, failed, sts=https://accounts.accesscontrol.windows.net/a26842db-0e87-4d85-b745-9b7bf0f96067/tokens/OAuth/2, firstname.lastname@example.org, ex=The remote server returned an error: (401)
This s fine at this stage as we haven’t created the trust between on premise and Office 365 yet.
- Connect to Office 365 MSOL PowerShell whilst importing the following module : import-module MSOnlineExtended
- Run get-MSOLServicePrincipal – This will return lots of results but you are specifically after the one with the displayname “Microsoft Lync Server”
- Now at this stage I have made an assumption and that is that the OAuth certificate used by the Lync/SfB server on premise is up to date and is available to be exported. If not renewal this!
- Open up the MMC for certificates and identify the exact certificate currently assigned to Oauth for Lync/SfB this is generally an internal certificate. Export it as a X.509 Base64 (Which is not the default)
- Then run the following PS script where the line certificate.import contains the location of the exported certificate:
$certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate $certificate.Import("C:\Certificates\Office365.cer") $binaryValue = $certificate.GetRawCertData() $credentialsValue = [System.Convert]::ToBase64String($binaryValue)
New-MsolServicePrincipalCredential -AppPrincipalId 00000004-0000-0ff1-ce00-000000000000 -Type Asymmetric -Usage Verify -Value $credentialsValue -StartDate 02/12/2015 -EndDate 01/12/2015
- Now for the above command there are two items to be bear in mind first of all the startdate cannot be before today and the enddate can only be for a period of one year so even if the certificate lasts longer this setup can only last for a year!
Get-MsolServicePrincipalCredential -AppPrincipalId 00000004-0000-0ff1-ce00-000000000000 - The Returnkeyvalue is "Asymmetric"
- Then you should get a result with your certificate with the dates specified.
- Finally you need to set the set-cssoauthconfiguration -exchangeautodiscoverurl from https to http as currently https will not pass the tests and also flag up errors. This is done from the on premise Lync/SfB Management shell
Then you should be able to run test-csexstorageconnectivity -verbose and get a test passed result!
You should also see an event with ID 32048 where it states “OAuth was properly configured for Storage Service.
CsOAuthConfiguration validly configured”
Finally when you need to renew your setup which will be every year you will need to remove the MSOLServicePrincipal and replace it with your new certificate using the above process!