简体   繁体   English

Sharepoint Provider托管的应用程序:无效的JWT令牌。 令牌已过期

[英]Sharepoint Provider Hosted App: Invalid JWT Token. The token is expired

I get the following error randomly when I work in my app: 当我在应用程序中工作时,随机出现以下错误:

Invalid JWT token. 无效的JWT令牌。 The token is expired. 令牌已过期。

[SecurityTokenExpiredException: Invalid JWT token. [SecurityTokenExpiredException:无效的JWT令牌。 The token is expired.] 令牌已过期。]
Microsoft.IdentityModel.S2S.Tokens.JsonWebSecurityTokenHandler.ValidateLifetime(JsonWebSecurityToken token) +296 Microsoft.IdentityModel.S2S.Tokens.JsonWebSecurityTokenHandler.ValidateLifetime(JsonWebSecurityToken令牌)+296
Microsoft.IdentityModel.S2S.Tokens.JsonWebSecurityTokenHandler.ValidateTokenCore(SecurityToken token, Boolean isActorToken) +162 Microsoft.IdentityModel.S2S.Tokens.JsonWebSecurityTokenHandler.ValidateTokenCore(SecurityToken token,Boolean isActorToken)+162
EventsWeb.TokenHelper.ReadAndValidateContextToken(String contextTokenString, String appHostName) in C:\\APP\\TokenHelper.cs:120 C:\\ APP \\ TokenHelper.cs:120中的EventsWeb.TokenHelper.ReadAndValidateContextToken(String contextTokenString,String appHostName)
EventsWeb.TokenHelper.GetClientContextWithContextToken(String targetUrl, String contextTokenString, String appHostUrl) in C:\\APP\\TokenHelper.cs:465 C:\\ APP \\ TokenHelper.cs:465中的EventsWeb.TokenHelper.GetClientContextWithContextToken(String targetUrl,String contextTokenString,String appHostUrl)
EventsWeb.Pages.User.tmpl.index.GetHostWebClientContext() in C:\\APP\\Pages\\User\\tmpl\\index.aspx.cs:90 C:\\ APP \\ Pages \\ User \\ tmpl \\ index.aspx.cs:90中的EventsWeb.Pages.User.tmpl.index.GetHostWebClientContext()
EventsWeb.Pages.User.tmpl.index.OnPreRender(EventArgs e) in C:\\APP\\Pages\\User\\tmpl\\index.aspx.cs:69 C:\\ APP \\ Pages \\ User \\ tmpl \\ index.aspx.cs中的EventsWeb.Pages.User.tmpl.index.OnPreRender(EventArgs e):69
System.Web.UI.Control.PreRenderRecursiveInternal() +107 System.Web.UI.Control.PreRenderRecursiveInternal()+107
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7675 System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)+7675

There is no way except of restarting the Internet Explorer to solve this issue. 除了重新启动Internet Explorer来解决此问题外,没有其他方法。 I have this in some applications. 我在某些应用程序中有此功能。 The ClientId and ClientSecret is valid, otherwise the restart of IE won't be able to solve this problem. ClientId和ClientSecret有效,否则重新启动IE将无法解决此问题。

The time when this message occurs differs. 出现此消息的时间不同。 Sometimes after 1hour sometimes after 5... 有时在1小时后有时在5小时后...

I don't know why the token is getting invalid due the working in this app. 我不知道为什么令牌会由于在此应用程序中工作而变得无效。 But thats not userfriendly... 但这不是用户友好的...

Any idea about this? 有什么想法吗?

Thanks 谢谢

The below two scenarios can cause token expire: 以下两种情况可能导致令牌过期:

  1. Users have long running sessions with your add-in in which the add-in makes calls to SharePoint many hours (currently more than 12) after it is launched. 用户与您的外接程序具有长时间运行的会话,其中,外接程序在启动后许多小时(当前超过12个)调用SharePoint。
  2. The add-in's design enables users to schedule the add-in to access SharePoint sometime after the session ends. 外接程序的设计使用户可以安排外接程序在会话结束后的某个时间访问SharePoint。

You could use the refresh token to obtain another access token from ACS in your code .The refresh token lasts a few months and can be persisted in a cookie or in server-side storage. 您可以使用刷新令牌从代码中的ACS获取另一个访问令牌。刷新令牌可持续数月,可以保存在cookie或服务器端存储中。 Try to use SharePointContext helper class , it could renew the access token if it is not valid automatically . 尝试使用SharePointContext帮助程序类,如果该访问令牌自动无效,则它可以续订访问令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM