I'm facing some issue, while using Xamarin.Auth for OAuth2 authentication.
From POSTMAN I'm sending request for token, via GET method to my backend URL: http://example.com/backend/oauth/token by adding to header:
Authorization, Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
and with below parameters in URL:
client_id=backendClient
scope=read
grant_type=password
username=admin
password=admin
so it goes like: http://example.com/backend/oauth/token?client_id=backendClient&scope=read&grant_type=password&username=admin&password=admin
it gives me back JSON, which looks like:
{ "access_token": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "token_type": "bearer", "refresh_token": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "expires_in": 9999, "scope": "read" }
I wanted to authenticate to my backend service, from mobile application (using Xamarin.Forms app), and I've tried to use Xamarin.Auth, for authenticating to my back-end - https://developer.xamarin.com/guides/xamarin-forms/web-services/authentication/oauth/
Indeed using OAuth2Authenticator, it's able at least to "ping" my backend (by putting URL, clientIde etc), as it returns:
<UnauthorizedException>
<error>unauthorized</error>
<error_description>Full authentication is required to access this resource</error_description>
</UnauthorizedException>
however message it's beeing send in wrong way - at least I think so, as there is no Authorization in header + I haven't see any possibility to pass username and password into OAuth2Authenticator.
Does anyone have idea, how I can do this? Or should I use something else - not Xamarin.Auth?
Thanks.
Here's how I do it (not using Xamarin.Auth):
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenGoesHere);
Then you can add any content you like and Get/Post/PutAsync, whatever you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With