I'm trying to authorize myself to use the strava API. I managed to get an access token and specifying the scopes. In order to be able to write data to one of my activities I need to pass in an authorization code (with the great help of
static async Task Main(string[] args)
{
// Step 1: Send user to authorization page
var queryParams = new Dictionary<string, string>
{
{ "client_id", clientId },
{ "response_type", "code" },
{ "redirect_uri", redirectUri },
{ "scope", scope }
};
var authorizeUri = $"{authorizeUrl}?{string.Join("&", queryParams.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}"))}";
Console.WriteLine($"Open the authorization url: {authorizeUri}");
// Step 2: User authorizes on page and get redirected to the redirect)uri with a code
...
}
using this url in a browser, gives me the authorization page on which I click approve after which I get redirected to the localhost url specified. In that localhost url the code that I need is displayed in the querystring….
In my use case I want to receive the authorization code in my code so I can use it to do the actual write on the activity. I know I have to authorize it one time manually.
How can I get the authorization code in code by calling the authorizeUri? For development purposes I'm writing code that runs on a laptop. In a later stage I'll turn my code into a mobile app.