public override async void OnPageStarted(WebView view, string url, Bitmap favicon) { base.OnPageStarted(view, url, favicon); layoutProgress = view.FindViewById <LinearLayout>(Resource.Id.layout_progress); layoutProgress.Visibility = ViewStates.Visible; layoutProgress.Enabled = true; //view.DispatchFinishTemporaryDetach(); if (url.Contains("&code=")) { string code = Common.FunGetValuefromQueryString(url, "code"); PreferenceHandler.SetAccessCode(code); PreferenceHandler.setLoggedIn(true); string tokenURL = string.Format(B2CConfig.TokenURL, B2CConfig.Tenant, B2CPolicy.SignInPolicyId, B2CConfig.ClientId, PreferenceHandler.GetAccessCode()); var response = await InvokeApi.Authenticate(tokenURL, string.Empty, HttpMethod.Post); if (response.StatusCode == System.Net.HttpStatusCode.OK) { string strContent = await response.Content.ReadAsStringAsync(); var tokenNew = JsonConvert.DeserializeObject <AccessToken>(strContent); PreferenceHandler.SetToken(tokenNew.id_token); PreferenceHandler.SetRefreshToken(tokenNew.refresh_token); layoutProgress.Visibility = ViewStates.Visible; await GetUserDetails(view); } } }
private async void WebView_LoadError(object sender, UIWebErrorArgs e) { var URL = (NSObject)e.Error.UserInfo.Values[2]; string req = URL.ToString(); if (req.Contains("&code=")) { string code = Common.FunGetValuefromQueryString(req, "code"); PreferenceHandler.SetAccessCode(code); string tokenURL = string.Format(B2CConfig.TokenURLIOS, B2CConfig.Tenant, B2CPolicy.SignInPolicyId, B2CConfig.Grant_type, B2CConfig.ClientId, code); var response = await InvokeApi.Authenticate(tokenURL, string.Empty, HttpMethod.Post); if (response.StatusCode == System.Net.HttpStatusCode.OK) { string strContent = await response.Content.ReadAsStringAsync(); var token = JsonConvert.DeserializeObject <AccessToken>(strContent); PreferenceHandler.SetToken(token.id_token); PreferenceHandler.SetRefreshToken(token.refresh_token); } } if (req.Contains("id_token=")) { string token = Common.FunGetValuefromQueryString(req, "id_token"); PreferenceHandler.SetToken(token); //PreferenceHandler.SetRefreshToken(token.refresh_token); } var responseUser = await InvokeApi.Invoke(Constants.API_GET_CURRENTUSER, string.Empty, HttpMethod.Get, PreferenceHandler.GetToken()); if (responseUser.StatusCode != 0) { InvokeOnMainThread(() => { GetCurrentUserResponse(responseUser); }); } }