Azure 通信服务聊天-刷新令牌不工作
我已经下载了azure通信聊天服务,并按照视频中显示的方式开始工作 但他们的问题是。。我如何克服令牌过期。。它一直在使treadID过期,我不能再聊下去了 我提到了RefreshToken,尽管它并不令人耳目一新。下面是我所做更改的代码Azure 通信服务聊天-刷新令牌不工作,azure,chat,refresh-token,azure-communication-services,Azure,Chat,Refresh Token,Azure Communication Services,我已经下载了azure通信聊天服务,并按照视频中显示的方式开始工作 但他们的问题是。。我如何克服令牌过期。。它一直在使treadID过期,我不能再聊下去了 我提到了RefreshToken,尽管它并不令人耳目一新。下面是我所做更改的代码 var userCredential = new CommunicationUserCredential ( initialToken: moderator.token,
var userCredential = new CommunicationUserCredential
(
initialToken: moderator.token,
refreshProactively: true,
tokenRefresher: cancellationToken => fetchNewTokenForCurrentUser(moderator.identity).GetAwaiter().GetResult(),
asyncTokenRefresher: cancellationToken => fetchNewTokenForCurrentUserasync(moderator.identity)
);
fetchNewTokenForCurrentUser方法如下所示
private async Task<string> fetchNewTokenForCurrentUser( string identity)
{
CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClient(resourceConnectionString);
CommunicationUser user = new CommunicationUser(identity);
Azure.Response<CommunicationUserToken> tokenResponse = await communicationIdentityClient.IssueTokenAsync
(
user,
scopes: new[] { CommunicationTokenScope.Chat }
);
string token = tokenResponse.Value.Token;
return token;
}
private异步任务fetchNewTokenForCurrentUser(字符串标识)
{
通讯身份客户端通讯身份客户端=新通讯身份客户端(resourceConnectionString);
通信用户用户=新的通信用户(标识);
Azure.Response-tokenResponse=await communicationIdentityClient.IssueTokenAsync
(
用户,
作用域:新建[]{CommunicationTokenScope.Chat}
);
字符串标记=tokenResponse.Value.token;
返回令牌;
}
但是这个代码不起作用。。
希望有人能帮助我。。提前感谢我们正在研究您报告的这个问题,需要进一步的详细信息。生成的代币应该持续24小时
- 这个问题是发生在您的本地设备上,还是将演示作为web应用程序部署在azure中
- 当你提到“它继续使treadID过期”时,你到底看到了哪一个错误
- 你有任何我们可以查看的错误跟踪吗
- 您能否捕获fiddler会话(如果问题可在本地重现?)
const string initialToken = "your-initial-token";
Uri apiUrl = new Uri("https://yourendpoint.dev.communication.azure.net");
const string identity = "your user id"; //i.e. 8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000006-6224-f48d-b274-5aaaaaaaaaaa";
var communicationUserCredential = new CommunicationUserCredential(
initialToken: initialToken,
refreshProactively: true,
tokenRefresher: cancellationToken => fetchNewTokenForCurrentUser(identity).GetAwaiter().GetResult(),
asyncTokenRefresher: cancellationToken => fetchNewTokenForCurrentUser(identity));
var chatClient = new ChatClient(apiUrl, communicationUserCredential);
//For the refresher logic. Note ValueTask vs Task
private async ValueTask<string> fetchNewTokenForCurrentUser(string identity)
{
const string connectionString = "your connection string";
CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClient(connectionString);
CommunicationUser user = new CommunicationUser(identity);
Azure.Response<CommunicationUserToken> tokenResponse = await communicationIdentityClient.IssueTokenAsync
(
user,
scopes: new[] { CommunicationTokenScope.Chat }
);
string token = tokenResponse.Value.Token;
return token;
}
const string initialToken=“您的初始令牌”;
Uri apiUrl=新Uri(“https://yourendpoint.dev.communication.azure.net");
const string identity=“您的用户id”//i、 e.8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000006-6224-f48d-b274-5AAAAA”;
var communicationUserCredential=新的communicationUserCredential(
initialToken:initialToken,
答:对,,
TokenRefresh:cancellationToken=>fetchNewTokenForCurrentUser(identity).GetAwaiter().GetResult(),
AsyncTokenRefresh:cancellationToken=>fetchNewTokenForCurrentUser(标识));
var chatClient=新的chatClient(APIRL、communicationUserCredential);
//对于刷新逻辑,请注意ValueTask vs Task
私有异步值任务fetchNewTokenForCurrentUser(字符串标识)
{
const string connectionString=“您的连接字符串”;
通讯身份客户端通讯身份客户端=新通讯身份客户端(connectionString);
通信用户用户=新的通信用户(标识);
Azure.Response-tokenResponse=await communicationIdentityClient.IssueTokenAsync
(
用户,
作用域:新建[]{CommunicationTokenScope.Chat}
);
字符串标记=tokenResponse.Value.token;
返回令牌;
}
一旦您有机会提供上述详细信息,我们将与您联系。
干杯我想你不仅需要更新版主令牌,还需要更新线程成员的令牌 例如,您有一个包含a、B、C和版主(这是用C#代码创建的)的线程。24小时后,所有用户的令牌都过期。如果a仍然希望查看历史消息并发送消息,则您需要续订a的令牌。同样的逻辑适用于其他用户 希望它能回答你的问题 我看到续订令牌pr也在等待中: