小编Ben*_*Ben的帖子

令牌刷新因 invalid_client 错误而失败

我有一个由应用程序 A 颁发的刷新令牌。此刷新令牌存储在应用程序 B 有权访问的 Azure Key Vault 中。应用程序 B 现在获取此刷新令牌并将其交换为访问令牌。

不幸的是,此交换失败并显示消息

"error": "invalid_client",
"error_description": "AADSTS7000215: Invalid client secret is provided."
Run Code Online (Sandbox Code Playgroud)

不过,客户端密码是正确的。我能够使用它获得 Key Vault 的访问令牌。

这是从 Fiddler 获取的刷新令牌交换的 HTTP 请求(我已删除所有机密和 ID):

POST https://login.microsoftonline.com/{TenantId}/oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US)  WindowsPowerShell/5.1.17763.134
Host: login.microsoftonline.com
Content-Length: 1221
Connection: Keep-Alive

grant_type=refresh_token
&client_id={ClientId}
&client_secret={ClientSecret}
&resource=https%3A%2F%2Fvault.azure.net
&redirect_uri=https%3A%2F%2Flocalhost%2F
&refresh_token={RefreshToken}
Run Code Online (Sandbox Code Playgroud)

这是怎么回事?

PS:我知道在 Key Vault 中存储刷新令牌是很疯狂的,但这是 Microsoft 推荐的访问 CSP 合作伙伴 API 的方式。

azure-active-directory

5
推荐指数
1
解决办法
8490
查看次数

PowerShell 功能和性能

我一直想知道 PowerShell 中函数对性能的影响。假设我们想使用 System.Random 生成 100.000 个随机数。

$ranGen = New-Object System.Random
Run Code Online (Sandbox Code Playgroud)

执行

for ($i = 0; $i -lt 100000; $i++) {
    $void = $ranGen.Next()
}
Run Code Online (Sandbox Code Playgroud)

在 0.19 秒内完成。我把调用放在一个函数中

Get-RandomNumber {
    param( $ranGen )

    $ranGen.Next()
}
Run Code Online (Sandbox Code Playgroud)

执行

for ($i = 0; $i -lt 100000; $i++) {
    $void = Get-RandomNumber $ranGen
}
Run Code Online (Sandbox Code Playgroud)

大约需要 4 秒。

为什么会有如此巨大的性能影响?

有没有办法可以在使用函数的同时获得直接调用的性能?

PowerShell 中是否有更好(更高效)的代码封装方式?

powershell

3
推荐指数
1
解决办法
285
查看次数

标签 统计

azure-active-directory ×1

powershell ×1