0

We have a stateful web application that maintains long living server session for each user (as long as user works with system session is alive) that need to work with Azure DevOps. We are using .NET client libraries.

We are keeping VssConnection for the session lifetime. We are creating connection like this:

var vssOAuthAccessTokenCredential = new VisualStudio.Services.OAuth.VssOAuthAccessTokenCredential(accessToken);
var connection = new VssConnection(connectionUrl, vssOAuthAccessTokenCredential);

The problem here is that access token expires after some time and I don’t see any kind of connection/credential class in SDK that will accept some callback that I can pass to refresh token.

I tried to implement my own IVssCredentialPrompt, but when I’m creating new VssConnection passing my IVssCredentialPrompt implementation and CredentialPromptType.PromptIfNeeded I’m getting

System.ArgumentException: The prompt option is invalid because the process is not interactive. Parameter name: PromptType.

I also can’t create my own implementation of FederatedCredential since it requires IssuedToken instance which constructor is internal.

What is recommended solution for this case?

Leonid K
  • 1
  • 1

1 Answers1

0

You can use PAT token:

var credential = new VssBasicCredential(string.Empty, "PAT");
var connection = new VssConnection(new Uri("https://dev.azure.com/<your-organization>/"), credential);
Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • Thanks, Yes, but ... That doesn't change a lot since user can revoke them anytime and we still has no callback to ask user to re-auth... Also we need to ask user to create and provide PAT or create it ourselves and store it in addition to access token/refresh token... – Leonid K Apr 17 '20 at 12:51