我正在开发bot框架技术,在我的一个项目中,我想在我的LoginController.cs中使用服务Url或Microsoft凭据创建状态客户端对象
这是我在LoginController.cs中编写的代码,它在bot模拟器中工作,但在发布我的机器人并将其添加到skype之后它就无法正常工作。
//[HttpGet, Route("api/{userid}/authorize")]
[HttpGet, Route("api/{userid}/token")]
public async System.Threading.Tasks.Task<HttpResponseMessage> Authorize(string userid, string code)
{
AuthenticationContext ac = new AuthenticationContext("https://login.windows.net/common/oauth2/token/");
ClientCredential cc = new ClientCredential(Constants.Constants.ADClientId, Constants.Constants.ADClientSecret);
AuthenticationResult ar = await ac.AcquireTokenByAuthorizationCodeAsync(code, new Uri(Constants.Constants.apiBasePath + userid + "/token"), cc, "https://api.office.com/discovery/");
if (!String.IsNullOrEmpty(ar.AccessToken))
{
// var stateClient = new StateClient(new Uri("http://localhost:9000/"));
// var stateClient = new StateClient(new Uri("http://skype.botframework.com/"));
//var microsoftAppCredentials = new MicrosoftAppCredentials(appId: "ace15a7e-b7f6-4776-a6a3-a58c0314bd01", password: "X7BS9hJt0skSBu6z9kgW1FB");
//var stateClient = new StateClient(new Uri("http://skype.botframework.com/"),microsoftAppCredentials,addJwtTokenRefresher:true);
//var stateClient = new StateClient(microsoftAppCredentials);
var stateClient = new StateClient(new Uri("https://apis.skype.com/"));
//var stateClient = new StateClient(new Uri("https://api.slack.com/"));
if (stateClient != null)
{
var userId = userid.Replace("-", ":");
var getData = await stateClient.BotState.GetUserDataAsync(Constants.Constants.botId, userid);
//var getData = await client.B.GetUserDataAsync(Constants.Constants.botId, userid);
getData.Data = ar.Serialize();
getData.ETag = "*";
var foo = await stateClient.BotState.SetUserDataAsync(Constants.Constants.botId, userid, getData);
//var foo = await client.Bots.SetUserDataAsync(Constants.Constants.botId, userid, getData);
}
//return Request.CreateResponse(foo);
var response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = new Uri("/loggedin.html", UriKind.Relative);
return response;
}
else
return Request.CreateResponse(HttpStatusCode.Unauthorized);
}
请告诉我们如何解决上述问题。
-Pradeep
答案 0 :(得分:1)
状态客户端服务的URL如下,与通道无关。
this.BaseUri = new Uri("https://state.botframework.com");
答案 1 :(得分:0)
尝试使用helper方法创建stateclient:
StateClient stateClient = activity.GetStateClient();