【发布时间】:2016-05-20 00:48:54
【问题描述】:
所以我正在尝试为我们的办公室身份验证实现持久令牌,这样用户就不必在每次进入新会话时都登录办公室。我目前必须验证用户的代码如下。
string authority = "https://login.microsoftonline.com/common";
var tokenCache = new ADALTokenCache(User.Identity.GetUserId());
AuthenticationContext authContext = new AuthenticationContext(authority, tokenCache );
var token = authContext.AcquireTokenSilentAsync(scopes, clientId, new UserIdentifier(userId, UserIdentifierType.RequiredDisplayableId));
例外是:"Failed to acquire token silently. Call method AcquireToken"
我首先获取token的方法如下
string authority = "https://login.microsoftonline.com/common";
var fileCache = new ADALTokenCache(User.Identity.GetUserId());
AuthenticationContext authContext = new AuthenticationContext(authority, fileCache);
var authResult = await authContext.AcquireTokenByAuthorizationCodeAsync(
authCode, redirectUri, credential, scopes);
我使用的令牌缓存是一个数据库实现,它是我从一个我再也找不到的教程制作的,如果我看数据库,我可以看到当AcquireTokenByAuthorizationCodeAsync 被调用时,新的令牌被插入到数据库中。
更新:
这是我在调用AcquireTokenByAuthorizationCodeAsync 时从 authResult 得到的结果
我已将 Virbonet 的答案标记为解决方案,但我没有修复它,但他确实向我解释了我哪里出错了
【问题讨论】:
-
您从哪里获得 authCode?span>
标签: c# asp.net office365 adal office365api