internal void NotifyOfCallback(Intent intent) { try { if (!intent.HasExtra("authState")) { _authState = null; } else { try { _authState = AuthState.JsonDeserialize(intent.GetStringExtra("authState")); } catch (JSONException) { _authState = null; } } if (_authState != null) { AuthorizationResponse response = AuthorizationResponse.FromIntent(intent); AuthorizationException authEx = AuthorizationException.FromIntent(intent); _authState.Update(response, authEx); if (response != null) { try { var clientAuthentication = _authState.ClientAuthentication; } catch (ClientAuthenticationUnsupportedAuthenticationMethod) { SetWaitHandle(); return; } var request = response.CreateTokenExchangeRequest(); using (var httpClient = new HttpClient(GetUnsecuredHandler())) { var jObj = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("client_id", request.ClientId), new KeyValuePair <string, string>("code", request.AuthorizationCode), new KeyValuePair <string, string>("code_verifier", request.CodeVerifier), new KeyValuePair <string, string>("grant_type", request.GrantType), new KeyValuePair <string, string>("scope", request.Scope), new KeyValuePair <string, string>("redirect_uri", request.RedirectUri.ToString()) }; var httpRequest = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri(request.Configuration.TokenEndpoint.ToString()), Content = new FormUrlEncodedContent(jObj) }; var httpResult = httpClient.SendAsync(httpRequest).Result; var tokenResponseJObject = JObject.Parse(httpResult.Content.ReadAsStringAsync().Result); tokenResponseJObject.Add("request", JObject.Parse(request.JsonSerializeString())); var tokenResponse = TokenResponse.JsonDeserialize(new JSONObject(tokenResponseJObject.ToString())); ReceivedTokenResponse(tokenResponse, null); } } } else { SetWaitHandle(); } } catch (Exception) { SetWaitHandle(); } }