首页 > 解决方案 > 为合作伙伴中心生成新的访问令牌

问题描述

大约 3 个月前,我创建了一个用于登录 Microsoft PartnerCenter 的令牌,该令牌现已过期,我需要创建一个新令牌,但我丢失了我使用的代码,并且按照文档中的说明操作时它不起作用。

我试图遵循文档中的示例 1:https ://docs.microsoft.com/en-us/powershell/module/partnercenter/new-partneraccesstoken?view=partnercenterps-3.0

但是让我感到困惑的是我应该在凭证对象中放入什么?是 AppID 和 App Secret 还是别的什么?

$TenantID = "MyTenant" #  Tenant
$ApplicationID = "MyAppID" # Application in Tenant "Partner Center"
$ApplictionSecret = "MyAPPSecreat" 

$credential = New-Object PSCredential ($ApplicationID, (ConvertTo-SecureString $ApplictionSecret -AsPlainText -Force))
$token = New-PartnerAccessToken -ApplicationId $ApplicationID -Scopes 'https://api.partnercenter.microsoft.com/user_impersonation' -ServicePrincipal -Credential $credential -Tenant $TenantID -UseAuthorizationCode

当我运行它时会发生什么,我最终进入一个永无止境的循环,我的网络浏览器打开并要求我登录,当我登录时它只是创建一个新选项卡,在 powershell 窗口中我收到警告并且端口号增加每次我这样做。

WARNING: Port 8400 is taken with exception 'Only one usage of each socket address (protocol/network address/port) is normally permitted'; trying to connect to the next port.
WARNING: Port 8401 is taken with exception 'Only one usage of each socket address (protocol/network address/port) is normally permitted'; trying to connect to the next port.
WARNING: Port 8402 is taken with exception 'Only one usage of each socket address (protocol/network address/port) is normally permitted'; trying to connect to the next port.
WARNING: Port 8403 is taken with exception 'Only one usage of each socket address (protocol/network address/port) is normally permitted'; trying to connect to the next port.
WARNING: Attempting to launch a browser for authorization code login.
WARNING: We have launched a browser for you to login. For the old experience with device code flow, please run 'New-PartnerAccessToken -UseDeviceAuthentication'.
WARNING: Port 8400 is taken with exception 'Only one usage of each socket address (protocol/network address/port) is normally permitted'; trying to connect to the next port.
WARNING: Port 8401 is taken with exception 'Only one usage of each socket address (protocol/network address/port) is normally permitted'; trying to connect to the next port.
WARNING: Port 8402 is taken with exception 'Only one usage of each socket address (protocol/network address/port) is normally permitted'; trying to connect to the next port.
WARNING: Port 8403 is taken with exception 'Only one usage of each socket address (protocol/network address/port) is normally permitted'; trying to connect to the next port.
WARNING: Port 8404 is taken with exception 'Only one usage of each socket address (protocol/network address/port) is normally permitted'; trying to connect to the next port.
WARNING: Attempting to launch a browser for authorization code login.
WARNING: We have launched a browser for you to login. For the old experience with device code flow, please run 'New-PartnerAccessToken -UseDeviceAuthentication'.
WARNING: Port 8400 is taken with exception 'Only one usage of each socket address (protocol/network address/port) is normally permitted'; trying to connect to the next port.
WARNING: Port 8401 is taken with exception 'Only one usage of each socket address (protocol/network address/port) is normally permitted'; trying to connect to the next port.
WARNING: Port 8402 is taken with exception 'Only one usage of each socket address (protocol/network address/port) is normally permitted'; trying to connect to the next port.
WARNING: Port 8403 is taken with exception 'Only one usage of each socket address (protocol/network address/port) is normally permitted'; trying to connect to the next port.
WARNING: Attempting to launch a browser for authorization code login.
WARNING: We have launched a browser for you to login. For the old experience with device code flow, please run 'New-PartnerAccessToken -UseDeviceAuthentication'.

不,在我运行命令之前,该端口上没有任何阻塞/监听。我尝试重新启动计算机并使用 netstat 验证端口上没有任何监听。

另请注意,当我设法让它工作时,我使用的应用程序与 3 个月前使用的应用程序相同,所以我怀疑它在那一侧的配置错误。它可能是我在代码中出了问题。

标签: azurepowershell

解决方案


所以这个问题的解决方案相当简单。

我只需要将默认浏览器更改为 Internet Explorer(来自 Chrome),然后它就可以工作了。似乎是某种错误。


推荐阅读