Calendar o365日历API未返回日历
我按照中提供的说明将我的web应用程序与用户的outlook日历集成。我被重定向到我的microsoft帐户,它返回到我的返回url,并填充代码参数。然而,当我试图从代码中生成令牌时,它返回空的,没有任何错误 有人能给点建议吗 以下代码用于从代码生成令牌:Calendar o365日历API未返回日历,calendar,outlook,office365,office365-apps,office365api,Calendar,Outlook,Office365,Office365 Apps,Office365api,我按照中提供的说明将我的web应用程序与用户的outlook日历集成。我被重定向到我的microsoft帐户,它返回到我的返回url,并填充代码参数。然而,当我试图从代码中生成令牌时,它返回空的,没有任何错误 有人能给点建议吗 以下代码用于从代码生成令牌: // Note the function signature is changed! public async Task<ActionResult> Authorize()
// Note the function signature is changed!
public async Task<ActionResult> Authorize()
{
// Get the 'code' parameter from the Azure redirect
string authCode = Request.Params["code"];
string authority = "https://login.microsoftonline.com/common";
string clientId = System.Configuration.ConfigurationManager.AppSettings["ida:ClientID"];
string clientSecret = System.Configuration.ConfigurationManager.AppSettings["ida:ClientSecret"];
AuthenticationContext authContext = new AuthenticationContext(authority);
// The same url we specified in the auth code request
Uri redirectUri = new Uri(Url.Action("Authorize", "Home", null, Request.Url.Scheme));
// Use client ID and secret to establish app identity
ClientCredential credential = new ClientCredential(clientId, clientSecret);
try
{
// Get the token
var authResult = await authContext.AcquireTokenByAuthorizationCodeAsync(
authCode, redirectUri, credential, scopes);
// Save the token in the session
Session["access_token"] = authResult.Token;
// Try to get user info
Session["user_email"] = GetUserEmail(authContext, clientId);
return Content("Access Token: " + authResult.Token);
}
catch (AdalException ex)
{
return Content(string.Format("ERROR retrieving token: {0}", ex.Message));
}
}
//注意函数签名已更改!
公共异步任务授权()
{
//从Azure重定向获取“code”参数
字符串authCode=Request.Params[“code”];
字符串权限=”https://login.microsoftonline.com/common";
字符串clientId=System.Configuration.ConfigurationManager.AppSettings[“ida:clientId”];
字符串clientSecret=System.Configuration.ConfigurationManager.AppSettings[“ida:clientSecret”];
AuthenticationContext authContext=新的AuthenticationContext(授权);
//与我们在身份验证代码请求中指定的url相同
Uri redirectUri=新的Uri(Url.Action(“Authorize”、“Home”、null、Request.Url.Scheme));
//使用客户端ID和密码建立应用程序标识
ClientCredential=新的ClientCredential(clientId,clientSecret);
尝试
{
//拿到代币
var authResult=等待authContext.AcquireTokenByAuthorizationCodeAsync(
authCode、重定向URI、凭据、作用域);
//在会话中保存令牌
会话[“访问令牌”]=authResult.token;
//尝试获取用户信息
会话[“用户电子邮件”]=GetUserEmail(authContext,clientId);
返回内容(“访问令牌:+authResult.Token”);
}
捕获(ADALEX)
{
返回内容(string.Format(“检索令牌时出错:{0}”,例如Message));
}
}
是指向我的应用程序的链接,如果您想尝试。单击位于左中角的“链接O365日历”链接在此处查看网络跟踪会很有帮助。Jason,请尝试查看我无法找到原因,但当我使用Visual Studio扩展添加连接服务时,一切都进行得很顺利。我试图手动注册应用程序和步骤,但没有帮助。我现在正在工作。