0
votes

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>
1

1 Answers

0
votes

You may try OAuth token:

https://docs.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/oauth?view=azure-devops

User Authorizes your Application

At a high-level, you call the "authorize" endpoint and provide a callback. The callback must be a secure url (https) in your application:

https://app.vssps.visualstudio.com/oauth2/authorize
    ?client_id={app ID}
    &response_type=Assertion
    &state={state}
    &scope={scope}
    &redirect_uri={callback URL}

Assuming the user accepts the authorization, Azure DevOps redirects to your callback location with the authorization code in the URL.

https://fabrikam.azurewebsites.net/myapp/oauth-callback
    ?code={authorization code}
    &state={state}

You may refer to the following case:

Access Azure DevOps REST API with oAuth