如何通过客户端应用而不是资源来控制令牌生存期? [英] How to control token lifetime by client app instead of resource?

查看:79
本文介绍了如何通过客户端应用而不是资源来控制令牌生存期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用Azure AD调用多个资源的SPA应用程序。

我到达了以下文档以获得一个应用程序调用多个资源:

https://docs.microsoft.com/en-us/previous-versions/azure/dn645538(v = azure.100)

我正在使用带pkce的授权代码来获取初始令牌,然后使用刷新来获取其他的。

主要问题是我不习惯在SPA应用程序中存储长时间的refresh_token 。虽然我可以使用refresh_token来获取我想要的令牌然后丢弃它,但我认为对于治理决策是不利的,将此责任留给SPA应用程序

因此,我寻找自定义令牌生命周期的方法,并达到:

https://docs.microsoft.com/en-US/azure/active-directory/develop/active-directory-configurable-token-lifetimes

这里的问题是配置是按资源而不是客户端应用程序。

想象一下,我有一个SPA,一个机密客户端和两个都可以访问的不同资源。

对我来说有意义的是,为client1提供的令牌将比为client2提供的令牌更频繁地到期。列出的文档说明如何在资源级别上独立于客户端。

如果有人可以提供帮助以下问题我很高兴:

有没有办法在客户端应用程序级别上执行此操作?

是否可以阻止refresh_tokens生成新的refresh_tokens?

在某些页面中令牌生命周期配置的文档有一个警告说它即将改变。有约会吗?是否有任何预览或发行说明,看看会发生什么变化?

推荐答案

嗨  eduardojandre,

Hi eduardojandre,

我研究过这个问题。正如您所提到的,您正在使用PKCE流获取访问令牌,然后使用刷新令牌获取另一个访问令牌。我同意刷新令牌是长寿的。这意味着当客户从
a服务器获得一个时,必须安全地存储此令牌以防止其被潜在攻击者使用,因此,将它们存储在浏览器中是不安全的。 

I have researched on this query. As you have mentioned that you are using PKCE flow to get the access token and then using refresh token to get another access token. I agree that Refresh Tokens are long-lived. This means when a client gets one from a server, this token must be stored securely to keep it from being used by potential attackers, for this reason, it is not safe to store them in the browser. 

您可以尝试以下方法:

要获取刷新令牌,您需要将范围作为" offline_access "传递给。因为offline_access范围可以让您的应用代表用户长时间访问资源。尽量不要使用"Offline_access"范围,
在这种情况下,您将只获得访问令牌。

To get the refresh token, you need to pass scope as "offline_access". Because the offline_access scope gives your app access to resources on behalf of the user for an extended time. Try not to use "Offline_access" scope, in that case you will get only access token.

对于令牌生存期:正如您已经提到的关于链接(可配置令牌生存期) )。截至目前,令牌生存期仅针对服务主体设置,无法为客户端应用程序级别执行此操作。 

根据文档,团队计划用新的替换此功能
中的功能 Azure Active Directory条件访问。新功能完成后,"可配置令牌生命周期政策"功能最终将在通知期后弃用。

For token lifetime: As you have already mentioned about the link (Configurable token lifetimes). As of now token lifetime is set only for service principals, there is no way to do this for client application level. 
As per the document, the team is planning to replace this functionality with a new feature in Azure Active Directory Conditional Access. Once the new feature is complete, "Configurable Token Lifetime policy" functionality will eventually be deprecated after a notification period.

希望信息有用。

谢谢。


这篇关于如何通过客户端应用而不是资源来控制令牌生存期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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