How do I get an access token given a refresh token in a C# WPF app?

I’m struggling to figure out how to get an access token if I have a refresh token. Here’s the closest thing I can find (I’ve replaced the actual values). It’s throwing an “invalid access_token” exception:

var client = new AuthenticationApiClient(new Uri(myDomain));
var accessTokenRequest = new AccessTokenRequest()
{
    AccessToken = myRefreshToken,
    ClientId = myClientID,
    Connection = myConnection,
    Scope = null,
};
var accessToken = await client.GetAccessTokenAsync(accessTokenRequest);

Is it the case that this is the correct method for obtaining an access token, and I’m just passing in bad values, or is there a different method?

To be honest, the above approach doesn’t make sense. If you’re requesting an access token, why do you need to pass in an access token as part of the AccessTokenRequest object? That’s why I suspect there’s a better way.

Based on the information you provided you seem to be using v3.x of auth0.net given that the GetAccessTokenAsync method was removed in v4.x of the library.

In version 3.x you could use a refresh token through the method GetDelegationTokenAsync() while passing a RefreshTokenDelegationRequest object.

If you’re implementing this in a new application you may want to consider starting with v4.x of the library instead. You can see the differences between versions and the scenarios where you should use one version over the other at: Migration Guide

Thanks, jmangelo. I switched to v4.x, but now I’m having bigger problems. LoginAsync() returns a null refresh token even though I set the withRefreshToken parameter to true. I’ll post another question that details my new issue. Man, this is frustrating. I do appreciate your answer, though.