Javascript 隐式OAuth不';使用FetchAPI时,不要重定向或提供回调url

Javascript 隐式OAuth不';使用FetchAPI时,不要重定向或提供回调url,javascript,reactjs,oauth-2.0,instagram-api,fetch-api,Javascript,Reactjs,Oauth 2.0,Instagram Api,Fetch Api,我正在使用Fetch API触发组件中的 但是,我的代码在其响应中返回一个force_loginURL(状态为200) 我仅在更改代码时收到访问令牌: onLoginClick(){ //https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token var resource = instagramAPI+"

我正在使用Fetch API触发组件中的

但是,我的代码在其响应中返回一个
force_login
URL(状态为200)

我仅在更改代码时收到访问令牌:

  onLoginClick(){
    //https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token
    var resource = instagramAPI+"?client_id="+this.props.clientId+"&redirect_uri="+this.props.redirect_uri+"&response_type="+this.props.type;
    fetch(resource)
    .then(function(data){
      console.log("fetched the data!")
      console.log(data.url);
      //window.location.href=data.url;
    })
    .catch(function(error){
      console.log(error);
    })
  }
……为此:

  onLoginClick(){
    //https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token
    var resource = instagramAPI+"?client_id="+this.props.clientId+"&redirect_uri="+this.props.redirect_uri+"&response_type="+this.props.type;
    fetch(resource)
    .then(function(data){
      console.log("fetched the data!")
      console.log(data.url);
      window.location.href=data.url;
    })
    .catch(function(error){
      console.log(error);
    })
  }
为什么我需要添加
window.location.href=data.url行?

为什么我不能在
数据.url上运行
获取
,并在响应数据中填充url标记?

原因是该标记不在响应数据中,而在返回的头中。如果身份验证成功,Instagram将在标头中发出重定向。此重定向中包含访问令牌

当您使用window.location.href时,您告诉浏览器执行它的工作,它将转发到重定向,从而包括访问令牌

如果希望令牌不转发,请查看data.headers。我没有使用JS获取,所以我不确定头的确切名称。可能是“重定向”。尝试:


你能澄清预期的行为与实际的行为是什么吗?
onLoginClick()
应该做什么?有一个按钮可以点击触发
onLoginClick()
,它应该可以启动Instagram API并接收带有访问令牌的响应。它似乎只在创建
window.location.href
时起作用。我希望它能返回与AJAX调用类似的正确响应,而不需要重新加载整个页面。
console.log(data.headers);