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

2021.3.1 is not working #107

Closed kolibaba closed 3 years ago

kolibaba commented 3 years ago

Tying to get issues from YT:

var connection = new BearerTokenConnection("https://[some].myjetbrains.com/youtrack", "[token]");
onnection.CreateIssuesService().GetIssues("[filter]", take: 1000);

Got error:

Unhandled exception. YouTrackSharp.UnauthorizedConnectionException: Could not authenticate. Server did not return expected authentication response. Check the Response property for more details.
   at YouTrackSharp.BearerTokenConnection.GetAuthenticatedApiClient()
   at YouTrackSharp.Issues.IssuesService.GetIssues(String filter, Nullable`1 skip, Nullable`1 take, Boolean wikifyDescription, Boolean wikifyContents)
kolibaba commented 3 years ago

Token is valid. Tried getting a new token and got the same error

rekolobov commented 3 years ago

@kolibaba hi, please check if your token scope is both YouTrack and Hub and re-issue it if it's not so due to changes in api we had to make this a requirement

see other breaking changes described here in case you missed it

kolibaba commented 3 years ago

Can't find scope hub image

rekolobov commented 3 years ago

apologies, seems the scope was chosen correctly in your case indeed

could you please check exception's Response property? assitionally, you could provide your instance name so that I could check server logs if it's required

kolibaba commented 3 years ago

{"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"}

rekolobov commented 3 years ago

Then generating new token with default selected scopes YouTrack and YouTrack Administration must help in your case (0-0-0-0-0 is exactly YouTrack Administration)

Note how Scope Services should look for a correct token screenshot

kolibaba commented 3 years ago

Thks, it works now! I used wrong token before, without admin scope.