[BC20] Gebruik Azure AD OpenID om te authenticeren
Microsoft wil graag dat we Azure AD OpenID gaan gebruiken voor authenticatie. Vanaf Business Central 20 is dat ook mogelijk. Je kunt ook de oude manier gebruiken door in de webclient de regel "UseLegacyACSAuthentication": "true" toe te voegen, maar meer toekomstgericht is om het als volgt te doen. Ik ga ervan uit dat er al een Azure tenant beschikbaar is.
- log in op https://portal.azure.com ga naar Azure Active Directory, en kies dan voor App Registrations.
- Klik op New Registration. Geef deze een naam, en kies voor "Accounts in this organizational directory only (single tenant)"
- Kies bij Redirect URI (Optional) voor web, en voer daar het adres van de webclient in, gevolgd door SignIn - dus bijvoorbeeld https://bc.companyname.nl/BC210/SignIn
- Klik op register
- Klik op het volgende scherm bij Redirect URIs op 1 Web. Klik bij Web op Add URI, en voeg de URI https://bc.companyname.nl/BC210/OAuthlanding.htm toe. Verander bc.companyname.nl naar je eigen URL.
- Kies onder implicit grant and Hybrid flows bij Select the tokens you would like to be issued by the authorization endpoint: voor ID Tokens (used for implicit and hybrid flows)
- Klik vervolgens op Save.
- Ga terug naar Overview en klik op Add an Application ID URl, of ga naar Expose an API. Klik naast Application ID URI op Set. Er wordt nu een Application ID URI getoond. Verander hier niets aan, en klik op Save.
- Ga terug naar de overview. Je hebt de application (client) ID en de Directory (Tenant) ID nodig. Daarnaast heb je ook het domein nodig van de Azure Tenant, zoals companyname.onmicrosoft.com
Je kunt met onderstaand script dan de service aanpassen. Het script gaat ervan uit dat de webclient dezelfde naam heeft als de service. Heet de service BC210, dan moet de weblclient ook BC210 gebruiken.
Vul het juiste Directory (Tenant) ID in bij de variabele $TenantID
Bij $ApplicationID voer je de Application (Client) ID in,
Bij $AppID voer je de waarde van het domain in.
De $ServerInstance verander je in de juiste naam, $Authenticationtype is AccessControlService, de $WebURLBase is het basisadres van de webclient (zoals bc.companyname.nl uit de redirect URIs), en uiteraard moet het correcte certificaatthumbprint worden ingevoerd.
Daarna kun je het script starten (elevated), en wordt de service aangepast zodat er gebruik kan worden gemaakt van Azure AD OpenID
Ook wordt SSL aangezet op SOAP en ODATA en worden deze geactiveerd.
$ServerInstance = "BC210"
$AuthenticationType="AccessControlService"
$TenantID = "9e97a650-59e6-451a-828b-384143be53af"
$ApplicationID = "bf79acf6-03d7-49b8-b0bc-e662aa079bf1"
$AppID = "https://companyname.onmicrosoft.com/$ApplicationID"
$WebURLBase="bc.companyname.nl"
$CertificateThumbPrint="f2017d76a452a16b447ee5f1971e4df7487a24cb"
$SOAPPort=7047
$OdataPort=7048
#--- no need to change anything below this line.------------
$OdataBaseURL="https://${WebUrlBase}:$OdataPort/$ServerInstance/"
$SoapBaseURL="https://${WebUrlBase}:$SOAPPort/$ServerInstance/"
$WSFederationEndPoint="https://login.microsoftonline.com/$TenantID/wsfed?wa=wsignin1.0%26wtrealm=$appid%26wreply=https://$WebURLBase/$ServerInstance/SignIn"
$ServiceLocation = (get-itemproperty -path HKLM:\SYSTEM\CurrentControlSet\Services\MicrosoftDynamicsNAVServer`$$serverinstance).ImagePath
if ($Servicelocation.indexof('"') -ge 0) {
$ServiceLocation = $ServiceLocation.split('"')[1]
}
$ServiceLocation = Split-path -path $ServiceLocation
if ([string]::IsNullOrWhitespace($ServiceLocation)) {
write-host "Could not locate $ServerInstance"
$ServerInstance = ""
read-host "Press enter to quit script"
return
}
Import-Module -name "$ServiceLocation\navadmintool.ps1"
Set-NAVServerConfiguration -ServerInstance $ServerInstance -KeyName ValidAudiences -KeyValue $ApplicationID
Set-NAVServerConfiguration -ServerInstance $ServerInstance -KeyName ClientServicesFederationMetadataLocation -KeyValue "https://login.microsoftonline.com/$TenantID/FederationMetadata/2007-06/FederationMetadata.xml" # BC20, BC21
Set-NAVServerConfiguration -ServerInstance $ServerInstance -KeyName ADOpenIDMetadataLocation -KeyValue "https://login.microsoftonline.com/$TenantID/.well-known/openid-configuration" # BC22
Set-NAVServerConfiguration -ServerInstance $ServerInstance -KeyName AppIdUri -KeyValue $AppID
Set-NAVServerConfiguration -ServerInstance $ServerInstance -KeyName ClientServicesCredentialType -KeyValue $AuthenticationType
Set-NAVServerConfiguration -ServerInstance $ServerInstance -KeyName WSFederationLoginEndpoint -keyvalue $WSFederationEndpoint
Set-NavServerConfiguration -ServerInstance $ServerInstance -KeyName AzureActiveDirectoryClientId -KeyValue "00000000-0000-0000-0000-000000000000"
Set-NavServerConfiguration -ServerInstance $ServerInstance -KeyName ServicesCertificateThumbprint -KeyValue $CertificateThumbPrint
Set-NavServerConfiguration -ServerInstance $ServerInstance -KeyName PublicWebBaseURL -KeyValue "https://$WebURLBase/$ServerInstance/"
<#OPTIONAL
Set-NavServerConfiguration -ServerInstance $ServerInstance -keyname ODataServicesPort -keyvalue $OdataPort
Set-NavServerConfiguration -ServerInstance $ServerInstance -keyname ODataServicesSSLEnabled -KeyValue True
Set-NavServerConfiguration -ServerInstance $ServerInstance -keyname SOAPServicesPort -keyvalue $SOAPPort
Set-NavServerConfiguration -ServerInstance $ServerInstance -keyname SOAPServicesSSLEnabled -KeyValue True
Set-NavServerConfiguration -ServerInstance $ServerInstance -keyName PublicOdataBaseURL -KeyValue $OdataBaseURL
Set-NavServerConfiguration -ServerInstance $ServerInstance -KeyName PublicSOAPBaseURL -KeyValue $SoapBaseURL
Set-NAVServerConfiguration -ServerInstance $ServerInstance -KeyName ApiServicesEnabled -KeyValue true
Set-NAVServerConfiguration -ServerInstance $ServerInstance -KeyName DeveloperServicesPort -KeyValue 7049
Set-NAVServerConfiguration -ServerInstance $ServerInstance -KeyName DeveloperServicesEnabled -KeyValue True
Set-NAVServerConfiguration -ServerInstance $ServerInstance -KeyName DeveloperServicesSSLEnabled -KeyValue True
#>
$ClientServicesPort=Get-NavServerConfiguration -ServerInstance $ServerInstance -keyName ClientServicesPort
Set-NAVWebServerInstanceConfiguration -WebServerInstance $ServerInstance -KeyName ClientServicesCredentialType -KeyValue $AuthenticationType
Set-NAVWebServerInstanceConfiguration -WebServerInstance $ServerInstance -KeyName AadApplicationId -KeyValue $ApplicationID
Set-NAVWebServerInstanceConfiguration -WebServerInstance $ServerInstance -KeyName AadAuthorityUri -KeyValue "https://login.microsoftonline.com/$TenantID"
Set-NAVWebServerInstanceConfiguration -WebServerInstance $ServerInstance -KeyName ClientServicesPort -KeyValue $ClientServicesPort
Restart-NAVServerInstance -ServerInstance $ServerInstance