In Xamarin.Maui, I’m trying to access Strava with oAuth2.
The procedure is to request an access code and then exchange this code for a token. This token is used for retreiving all the data needed from my Strava account.
To get the access code, I’m using the WebAuthenticator :
string cUrl = "https://www.strava.com/api/v3/oauth/authorize";
var authURL = new Uri(
cUrl +
"?client_id=" + clientId +
"&redirect_uri=" + new Uri("myredirect_URI ") +
"&response_type=code" +
"&approval_prompt=auto" +
"&scope=read,read_all,profile:read_all,activity:read_all");
var callbackUrl = new Uri("my_callback_url ");
WebAuthenticatorResult r = await Microsoft.Maui.Essentials.WebAuthenticator.AuthenticateAsync(authURL, callbackUrl);
It’s quite easy and I receive the proper access code. Then I exchange it for a token and everything runs smoothly.
The first time this code is run, the browser opens Strava’s website and asks my user name and password to login to my strava account (this is the normal procedure). Then the control is given back to my app with the requested access code.
The problem is when I run the same code a second time, the browser doesn’t open anymore on Strava’s web site for login. But the control is given back to my app with a proper access code.
To get back my Strava login screen, I have to uninstall my app on my mobile and reinstall and run it again.
With the « old » Xamarin (pre-Maui), I have been succesfully using OAuth2Authenticator.
Does anybody have an idea about this problem ?
TIA
Eric
Hello Ben,
Thanks for your answer but I do not think it’s the solution.
AFAIK, there are two phases in the identification process. The first phase is the login process (authenticate) that gives access to the user data in Strava. The other phase is the authorization access that gives the right to the app to connect to Strava.
In summary : the login is related to the user and the authorization to the app.
The user must give a login and a password to acces its data.
The app must give a client_id (it’s the app id given by Strava), an approval_code, … to be authorized by Strava. This authorization is « forever » (at least until a deauthorize).
With approval_code=force, the authorization is asked every time the code is run and that’s not what we want.
I just want the user login process (authentication) to be launched when I want.
The user login and the app authorization screens :
![Screenshot_20220304-091235[1].jpg](https://groups.google.com/group/strava-api/attach/12677c11abea9/Screenshot_20220304-091235%5B1%5D.jpg?part=0.1&view=1)
![Screenshot_20220304-085058_Chrome[1].jpg](https://groups.google.com/group/strava-api/attach/12677c11abea9/Screenshot_20220304-085058_Chrome%5B1%5D.jpg?part=0.2&view=1)
Eric