Xamarin.Auth: Oauth2 with Authorization Code Grant not working

OAuth2 Authorization Code Grant flow not working

With parameters:

  • clientId
  • clientSecret
  • scope
  • authorizeUrl
  • redirectUrl
  • accessTokenUrl

is not working as expected. after the authorization is successful redirectUrl is triggered instead of the accesstokenUrl.

Version

  • nuget version = 1.5.0.3
  • component version = 26.0.2
  • xamarin forms version = 2.5.0.121934

Steps to reproduce

  1. Update Xamarin.Forms, Xamarin.auth to the versions above
  2. create an Auth client
OAuth2Authenticator authenticator = new OAuth2Authenticator(
         clientId,
         clientSecret,
         Scope,
         new Uri(AuthorizeUrl),
         new Uri(redirectUri),
         new Uri(AccessTokenUrl),
         null,
         isUsingNativeUI);

authenticator.Completed += OnAuthCompleted;
authenticator.Error += OnAuthError;

var presenter = new OAuthLoginPresenter();
presenter.Login(authenticator);

  1. After Authorize, access token URL is not trigged. instead, redirect URL is triggered

Expected behaviour

https://oauth2.thephpleague.com/authorization-server/auth-code-grant/

Actual behaviour

screenshot_1516621895

VS bug #733076, VS bug #946864

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

This is because in the OAuth2Authenticator class we are calling Uri.AbsoluteUri to set the “redirect_uri” parameter for the access token HTTP request. This adds a trailing slash to the redirect URI that many providers reject because it doesn’t exactly match the redirect URI passed in the authorize HTTP request step of the process. We should be using Uri.OrginalString instead.