【发布时间】:2020-10-17 01:56:38
【问题描述】:
我会使用 react-adal api 获得缓存的令牌
import { authContext, } from '../auth'
const AvatarContainer = () => {
getPersonPhoto(authContext)
return (
<Avatar />
)
}
async function getPersonPhoto(authContext) {
const user = await authContext.getCachedUser();
const token = authContext.getCachedToken('https://graph.microsoft.com')
console.log("the token", token)
var photoUrl = "https://graph.microsoft.com/v1.0/users/" + user.profile.aud + "/photo/$value";
var Avatar = null;
// try {
// Avatar = await client
// .api(photoUrl)
// .get();
// return Avatar;
// } catch (e) { return null; }
}
export default AvatarContainer
令牌值始终为空,我指定了ressource uri,但它不起作用。
我检查了我的本地存储,我有令牌
【问题讨论】:
-
您能否提供您的 authContext` 代码,该代码可能应该从本地存储中获取令牌并将其提供给应用程序?
-
是 adal
AuthenticationContext类 github.com/AzureAD/azure-activedirectory-library-for-js/wiki/… 的一个实例 -
那么你确定你有一个有效的用户吗?你能验证
user也不为空吗? -
是的,我登录良好
标签: javascript reactjs adal adal.js