Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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
Postman Oauth2调用工作,但Jquery中的同一调用失败(web扩展)_Jquery_Laravel 5_Oauth_Laravel 5.1_Firefox Addon Webextensions - Fatal编程技术网

Postman Oauth2调用工作,但Jquery中的同一调用失败(web扩展)

Postman Oauth2调用工作,但Jquery中的同一调用失败(web扩展),jquery,laravel-5,oauth,laravel-5.1,firefox-addon-webextensions,Jquery,Laravel 5,Oauth,Laravel 5.1,Firefox Addon Webextensions,我一直在使用Oauth2和Postman,它工作得很好。我如期拿到了代币 但是,当我在代码中尝试此操作时,它会生成所有代码,但从未返回要使用的代码(代码在我的数据库中,但不是从jquery调用返回) 函数验证(重定向URL){ log('start validate function'); var clientID2=“CLIENTID HERE”; var redirectURL2=browser.identity.getRedirectURL(); 设m=redirectURL.match

我一直在使用Oauth2和Postman,它工作得很好。我如期拿到了代币

但是,当我在代码中尝试此操作时,它会生成所有代码,但从未返回要使用的代码(代码在我的数据库中,但不是从jquery调用返回)

函数验证(重定向URL){
log('start validate function');
var clientID2=“CLIENTID HERE”;
var redirectURL2=browser.identity.getRedirectURL();
设m=redirectURL.match(/[\?](.*)/);
如果(!m | | m.长度<1)
返回null;
设params=newURLSearchParams(m[1]。拆分(“#”)为[0]);
让标记URL=”http://localhost:8000/oauth/access_token";
//tokenurl+=`?客户端id=${ClientD2}`;
//tokenurl+=`?客户端密码=${clientSecret}`;
//令牌URL+=`&grant_type=authorization_code`;
//tokenurl+=`&code=${params.get(“code”)}`;
//tokenurl+=`&redirect_uri=${encodeURIComponent(redirectURL2)}`;
log('validate function tokenurl'+tokenurl);
$.ajax({
方法:“张贴”,
url:tokenurl,
async:true,
跨域:是的,
标题:{
“内容类型”:“应用程序/x-www-form-urlencoded”,
“缓存控制”:“无缓存”
},
数据:{
客户识别码:client2,
客户机密:“客户ID机密”,
重定向uri:redirectURL2,
授权类型:“授权代码”,
代码:params.get(“代码”),
}
})
.done(函数(msg){
log('完成验证调用的返回');
//log(“令牌保存调用:“+msg”);
})
.fail(函数(jqXHR、textStatus、errorshown){
log('validate调用返回失败');
如果(文本状态){
log('validate call returned textStatus-'+textStatus);
}
如果(抛出错误){
log('validate call returned errorshown-'+errorshown);
}
log('validate call Finish返回失败');
})
.始终(功能(xhr、状态){
log('finishvalidatecallajax请求');
});
}
函数authorize(){
console.log('authorize2');
const redirectURL=browser.identity.getRedirectURL();
log('redirectURL');
log(encodeURIComponent(redirectURL));
日志(重定向URL);
const clientID=“clientID HERE”;
const scopes=[“openid”、“email”、“profile”];
让authURL=”http://localhost:8000/oauth/authorize";
authURL+=`?客户端id=${clientID}`;
authURL+=`&grant_type=authorization_code`;
authURL+=`&client_secret=4c7f6f8fa93d59c45502c0ae8c4a95b`;
authURL+=`&response_type=code`;
authURL+=`&redirect_uri=${encodeURIComponent(redirectURL)}`;
//authURL+=`&scope=${encodeURIComponent(scopes.join('')}`;
log('redirectURL');
日志(重定向URL);
log('authURL');
log(authURL);
返回browser.identity.launchWebAuthFlow({
互动:没错,
url:authURL
});
}
函数getAccessToken(){
log('call authorize');
返回authorize()。然后(验证);
}
log('callgetAccessToken');
getAccessToken();
我没有得到返回的数据,控制台日志显示了error这个词。这些函数被调用并到达我的后端,因为它正在生成最终代码并将其存储在数据库中

我正在使用这个laravel oauth包 使用5.1版

我在运行版本54的firefox开发者版上的firefox webextension中使用了它,该版本支持Oauth2调用(基于文档)

当您尝试安装和使用扩展时,在(OSX上的Ctrl-Shift-J或Cmd-Shift-J)中显示了什么?请将问题添加到主题中:包含重复该问题的问题。对于Chrome扩展或Firefox WebExtensions,这几乎总是意味着包括manifest.json和一些背景、内容和/或弹出脚本/HTML。寻求调试帮助的问题(“为什么这段代码没有按我想要的方式工作?”)必须包括:(1)所需的行为,(2)特定的问题或错误,(3)在问题本身中重现它所需的最短代码。另请参阅:、和。
function validate(redirectURL) {
  console.log('start validate function');


  var clientID2 = "CLIENTID HERE";
  var redirectURL2 = browser.identity.getRedirectURL();
  let m = redirectURL.match(/[#\?](.*)/);
  if (!m || m.length < 1)
    return null;
  let params = new URLSearchParams(m[1].split("#")[0]);
    let tokenurl = "http://localhost:8000/oauth/access_token";
  // tokenurl += `?client_id=${clientID2}`;
  // tokenurl += `?client_secret=${clientSecret}`;
  // tokenurl += `&grant_type=authorization_code`;
  // tokenurl += `&code=${params.get("code")}`;
  // tokenurl += `&redirect_uri=${encodeURIComponent(redirectURL2)}`;
  console.log('validate function tokenurl '+ tokenurl);
  $.ajax({
    method: "POST",
    url: tokenurl,
    async: true,
    crossDomain: true,
    headers: {
      "content-type": "application/x-www-form-urlencoded",
      "cache-control": "no-cache"
    },
    data : {
      client_id : clientID2,
      client_secret : "CLIENT ID SECRET",
      redirect_uri : redirectURL2,
      grant_type : "authorization_code",
      code : params.get("code"),
    }
  })
    .done(function( msg ) {
      console.log('Done return for validate call');
      // console.log( "Token Save Called: " + msg );
    })
    .fail(function(jqXHR, textStatus, errorThrown){
      console.log('Fail return for validate call');
      if(textStatus){
        console.log('validate call returned textStatus-' + textStatus);
      }
      if(errorThrown){
        console.log('validate call returned errorThrown-'+errorThrown);
      }
      console.log('Fail return for validate call Finish');
    })
    .always(function( xhr, status ) {
       console.log('finish validate call ajax request');
     });
}


function authorize() {
  console.log('authorize2');
  const redirectURL = browser.identity.getRedirectURL();
  console.log('redirectURL');
  console.log(encodeURIComponent(redirectURL));
  console.log(redirectURL);
  const clientID = "CLIENTID HERE";
  const scopes = ["openid", "email", "profile"];
  let authURL = "http://localhost:8000/oauth/authorize";
  authURL += `?client_id=${clientID}`;
  authURL += `&grant_type=authorization_code`;
  authURL += `&client_secret=4c7f6f8fa93d59c45502c0ae8c4a95b`;
  authURL += `&response_type=code`;
  authURL += `&redirect_uri=${encodeURIComponent(redirectURL)}`;
  // authURL += `&scope=${encodeURIComponent(scopes.join(' '))}`;

  console.log('redirectURL');
  console.log(redirectURL);
  console.log('authURL');
  console.log(authURL);

  return browser.identity.launchWebAuthFlow({
    interactive: true,
    url: authURL
  });
}


function getAccessToken() {
  console.log('call authorize');
  return authorize().then(validate);
}

console.log('call getAccessToken');
getAccessToken();