I want get authentication token using REST API or session based authentication for an app or organization of Azure DevOps on SharePoint webpart page. I want some other ways to authenticate REST API of an organization except Personal Access Token (PAT) method. Can you please help me to give a solution of it? If possible please provide an example/demo of it in JavaScript/JQuery.
I had added an example in which I am using personal Access Token (PAT) to get Projects of an organization on a SharePoint page
var PATToken = 'xxxx7xxxx6xxxxx7xxxxxxx2xxx';//user need to replace his Personal Access Token here and run this snippent on SharePoint Page.
var orgName = 'TestRaju';
getOrgProjects(orgName);
function getOrgProjects(orgName) {
$.ajax({
url: 'https://dev.azure.com/' + orgName + '/_apis/projects?api-version=5.1',
dataType: 'json',
headers: {
'Authorization': 'Basic ' + btoa("" + ":" + PATToken)
}
}).success(function (results) {
console.log(results);
}).error(function (error) {
console.log(error);
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>