【发布时间】:2019-11-14 11:00:33
【问题描述】:
我正在尝试使用 jQuery 获取 access_token。问题是,我无法获得该令牌(服务器在 localhost 上运行)。服务器工作正常(我用邮递员试过),但我不能用 jQuery 得到它。 浏览器在点击按钮后写入。
来自“http://localhost:8080/oauth/token?callback=jQuery34105901959820360243_1562175129954&grant_type=password&client_id=my-client&client_secret=my-secret&username=test%40seznam.cz&password=Peter&_=1562175129955”的资源由于 MIME 类型(“application/json”)不匹配(X-Content-Type-Options: nosniff)而被阻止。
获取access_token的jQuery函数
function authenticateUser(email, password) {
var body = {
grant_type: 'password',
client_id: 'my-client',
client_secret: 'my-secret',
username: "test@seznam.cz",
password: "Peter"
};
$.ajax({
url: 'http://localhost:8080/oauth/token',
crossDomain: true,
type: 'POST',
dataType: 'jsonp',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
header: {"Access-Control-Allow-Origin": "*"},
data: body,
complete: function(result) {
alert(result);
},
success: function(result) {
alert(result + " OK!");
},
error: function(result) {
alert(result + " CHYBA");
},
});
return true;
}
【问题讨论】:
标签: javascript jquery ajax oauth-2.0 mime