public static async Task UnRegisterDevice()
        {
            var bikerId = BikerService.GetBikerInfo()._id;

            var playerId = (await OneSignal.Current.IdsAvailableAsync()).PlayerId;
            var platform = Xamarin.Essentials.DeviceInfo.Platform.ToString().ToLower();

            var deviceInfo = new { installationId = playerId, platform = platform };

            await HttpClientService.Put($"https://delivery-3rd-api.azurewebsites.net/api/Biker/UnRegisterBikerDevice/{bikerId}", deviceInfo);
        }
Beispiel #2
0
        public static async Task <bool> IDP4Login()
        {
            try
            {
                var authUrl     = new Uri($"https://pilotdeli-mvc.azurewebsites.net/mobileauth/login");
                var callbackUrl = new Uri(CALLBACK_URL);
                var result      = await WebAuthenticator.AuthenticateAsync(authUrl, callbackUrl);

                appToken.AccessToken.Token  = result?.AccessToken;
                appToken.RefreshToken.Token = result?.RefreshToken;

                appToken.AccessToken.ExpiredDate = getTokenExpiredDate(appToken.AccessToken.Token);

                var needLogout = await NeedLoginAgain();

                if (needLogout)
                {
                    await App.Current.MainPage.DisplayAlert("แจ้งเตือน", $"Session หมด อายุ", "ปิด");
                    await Logout();

                    return(false);
                }

                var RefId = result.Properties.ContainsKey("ref_id") ? result.Properties["ref_id"] : "";

                if (!string.IsNullOrWhiteSpace(RefId))
                {
                    await BikerService.SetBikerInfo(RefId);
                }
                else
                {
                    await App.Current.MainPage.DisplayAlert("แจ้งเตือน", $"คุณยังไม่ได้ยืนยัน Consent", "ปิด");
                    await Logout();

                    return(false);
                }

                //TODO: SetClientBearer when server use real IDP
                //HttpClientService.SetClientBearer(appToken.AccessToken.Token);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #3
0
        public static async Task Logout()
        {
            try
            {
                //await Browser.OpenAsync("https://pilotdeli-mvc.azurewebsites.net/mobileauth/logout2", BrowserLaunchMode.SystemPreferred);
                if (Device.RuntimePlatform == Device.Android)
                {
                    var authUrl     = new Uri($"https://pilotdeli-mvc.azurewebsites.net/mobileauth/logout");
                    var callbackUrl = new Uri(CALLBACK_URL);
                    await WebAuthenticator.AuthenticateAsync(authUrl, callbackUrl);
                }

                BikerService.ClearRider();
            }
            catch (Exception e)
            {
            }
        }