Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用图形OAuth v2.0刷新令牌_Javascript_Angular_Microsoft Graph Api_Hello.js - Fatal编程技术网

Javascript 使用图形OAuth v2.0刷新令牌

Javascript 使用图形OAuth v2.0刷新令牌,javascript,angular,microsoft-graph-api,hello.js,Javascript,Angular,Microsoft Graph Api,Hello.js,我正在通过Microsoft Graph请求用户的信息。我使用2.0端点 这是我的登录功能: login() { hello('msft').login({scope: Configs.scope}).then( () => { this.zone.run(() => { this.meService.getMe().subscribe(data => { localStorage.setIte

我正在通过Microsoft Graph请求用户的信息。我使用2.0端点

这是我的登录功能:

login() {
    hello('msft').login({scope: Configs.scope}).then(
      () => {
        this.zone.run(() => {
          this.meService.getMe().subscribe(data => {
              localStorage.setItem('username', data.mail);
              localStorage.setItem('jobtitle', data.jobTitle);
              localStorage.setItem('loggedin', 'yes');
            },
            err => {
            console.log(err);
            },
            () => {
              this.router.navigate(['/home']);
            });
        });
      },
      e => console.error(e.error.message)
    );
  }
initAuth() {
    this.redirect_uri = window.location.href;
    hello.init({
        msft: {
          id: Configs.appId,
          oauth: {
            version: 2,
            auth: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
          },
          scope_delim: ' ',
          form: false
        },
      },
      {redirect_uri: window.location.href}
    );
  }
这是我的初始化函数:

login() {
    hello('msft').login({scope: Configs.scope}).then(
      () => {
        this.zone.run(() => {
          this.meService.getMe().subscribe(data => {
              localStorage.setItem('username', data.mail);
              localStorage.setItem('jobtitle', data.jobTitle);
              localStorage.setItem('loggedin', 'yes');
            },
            err => {
            console.log(err);
            },
            () => {
              this.router.navigate(['/home']);
            });
        });
      },
      e => console.error(e.error.message)
    );
  }
initAuth() {
    this.redirect_uri = window.location.href;
    hello.init({
        msft: {
          id: Configs.appId,
          oauth: {
            version: 2,
            auth: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
          },
          scope_delim: ' ',
          form: false
        },
      },
      {redirect_uri: window.location.href}
    );
  }
这里我得到了访问令牌:

getAccessToken() {
    const msft = hello('msft').getAuthResponse();
    console.log(msft);
    const accessToken = msft.access_token;
    return accessToken;
  }
我得到一个访问令牌,通过它我可以登录。但是,我没有得到刷新令牌。从我读到的内容来看,您可以通过/token端点获得刷新和访问令牌。就我所见,我只使用/authorize端点,它能工作吗

这带来了一个问题。我无法刷新我的令牌

响应如下所示:

access_token:
"This is private, but it's a very long string"
client_id:"e6c987d2-8bdc-4f1a-bafc-04ba3d51f340"
display:"popup"
expires:1524649746.548
expires_in:3599
network:"msft"
redirect_uri:"http://localhost:4200/"
scope:"basic,User.Read"
session_state:"89a68bd2-5ae5-4df2-88d0-d28718fd10bc"
state:""
token_type:"Bearer"
任何帮助都将不胜感激

由于您正在使用,因此无法使用刷新令牌。仅支持使用

为了使用刷新令牌,您需要切换到授权代码授权,并实现服务器端代码以将授权代码处理为访问令牌。您还需要请求作用域
脱机\u访问
,该访问触发
刷新\u令牌的生成