首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获得带有adal角包adal.js身份验证上下文的Microsoft

获得带有adal角包adal.js身份验证上下文的Microsoft
EN

Stack Overflow用户
提问于 2021-10-08 09:16:00
回答 1查看 139关注 0票数 0

我正在尝试使用使用authenticationContext创建的'adal-angular/lib/adal.js' package来获取microsoft graph资源的令牌。

错误:

需要

用户登录。此时console.log(:error在这里)

依赖关系:

代码语言:javascript
复制
"adal-angular": "^1.0.18",
"vue": "^2.6.12",
"vue-adal": "^1.3",

代码:

代码语言:javascript
复制
initialize() {
  this.authenticationContext = new AuthenticationContext(config);
  return new Promise((resolve, reject) => {
    if (this.authenticationContext.isCallback(window.location.hash) || window.self !== window.top) {
        this.authenticationContext.handleWindowCallback();
        this.graphToken(this.authenticationContext);
        let user = this.authenticationContext.getCachedUser();
        resolve(user);
     } else {
        let user = this.authenticationContext.getCachedUser();
        if (user) {
          resolve(user);
        } else {
          this.signIn();
        }
     }
   });
  }

graphToken(authctx) {
  authctx.acquireToken('https://graph.microsoft.com', function (error, token) {
    console.log(error + ":::error is here");
    console.log(token + "graph token");
  })  
}
EN

回答 1

Stack Overflow用户

发布于 2022-01-13 13:11:40

代码语言:javascript
复制
  initialize() {
this.authenticationContext = new AuthenticationContext(config);

return new Promise((resolve, reject) => {
  if (this.authenticationContext.isCallback(window.location.hash) || window.self !== window.top) {
    // redirect to the location specified in the url params.
    this.authenticationContext.handleWindowCallback();
  }
  // try pull the user out of local storage
  let user = this.authenticationContext.getCachedUser();
  // get token
  auth.acquireToken(accessTokenRequest.scopes).then((accessToken)=> {
    if (user) {
      user.token_access_graph = accessToken;
      resolve(user);
    } else {
      this.signIn();
    }
  }).catch(error => {
    console.log('acquireToken error', error);
  })
});

},

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69493398

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档