コード例 #1
0
        /// <summary>
        /// This is the go-to method to handle the authorization and sign-in OAuth flow.
        /// It tries to fetch the google auth token from cache, and if it can't it will try to
        /// fetch it using a refresh token, if that's not possible it will prompt the user to
        /// authorize the application resulting in a google auth token.
        /// It will then use this google auth token to try to sign into firebase, and if that
        /// doesn't work the first time it will retry a second time after having the using re-authorize
        /// the application. (It does this since the refresh token could have been revoked.)
        /// </summary>
        /// <returns><c>true</c> if sign in was successful, <c>false</c> otherwise.</returns>
        public async Task <bool> SignInPromptUserIfNecessary()
        {
            try
            {
                string googleToken;

                using (new DisposableLogger(() => AuthLog.GetAccessTokenBegin("Google"), (sw) => AuthLog.GetAccessTokenEnd(sw, "Google", !string.IsNullOrEmpty(GoogleClient.accessToken))))
                {
                    // Try to fetch google token without prompting the user (authorizing).
                    if (await GoogleClient.Client.GetAccessTokenWithoutAuthentication())
                    {
                        googleToken = GoogleClient.accessToken;
                    }
                    else // Prompt the user to authorize the application.
                    {
                        googleToken = await AuthModal.AuthorizeAndGetGoogleAccessTokenAsync();
                    }
                }

                var firebaseSignInSuccess = false;
                using (new DisposableLogger(() => AuthLog.GetAccessTokenBegin("Firebase"), (sw) => AuthLog.GetAccessTokenEnd(sw, "Firebase", firebaseSignInSuccess)))
                {
                    // Try to sign into firebase with the googleToken.
                    firebaseSignInSuccess = await SignInWithFirebaseAsync(googleToken);
                }
                if (!firebaseSignInSuccess)
                {
                    // Could not log into firebase. Could be caused by a refresh token revocation, try re-authenticating with Google.
                    googleToken = await AuthModal.AuthorizeAndGetGoogleAccessTokenAsync();

                    using (new DisposableLogger(() => AuthLog.GetAccessTokenBegin("Firebase"), (sw) => AuthLog.GetAccessTokenEnd(sw, "Firebase", firebaseSignInSuccess)))
                    {
                        // Retry firebase login.
                        firebaseSignInSuccess = await SignInWithFirebaseAsync(googleToken);

                        // Return result.
                        return(firebaseSignInSuccess);
                    }
                }

                return(firebaseSignInSuccess);
            }
            catch (Exception e)
            {
                // Log Exception.
                LifecycleLog.Exception(e);
                return(false);
            }
        }
コード例 #2
0
        private async void Auth_Tapped(object sender, TappedRoutedEventArgs e)
        {
            SignInButton.IsEnabled = false;
            var signInAuthResult = false;

            // Time and log signing in and authentication.
            using (new DisposableLogger(() => AuthLog.GetAccessTokenBegin("Google"), (sw) => AuthLog.GetAccessTokenEnd(sw, "Google", signInAuthResult)))
            {
                signInAuthResult = await GoogleClient.Client.SignInAuthenticate();
            }

            if (signInAuthResult)
            {
                if (_authCompletionSource.TrySetResult(GoogleClient.accessToken))
                {
                    ShowAuth(false);
                }
            }
            SignInButton.IsEnabled = true;
        }
コード例 #3
0
        public int AddCustomer(CustomerAccProfile _Customer, APIServiceRequest _requestedDataObject)
        {
            try
            {
                string FunctionId   = "090103003";
                string FunctionName = "CustomerAccProfile";
                string MainAuthFlag = string.Empty;
                string MonitoringId = "3";

                var _max = _IUoW.Repository <CustomerAccProfile>().GetMaxValue(x => x.AccountProfileId);
                if (_max > 0)
                {
                    _Customer.AccountProfileId = (_max + 1).ToString();
                }
                else
                {
                    _Customer.AccountProfileId = MonitoringId + (_max + 1).ToString().PadLeft(8, '0');
                }

                if (_Customer.sameAsPeranent == "True")
                {
                    _Customer.PermanentAddress1 = _Customer.PresentAddress1;
                    _Customer.PermanentAddress2 = _Customer.PresentAddress2;
                    _Customer.PermanentCountry  = _Customer.CountryId;
                    _Customer.PermanentDistrict = _Customer.PresentDistrict;
                    _Customer.PermanentArea     = _Customer.PresentArea;
                    _Customer.PermanentCity     = _Customer.PresentCity;
                    _Customer.PermanentThana    = _Customer.PresentThana;
                    //_Customer.PermanentPhone = _Customer.PresentPhone;
                }
                //else {
                //_Customer.AuthStatusId = "U";
                //_Customer.LastAction = "ADD";
                //_Customer.AccountStatusId = "R";
                //_Customer.MakeDT = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                //_Customer.MakeBy = "mtaka";
                //}
                _Customer.SystemAccountNo = Guid.NewGuid().ToString();
                _Customer.AuthStatusId    = "U";
                _Customer.LastAction      = "ADD";
                _Customer.AccountStatusId = "001";
                _Customer.MakeDT          = System.DateTime.Now;
                _Customer.MakeBy          = "mtaka";
                var result = _IUoW.Repository <CustomerAccProfile>().Add(_Customer);

                #region Auth Log
                if (result == 1)
                {
                    string url = ConfigurationManager.AppSettings["LgurdaService_server"] + "/GetAuthPermissionByFunctionId/" + FunctionId + "/" + FunctionName + "?format=json";
                    using (WebClient wc = new WebClient())
                    {
                        TransactionRules OBJ_TransactionRules = new TransactionRules();
                        var json = wc.DownloadString(url);
                        OBJ_TransactionRules = JsonConvert.DeserializeObject <TransactionRules>(json);
                        MainAuthFlag         = OBJ_TransactionRules.GetAuthPermissionByFunctionIdResult;
                    }
                    if (MainAuthFlag == "1")
                    {
                        #region Data Store in Account Info
                        if (result == 1)
                        {
                            _AccInfo = new AccMaster();
                            var _maxAccInfoId = _IUoW.Repository <AccMaster>().GetMaxValue(x => x.AccountId) + 1;
                            _AccInfo.AccountId = _maxAccInfoId.ToString().PadLeft(3, '0');
                            //_AccInfo.AccProfileId = _Customer.AccountProfileId;
                            _AccInfo.WalletAccountNo = _Customer.WalletAccountNo;
                            _AccInfo.SystemAccountNo = _Customer.SystemAccountNo;
                            //_AccInfo.AccNm = _Customer.CustomerNm;
                            _AccInfo.AccTypeId       = _Customer.AccTypeId;
                            _AccInfo.BankAccountNo   = _Customer.BankAccountNo;
                            _AccInfo.TransDT         = Convert.ToDateTime(System.DateTime.Now.ToString("dd/MM/yyyy"));
                            _AccInfo.AccountStatusId = "001";
                            _AccInfo.AuthStatusId    = "U";
                            _AccInfo.LastAction      = "ADD";
                            _AccInfo.MakeDT          = System.DateTime.Now;
                            _AccInfo.MakeBy          = "mTaka";

                            _IUoW.Repository <AccMaster>().Add(_AccInfo);
                        }
                        #endregion

                        _IAuthLogService = new AuthLogService();
                        long _outMaxSlAuthLogDtl = 0;
                        result = _IAuthLogService.AddAuthLog(_IUoW, null, _Customer, "ADD", "0001", _Customer.FunctionId, 1, "CustomerAccProfile", "MTK_ACC_CUSTOMER_ACC_PROFILE", "AccountProfileId", _Customer.AccountProfileId, _Customer.UserName, _outMaxSlAuthLogDtl, out _outMaxSlAuthLogDtl);
                    }
                    if (MainAuthFlag == "0")
                    {
                        _IAuthLogService = new AuthLogService();
                        AuthLog _ObjAuthLog = new AuthLog();
                        _ObjAuthLog.TableNm       = "MTK_ACC_CUSTOMER_ACC_PROFILE";
                        _ObjAuthLog.AuthStatusId  = "A";
                        _ObjAuthLog.LastAction    = "ADD";
                        _ObjAuthLog.FunctionId    = FunctionId;
                        _ObjAuthLog.TablePkColVal = _Customer.AccountProfileId;
                        _ObjAuthLog.MainAuthFlag  = MainAuthFlag;

                        //_Customer.AccIdofAccInfo = _AccInfo.AccountId;

                        result = _IAuthLogService.SetTableObject <CustomerAccProfile>(_IUoW, _ObjAuthLog, _Customer);

                        if (result == 1) //For Creating User in Lguarda
                        {
                            string _UserId = _Customer.WalletAccountNo;
                            string _MakeBy = _requestedDataObject.UserId;
                            string _UserClassificationId = "2";
                            string _UserAreaId           = "5";
                            string _UserAreaIdValue      = _Customer.SystemAccountNo;
                            string _UserDescription      = "null";
                            string _BranchId             = "null";
                            string _CustomerFatherNm     = string.IsNullOrWhiteSpace(_Customer.FatherName) ? "null" : _Customer.FatherName;
                            string _CustomerMotherNm     = string.IsNullOrWhiteSpace(_Customer.MotherName) ? "null" : _Customer.MotherName;
                            //string _CustomerDOB = (_Customer.CustomerDOB == null) ? "null" : DateTime.ParseExact(_Customer.CustomerDOB.ToString(), "dd-MM-yyyy", CultureInfo.InvariantCulture).ToString();
                            string _CustomerDOB      = "null";
                            string _AccNo            = _Customer.WalletAccountNo;
                            string _MailAddress      = string.IsNullOrWhiteSpace(_Customer.Email) ? "null" : _Customer.Email;
                            string _MobNo            = string.IsNullOrWhiteSpace(_Customer.AlternativeMblNo) ? _Customer.WalletAccountNo : _Customer.AlternativeMblNo;
                            string _AuthenticationId = "5";
                            string _WorkCriteria     = "2";
                            string _RoleId           = "29";
                            string _RequestClientIP  = string.IsNullOrWhiteSpace(_requestedDataObject.RequestClientIP) ? "null" : _requestedDataObject.RequestClientIP;
                            string _RequestAppId     = string.IsNullOrWhiteSpace(_requestedDataObject.RequestAppId) ? "09" : _requestedDataObject.RequestAppId;
                            string url1 = ConfigurationManager.AppSettings["LgurdaService_server"] + "/Add_UserProfile/" + _UserId + "/" + _MakeBy + "/" +
                                          _UserClassificationId + "/" + _UserAreaId + "/" +
                                          _UserAreaIdValue + "/" + _Customer.UserName + "/" +
                                          _UserDescription + "/" + _BranchId + "/" +
                                          _AccNo + "/" + _CustomerFatherNm + "/" +
                                          _CustomerMotherNm + "/" + _CustomerDOB + "/" +
                                          _MailAddress + "/" + _MobNo + "/" +
                                          _AuthenticationId + "/" + _RequestClientIP + "/" +
                                          "null" + "/" + "null" + "/" +
                                          _WorkCriteria + "/" + _RequestAppId + "/" + "A" + "/" + _RoleId + "?format=json";
                            string lg_result = PostParameter(url1);
                            result = (!string.IsNullOrWhiteSpace(lg_result) && lg_result.ToLower() == "true") ? 1 : 0;
                        }
                    }
                }
                #endregion
                //#region Auth Log
                //if (result == 1)
                //{
                //    _IAuthLogService = new AuthLogService();
                //    long _outMaxSlAuthLogDtl = 0;
                //    result = _IAuthLogService.AddAuthLog(_IUoW, null, _Customer, "ADD", "0001", "090103003", 1, "MTK_ACC_CUSTOMER_ACC_PROFILE", "AccountProfileId", _Customer.AccountProfileId, "mtaka", _outMaxSlAuthLogDtl, out _outMaxSlAuthLogDtl);
                //}
                //#endregion
                if (result == 1)
                {
                    _IUoW.Commit();
                }
                return(result);
            }
            catch (Exception ex)
            {
                _ObjErrorLogService = new ErrorLogService();
                _ObjErrorLogService.AddErrorLog(ex, string.Empty, "AddCustomer(obj)", string.Empty);
                return(0);
            }
        }
コード例 #4
0
 private void FirebaseAuthLink_FirebaseAuthRefreshed(object sender, FirebaseAuthEventArgs e)
 {
     AuthLog.AccessTokenRefreshed("Firebase");
     accessToken = e.FirebaseAuth.FirebaseToken;
 }