You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For that, like in sample UWP, I have add a HttpClient that uses RefreshTokenHandler recovered with a LoginAsync(...), but I get an Unhandled Exception during the GetAsync(....).
My code
public MainPage ()
{
InitializeComponent ();
Login.Clicked += Login_Clicked;
CallApi.Clicked += CallApi_Clicked;
var browser = DependencyService.Get<IBrowser>();
var options = new OidcClientOptions
{
Authority = "https://demo.identityserver.io",
ClientId = "interactive.public",
Scope = "openid profile email api offline_access",
RedirectUri = "xamarinformsclients://callback",
Browser = browser,
ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect
};
_client = new OidcClient(options);
//Default client
_lazyapiClient.Value.BaseAddress = new Uri("https://demo.identityserver.io/");
}
private async void Login_Clicked(object sender, EventArgs e)
{
_result = await _client.LoginAsync(new LoginRequest());
if (_result.IsError)
{
OutputText.Text = _result.Error;
return;
}
var sb = new StringBuilder(128);
foreach (var claim in _result.User.Claims)
{
sb.AppendFormat("{0}: {1}\n", claim.Type, claim.Value);
}
sb.AppendFormat("\n{0}: {1}\n", "refresh token", _result?.RefreshToken ?? "none");
sb.AppendFormat("\n{0}: {1}\n", "access token", _result.AccessToken);
OutputText.Text = sb.ToString();
_lazyapiClient.Value.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _result?.AccessToken ?? "");
//My new APIClient compatible RefreshToken
_apiClient = new HttpClient(_result.RefreshTokenHandler);
_apiClient.BaseAddress = new Uri("https://demo.identityserver.io/");
}
private async void CallApi_Clicked(object sender, EventArgs e)
{
var result = await _lazyapiClient.Value.GetAsync("api/test");
var result2 = await _apiClient.GetAsync("api/test"); //==> Throw Unhandled exception
if (result.IsSuccessStatusCode)
{
OutputText.Text = JArray.Parse(await result.Content.ReadAsStringAsync()).ToString();
}
else
{
OutputText.Text = result.ReasonPhrase;
}
}
Would I have made a mistake?
The text was updated successfully, but these errors were encountered:
I'm experiencing the same problem. Is it a 'The inner handler has not been assigned.' exception? I was wondering if it may be related to the HttpClient version I am using.
Hello,
I wanted to add the management of the resfresh token () to Oidc sample - XamarinForms (UWP).
For that, like in sample UWP, I have add a HttpClient that uses RefreshTokenHandler recovered with a LoginAsync(...), but I get an Unhandled Exception during the GetAsync(....).
My code
Would I have made a mistake?
The text was updated successfully, but these errors were encountered: