microsoft / azure-devops-extension-api

REST client libraries and contracts for Azure DevOps web extension developers.
MIT License
95 stars 45 forks source link

CORS error when using client #39

Open JonThorr opened 4 years ago

JonThorr commented 4 years ago

I am getting a CORS error when I am calling the REST API using the client. This is what I do:

import {getClient} from 'azure-devops-extension-api';
import * as SDK from 'azure-devops-extension-sdk';
import {WorkItemTrackingRestClient} from 'azure-devops-extension-api/WorkItemTracking';

const getRecent = async () => {
   await SDK.init();
   const client = getClient(WorkItemTrackingRestClient);
   const recent = await client.getRecentActivityData();
   return recent;
}

Looking at the samples I have seen, then I have not been able to figure out what I am missing. Any ideas how I can get this working?

pauldev263 commented 4 years ago

Check your json settings file, it needs to have a scopes section.

"scopes":[ "vso.work" ]

The sample repository doesn't include it as it only requests data about the project.

See more scopes info

pelizza commented 3 years ago

I had the same error before adding the scope and that fixed the issue.

rodrigocipriani commented 3 years ago

Actually after upload the new version of extension to the Azure DevOps, you have to update rights for it in the https://dev.azure.com/{your_organization}/_settings/extensions?tab=installed

when you add new scopes "scopes": ["vso.build"] in the manifest file.

pelizza commented 3 years ago

Exactly. Users need to manually authorise a new scope added to the descriptor.

tovVAar commented 3 years ago

After adding the scope, some fetch requests that I had for azure functions stopped working with a 401 error, and removing back the scopes, it works again. Does anyone have an idea about what could be wrong?

pelizza commented 3 years ago

You probably need to manually go to the admin section where you see your installed extensions and approve the scope change for your app, as described by @rodrigocipriani.

tovVAar commented 3 years ago

Thanks, I realized that the certificate changes after updating the scope, so I had to update the secret that was keeping track of the certificate for authenticate on the azure function.