Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bearer token doesn't work - Unauthorized #57

Closed
vovkms opened this issue Jul 24, 2020 · 1 comment
Closed

Bearer token doesn't work - Unauthorized #57

vovkms opened this issue Jul 24, 2020 · 1 comment

Comments

@vovkms
Copy link

vovkms commented Jul 24, 2020

Following this guide: https://github.com/microsoft/azure-devops-auth-samples/blob/master/OAuthWebSample/README.md
I was able to create an application and authorize it to access ADO on behalf of me with the following scopes: vso.code_manage vso.project
When I generate a bearer token, I can see nameid claim value equal to my userId.

However, when I use the token - I get either 401 through Rest APIs (calling https://dev.azure.com/microsoft/_apis/projects), or using the following code:

string token = "<bearer_token>";
string patToken = "<pat_token>";

VssOAuthAccessTokenCredential credentials = new VssOAuthAccessTokenCredential(token);
//VssCredentials credentials = new VssBasicCredential(string.Empty, patToken);

// Connect to Azure DevOps Services
VssConnection connection = new VssConnection(new Uri(c_collectionUri), credentials);

Console.WriteLine(connection.AuthorizedIdentity.DisplayName);

I get the following exception:
Microsoft.VisualStudio.Services.Common.VssUnauthorizedException: 'TF400813: The user ' is not authorized to access this resource. '

If I use the commented VssCredentials with PAT token with the same scope - I'm able to call both the Rest API and use this code.

@anydot
Copy link
Contributor

anydot commented Aug 25, 2020

Hi, organization admins can disable OAuth support, that then result in the above error

@anydot anydot closed this as completed Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants