有没有一种方法可以使用oauth令牌连接到New-CsOnlineSession?

时间:2020-01-13 19:05:45

标签: powershell oauth azure-active-directory skype-for-business lync

我正在寻找一种使用oauth令牌从网络应用程序运行“ New-CsOnlineSession”的方法。 WebApp将负责对用户进行身份验证。这将使用Microsoft Modern Authentication,它将处理两个因素的身份验证和同意。

我已经在Azure门户中注册了一个应用,并授予了Skype For Business Powershell Server Application的用户模拟权限。

但是,当我连接使用WebApp获得的令牌时,却收到错误消息,指出使用了错误的受众。

下面是我的powershell会话的笔录。一旦我在Powershell中完成了此工作,其想法就是WebApp将执行powershell命令,因此在PowerShell提示输入凭据的情况下执行此操作的任何方式都将失效。

PS C:\WINDOWS\system32> $token = ConvertTo-SecureString -String $oauthtoken -AsPlainText -Force
PS C:\WINDOWS\system32> $session = New-CsOnlineSession -OAuthAccessToken $token -Verbose
VERBOSE: OAuthAccessToken is provided.
VERBOSE: Determining domain to administer
VERBOSE: AdminDomain = 'mydomain.onmicrosoft.com'
VERBOSE: Discovering PowerShell endpoint URI
VERBOSE: TargetUri = 'https://admin2e.online.lync.com/OcsPowershellOAuth'
VERBOSE: AuthUri = 'https://login.windows.net/common/oauth2/authorize', ClientId = 7716031e-6f8b-45a4-b82b-922b1af0fbb4
VERBOSE: Validating authentication token.
New-CsOnlineSession : OAuthAccessToken has invalid audience https://teamsconfigapi-int.trafficmanager.net, expected https://admin2e.online.lync.com/OcsPowershellOAuth.
At line:1 char:12
+ $session = New-CsOnlineSession -OAuthAccessToken $token -Verbose
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,New-CsOnlineSession

1 个答案:

答案 0 :(得分:0)

您可以尝试将-OverrideAccessTokenResourceUri设置为指定的URL。