例如,我通过访问 blob 存储
from azure.identity import ClientSecretCredential
token_credential = ClientSecretCredential(
"", # tenant id
"", # application id
"" # application secret
)
from azure.storage.blob import BlobServiceClient
blob_service_client = BlobServiceClient(account_url=url, credential=token_credential)
但是默认 token ttl 是 60-90 分钟,是否可以将其增加到一天?
最佳答案
is it possible to increase that to one day?
是的,可以通过执行以下步骤来延长访问/ID token 的过期时间:
运行
Connect
命令,使用以下 powershell cmdlet 登录到您的 Azure AD 帐户:Connect-AzureAD -Confirm
接下来,您应该使用以下 cmdlet 创建 token 生命周期策略:
$policy = New-AzureADPolicy -Definition @('{"TokenLifetimePolicy":{"Version":1,"AccessTokenLifetime":"24:00:00"}}') -DisplayName "WebPolicyScenario" -IsOrganizationDefault $false -Type "TokenLifetimePolicy" ``
要检查在上述步骤中创建的策略并获取其 ObjectId,请使用以下 cmdlet:
Get-AzureADPolicy -Id $policy.Id
现在将创建的策略添加到您的服务主体中。还可以使用以下 cmdlet 获取服务主体的 ObjectId:
$sp = Get-AzureADServicePrincipal -Filter "DisplayName eq ' <service principal display name>' "
- 最后,运行以下 cmdlet 将策略设置为您的服务原则:
Add-AzureADServicePrincipalPolicy -Id $sp.ObjectId -RefObjectId $policy.Id
关于python - 如何增加azure oauth token 的过期时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73157005/