New-SPTrustedSecurityTokenIssuer

add-pssnapin microsoft.sharepoint.powershell
$TargetSiteUrl = "http://srv2016.dev2016.local/" #adres witryny z włączonym SideLoading
$CertPath = "C:\cert.cer" #podaj poprawną ścieżkę do Twojego pliku CER 
Set-SPAppDomain "apps.local" #dostosuj tą wartość
$account = Get-SPManagedAccount "dev2016\spfarm" #użyj swojego konta zarządzanego
$issuerId = "447f40c6-99df-4d37-9739-5370102489f7" #możesz zmienić tą wartość na dowolny poprawny guid zapisany lowercase
$sPAppSiteSubscriptionName = "app"  #możesz zmienić tą wartość na dowolną
net start SPAdminV4
net start SPTimerV4
Get-SPServiceInstance | where{$_.GetType().Name -eq "AppManagementServiceInstance" -or $_.GetType().Name -eq "SPSubscriptionSettingsServiceInstance"} | Start-SPServiceInstance
Get-SPServiceInstance | where{$_.GetType().Name -eq "AppManagementServiceInstance" -or $_.GetType().Name -eq "SPSubscriptionSettingsServiceInstance"}
$spweb = Get-SPWeb $TargetSiteUrl
$realm = Get-SPAuthenticationRealm -ServiceContext $spweb.Site
$fullAppIdentifier = $issuerId + '@' + $realm
$certificate = Get-PfxCertificate $CertPath

Get-SPTrustedSecurityTokenIssuer | Remove-SPTrustedSecurityTokenIssuer

New-SPTrustedSecurityTokenIssuer -Name $issuerId -Certificate $certificate -RegisteredIssuerName $fullAppIdentifier –IsTrustBroker
$serviceConfig = Get-SPSecurityTokenServiceConfig
$serviceConfig.AllowOAuthOverHttp = $true
$serviceConfig.Update()