如何配置Azure AD访问令牌的过期时间(使用ADAL)? [英] How can I configure the expiration time of an Azure AD access token (using ADAL)?

查看:461
本文介绍了如何配置Azure AD访问令牌的过期时间(使用ADAL)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用Azure AD通过其Office 365帐户将用户身份验证到我们的WPF应用程序中。这是使用Active Directory身份验证库(ADAL)完成的。

We use Azure AD to authenticate users into our WPF application, using their Office 365 accounts. This is done using the Active Directory Authentication Library (ADAL).

当前,每次打开应用程序时,系统都会提示他们登录。我们要更改此设置,以允许通过缓存的令牌登录到应用程序。这可行,但是我们希望将令牌的到期时间缩短到24小时或更短,需要在该时间过后再次登录。

Currently, they are prompted to log in every time they open the app. We want to change this to allow logging in to the app via a cached token. This works but we want to shorten the expiration time of the token to 24 hours or less, requiring another sign in after that time has passed.

我看不到一种方法来操纵代码中访问令牌的过期。这是否需要在Azure AD中完成?

I don't see a way to manipulate the expiration of an Access Token in code. Is this something that needs to be done within Azure AD?

推荐答案

摘要



您不能使用ADAL来配置令牌的到期时间。 ADAL是一个身份验证库,可以帮助您与令牌服务进行交互,但是您可以 在服务主体,应用程序或租户上设置令牌生存期配置。

Summary

You cannot use ADAL to configure the expiration time of tokens. ADAL is an authentication library that helps you interact with the token service, but you can set the token lifetime configuration on your Service Principal, Application, or Tenant.

您需要使用Powershell创建描述所需行为的策略,并将其链接到服务主体,租户或应用程序。请注意,如果您要构建多租户应用,则租户所有者可以覆盖您的政策。

You'll need to use Powershell to create a policy describing the behavior you want, and link it to your service principal, tenant, or application. Keep in mind, if you're building a multi-tenant app, the owner of the tenant can overwrite your policy.

tl; dr: 不要依赖应用程序中的令牌生存期,因为它可以随时更改时间。

tl;dr: Don't rely on the token lifetime in your app as it can change at any time.

您可以使用 Azure AD Powershell命令。然后运行以下命令来设置访问令牌的生存期:

You can set these properties using Azure AD Powershell Commands. Then run the following commands to set an access token lifetime:


  1. 登录到Powershell。

Connect-AzureAD-确认


  1. 创建一个新策略,将访问令牌的生存期设置为2小时。您可以将其更改为10分钟到1天。

New-AzureADPolicy-定义@(' { TokenLifetimePolicy:{ Version:1, AccessTokenLifetime: 02:00:00, MaxAgeSessionSingleFactor: 02:00:00}}')-DisplayName WebPolicyScenario -IsOrganizationDefault $ false -Type TokenLifetimePolicy


  1. 获取策略的ObjectId。

Get-AzureAdPolicy


  1. 将新策略链接到您的应用程序。您可以使用 GraphExplorer 获取应用的objectId。

  1. Link the new policy to your application. You can get the objectId of your app using the GraphExplorer.

Add-AzureADApplicationPolicy -Id<应用程序的ObjectId> -RefObjectId<策略的ObjectId>

有关更多示例和完整文档,请查看 Azure AD可配置令牌有效期

For more examples and the full documentation, check out Azure AD Configurable Token Lifetime.

这篇关于如何配置Azure AD访问令牌的过期时间(使用ADAL)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆