7

I am trying to connect Azure DevOps using below code in asp.net core(2.1) mvc app

Uri orgUrl = new Uri("https://dev.azure.com/xxxxx/");          
String personalAccessToken = "xxxxx";  
VssConnection connection = new VssConnection(orgUrl, new VssBasicCredential(string.Empty, personalAccessToken));

But getting this error "VssUnauthorizedException: 'VS30063: You are not authorized to access https://dev.azure.com.'"

Same code is working in .net core console app, Please can anybody help me on this?

Here my code i am trying to get Work items, geting error on GetClient enter image description here

nakul89
  • 117
  • 1
  • 1
  • 7
  • How the things going? Does your MVC app can execute successfully now? Feel free to share us your process thus other SO users can help you. – Mengdi Liang Sep 10 '19 at 08:43

4 Answers4

6

There's no error on your code.

VS30063: You are not authorized to access https://dev.azure.com.

This is an unauthorized error code. It should caused by your PAT token is not available. By using your code, if I use a expired token, will receive the same error.

enter image description here

After generated a new PAT token, the error disappeared and the code work successfully.

So, just try with generate a new token from Azure Devops and use it.

Updated:

With the key code which from the screenshot of the updated question, I create a completed Application to writeLine the WIQL result. Still succeed shown as below:

enter image description here

Could you execute your code and share the error screenshot?(Note: Just for error line)

Mengdi Liang
  • 17,577
  • 2
  • 28
  • 35
  • 1
    Thanks, but new PAT is also giving same issue and old one is not expired. Interesting thing is same code is working in console app for both new and old PAT, so i am not able to figure out why it is not working in web app? – nakul89 Sep 03 '19 at 11:58
  • I could not know what's your script look like. See my updated pic in answer, it still succeed on my Asp.Net core mvc app with the same code and same token. No difference used between Console app and Asp.Net core MVC app.Do you mind share which operation(API) are you trying to doing? Better share some code. – Mengdi Liang Sep 03 '19 at 13:33
  • I have updated the question with screenshot of code please have a look – nakul89 Sep 04 '19 at 06:00
  • @nakul89 I don't know how do you list and writeLine the result of WIQL. But I use the code which shown in your updated screenshots to create a complete application, still succeed. See the updated pic in my answer. It's weird and I think the error should not caused by these credential connection script. Emm~~You'd better share more so that I could debug it. – Mengdi Liang Sep 04 '19 at 14:32
  • Here is my code https://github.com/ncool89/vsts.git ,can you please check what is wrong in that? – nakul89 Sep 17 '19 at 09:27
  • @nakul89 I tested and analysis these code, very wired that it’s succeed on my side.( I test with disabling the code related to sql connect). Since console app has cache, you’d better change another machine to compile these script. – Mengdi Liang Sep 18 '19 at 12:11
  • @nakul89 In addition, you can use fiddler to capture the data between this mvc app and azure devops. In fiddler trace you can see the detailed error about 401 caused reason. Fiddler is a very great debug tool between web applicant and internet – Mengdi Liang Sep 18 '19 at 13:21
  • @IngoB Could you try with using Fiddler to capture the internet records? Or you can raise a new ticket with the fiddler trace if convenient. – Mengdi Liang Oct 21 '19 at 15:17
  • @Merlin Liang: It was my wrong, see my answer. Thank you very much! – IngoB Oct 21 '19 at 18:46
1

Did you set the PAT permissions on every scope you are using? After creating a new token, I forgot to set permissions on "Code" - "read" for the GitHttpClient.

IngoB
  • 2,552
  • 1
  • 20
  • 35
0

In my case the issue was caused by a wrong organization URL.

When you use a URL like this:

https://dev.azure.com/example-org

And the organization exists but you do not have access to example-org, then you will also get the message:

VS30063: You are not authorized to access https://dev.azure.com.
veertien
  • 457
  • 5
  • 18
-1

I got this error while creating custom agent in azure devops after entering the PAT. I gave full control while creating new PAT and used that PAT while configuring custom agent pool.

enter image description here

karunakar bhogyari
  • 622
  • 1
  • 8
  • 16
  • 2
    What subset of permissions is required to create/query work items? I'm getting this error with full access to work items – merhoo Sep 07 '21 at 17:57