我正在使用 ASP.NET 4.8,针对 Azure AD 实施 OpenID 身份验证,并连续配置对 Power BI API 的访问。 此处描述了该方案< /a>.我不明白的是这在网络农场中是如何工作的。
以下是我对单个服务器上的步骤的理解:
-
用户使用 OpenID 针对 Azure AD 进行身份验证并接收授权代码
此授权代码由 ConfidentialClientApplication 在对 AcquireTokenByAuthorizationCode 的调用中使用,以获取存储在令牌缓存中的 AccessToken。
-
稍后,当用户需要访问某些 API 时,将从令牌缓存中检索 AccessToken。如果 AccessToken 已过期或不存在,ConfidentialClientApplication 可以访问 RefreshToken 以获取新的 AccessToken。
我想我不明白这在多服务器场景中是如何工作的。如果网络场中的节点 A 执行了上述步骤并包含访问令牌和刷新令牌,那么当没有这些令牌的节点 B 处理请求时会发生什么情况?有没有办法从 cookie 中获取刷新令牌,以便在节点 B 上请求新的访问令牌?
感谢您的帮助!
I am using ASP.NET 4.8, implementing OpenID auth against Azure AD, and consecutive provisioning of access to Power BI APIs. The scenario is described here. What I don't understand is how this works in a web farm.
Here is how I understand the steps on a single server:
-
A user authenticates using OpenID against Azure AD and receives an authorization code
-
This authorization code is used by ConfidentialClientApplication in a call to AcquireTokenByAuthorizationCode to get an AccessToken that is stored in a token cache.
-
Later, when a user needs to access some API, the AccessToken is retrieved from the token cache. If the AccessToken is expired or is not there, the ConfidentialClientApplication has access to the RefreshToken to get a new AccessToken.
I guess I don't understand how this works in a multi-server scenario. If node A in a web farm went through the steps above and contains the access and refresh tokens, what happens when a request is served by node B that has none of these tokens? Is there a way to get a hold of the refresh token from a cookie in order to request a new access token on node B?
Thank you for your help!
发布评论
评论(1)
您应该使用分布式缓存。有关此信息的更多信息: https://learn.microsoft.com/en-us/azure/active-directory/develop/mmsal-net-net-token-cache-serialization?tabsition = aspnetcore#distribed-token-token-token-caches
注意:上面的链接不包含一个现成的示例,您将需要首先设置任何类型的真实分布式缓存(SQL,Radis,ncache):https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed
You should use the distributed cache. More about this here: https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-net-token-cache-serialization?tabs=aspnetcore#distributed-token-caches
Note: link above contains not a ready-to-use example, you will need to setup any kind of real distributed cache first (SQL, Radis, NCache): https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed