JetBrains / YouTrackSharp

.NET Standard 2.0 Library to access YouTrack API.
https://www.jetbrains.com/youtrack
Apache License 2.0
134 stars 105 forks source link

Token is granted for [YouTrack] and can't be used for 0-0-0-0-0 #116

Open dse-copsfs opened 2 years ago

dse-copsfs commented 2 years ago

Expected behavior

Get a list of projects.

Actual behavior

An exception

Response    "{\"error\":\"invalid_token\",\"error_code\":401,\"error_description\":\"Token is granted for [YouTrack] and can't be used for 0-0-0-0-0\",\"error_developer_message\":\"Token is granted for [YouTrack] and can't be used for 0-0-0-0-0\"}"

Steps to reproduce the behavior

  1. Create a new permanent token (scope: YouTrack) for some user of a cloud version (our instance is: https://cops-cz.myjetbrains.com/youtrack)
  2. YouTrackSharp nuget package v. 2021.3.6
  3. Following https://github.com/JetBrains/YouTrackSharp, we tried:
    var connection = new BearerTokenConnection("https://cops-cz.myjetbrains.com/youtrack/", "perm:abcdefgh");
    var projectsService = connection.CreateProjectsService();
    var projects = await projectsService.GetAccessibleProjects();

Please advice us what is the issue.

rekolobov commented 2 years ago

Hi, please create a permanent token while selecting both YouTrack and YouTrack Administration scopes token

dse-copsfs commented 2 years ago

Hello, thanks, now it works. I have one following question, please. Our use case is read-only. No manipulation with users/projects. In this case, is the YouTrack Administration scope needed too?

kim-lindhard commented 2 years ago

You need both the YouTrack and the YouTrack Administration scopes in the Permanent Token

I tried creating a Permanent Token with only the YouTrack scope and got the 401 error code I tried creating a Permanent Token with only the YouTrack Administration scope and got the 401 error code