microsoft / azure-devops-extension-api

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

blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource #100

Open padhibibaswan opened 1 year ago

padhibibaswan commented 1 year ago

Code :

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

SDK.init().then(() => { SDK.ready().then(async () => {

   // This works perfectly fine and get 200 response code 
    const client = getClient(WorkItemTrackingRestClient);
    const recent = await client.getRecentActivityData();
    console.log(recent);

    // This does not work and i get the 401 error code.
    const gitclient = getClient(GitRestClient);
    const repos = await gitclient.getRepositories("projectname");
    console.log(repos);    

}
);

});

The complete error message that i get is : Access to fetch at 'https://dev.azure.com///_apis/git/Repositories' from origin 'https://bibasample.gallerycdn.vsassets.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I have also added the Scope as below :

"scopes": [ "vso.code_write", "vso.release", "vso.tokens" ]

padhibibaswan commented 1 year ago

Added the scope in correct file and it worked .

kannan-cidc commented 6 months ago

@padhibibaswan which file did you add the scope ? can you please help ? I have the same scopes that you have in vss-extension.json should we mention the scopes somewhere else ?

kannan-cidc commented 6 months ago

never mind, I figured out, we need to add the "scopes": ["vso.work", "vso.code"] based on whether you are dealing with workitems or code/repo and then deploy and test it from test org . thanks for the help @padhibibaswan

kannan-cidc commented 6 months ago

We can close this issue.