Skip to content

Commit

Permalink
Fix web authenticator not called on main thread authgear#44
Browse files Browse the repository at this point in the history
  • Loading branch information
roxk committed Jun 2, 2022
1 parent f384b7f commit b9f290d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions Authgear.Xamarin/AuthgearSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,19 +390,22 @@ private async Task<string> GetAuthorizeEndpointAsync(OidcAuthenticationRequest r
/// <returns>Redirect URI with query parameters</returns>
private async Task<string> OpenAuthorizeUrlAsync(string redirectUrl, string authorizeUrl)
{
// WebAuthenticator abstracts the uri for us but we need the uri in FinishAuthorization.
// Substitute the uri for now.
var result = await WebAuthenticator.AuthenticateAsync(new WebAuthenticatorOptions
return await MainThread.InvokeOnMainThreadAsync(async () =>
{
Url = new Uri(authorizeUrl),
CallbackUrl = new Uri(redirectUrl),
PrefersEphemeralWebBrowserSession = !shareSessionWithSystemBrowser
var result = await WebAuthenticator.AuthenticateAsync(new WebAuthenticatorOptions
{
Url = new Uri(authorizeUrl),
CallbackUrl = new Uri(redirectUrl),
PrefersEphemeralWebBrowserSession = !shareSessionWithSystemBrowser
}).ConfigureAwait(false);
// WebAuthenticator abstracts the redirect uri (WebAuthenticatorResult) for us but we need the uri in FinishAuthorization.
// Substitute the uri for now.
var builder = new UriBuilder(redirectUrl)
{
Query = result.Properties.ToQueryParameter()
};
return builder.ToString();
}).ConfigureAwait(false);
var builder = new UriBuilder(redirectUrl)
{
Query = result.Properties.ToQueryParameter()
};
return builder.ToString();
}

private async Task<(UserInfo userInfo, OidcTokenResponse tokenResponse)> ParseDeepLinkAndGetUserAsync(string deepLink, string codeVerifier)
Expand Down

0 comments on commit b9f290d

Please sign in to comment.