Using Xamarin.Auth for OAuth2 authentication - username and password

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:

unauthorized
Full authentication is required to access this resource

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.

Posts

  • VegasJVegasJ USUniversity ✭✭
    edited February 2017

    I know this is old but for others looking, I don't think Xamarin.Auth OAuth2Authenticator supports the password grant_type, only the implicit and auth code ones. I believe you would need to extend and write a custom OAuth2Authenticator.

Sign In or Register to comment.