function requestToken() {
$.ajax({
"async": true,
"crossDomain": true,
"url": endpointUrl, // Pass your tenant name instead of sharepointtechie
"method": "POST",
"headers": {
"content-type": "application/x-www-form-urlencoded"
},
"data": {
"grant_type": "password",
"client_id ": clientId, //Provide your app id
"client_secret": clientSecret,
"scope ": "https://graph.microsoft.com/.default",
"userName": "xxxxxxxxx",
"password": "xxxxxxxx",
"redirect_uri" : "xxxxxxx"
},
success: function (response) {
console.log(response);
token = response.access_token;
$.ajax({
url: 'xxxxxx',
type: 'GET',
dataType: 'json',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + token + '');
},
data: {},
success: function (results) {
console.log(results);
debugger;
},
error: function (error) {
console.log("Error in getting data: " + error);
}
});
}
})
}
我的意思是向MS Graph Api发出请求,以便从OneDrive上托管的Excel电子表格中获取单元格和行数据。
一切都很好,但是我想知道解决这个问题的最佳实践是什么。
我可以使用client-id和client-secret编写一个AJAX请求来认证使用,但是这会将这些凭证公开给客户端浏览器。
我如何仍可以向API发出请求,但要确保应用凭据安全。
干杯,乔希
谢谢杰森!我可以使用该隐式授权流程代表其他用户登录用户吗?
我不确定是否要遵循。您不能在任何流程中以另一个用户身份登录一个用户,这意味着用户A无法登录并充当用户B。