예제 #1
0
        public void DeleteCredentials()
        {
            var account = _accountStore.FindAccountsForService(_AppName).FirstOrDefault();

            if (account != null)
            {
                _accountStore.Delete(account, _AppName);
            }
        }
예제 #2
0
 public async Task <bool> HasAccessToken(string clientId, string serviceId, CancellationToken cancellationToken)
 {
     return(await Task.Factory.StartNew(() =>
     {
         var normalizedUsername = NormalizeClientId(clientId);
         var account = _accountStore.FindAccountsForService(serviceId).FirstOrDefault(a => string.Equals(a.Username, normalizedUsername,
                                                                                                         StringComparison.CurrentCultureIgnoreCase));
         return account != null;
     }, cancellationToken).ConfigureAwait(false));
 }
예제 #3
0
        /// <summary>
        /// Adds a credential to the Credential Locker.
        /// </summary>
        /// <param name="resource">The resource for which the credentials are used.</param>
        /// <param name="userName">The user name that must be present in the credentials.</param>
        /// <param name="password">The password for the created credentials.</param>
        /// <exception cref="ArgumentNullException">Dispatched when <paramref name="resource"/>, <paramref name="userName"/> or
        /// <paramref name="password"/> is <c>Null</c>
        /// </exception>
        public bool CreateAccount(string resource, string userName, string password)
        {
            if (string.IsNullOrEmpty(resource))
            {
                throw new ArgumentNullException(nameof(resource), "The argument is null");
            }
            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException(nameof(userName), "The argument is null");
            }
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException(nameof(password), "The argument is null");
            }

            try
            {
                account = new Account {
                    Username = userName
                };
                account.Properties.Add(resource, password);
                vault.Save(account, AppName);

                var lista = vault.FindAccountsForService(AppName);

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
예제 #4
0
        public Authenticator()
        {
            accountStore = AccountStore.Create();
            var accounts = accountStore.FindAccountsForService(CREDENTIALS_NAME);

            account = accounts.FirstOrDefault();
        }
예제 #5
0
 public LoginPage()
 {
     InitializeComponent();
     Init();
     store   = AccountStore.Create();
     account = store.FindAccountsForService(AppAuthenParameters.AppName).FirstOrDefault();
 }
예제 #6
0
        private void GoogleButton_TouchUpInside(object sender, EventArgs e)
        {
            store = AccountStore.Create();
            string clientId    = "702647090904-45v1qskciukrf1ojmnotljnmk9k7ph23.apps.googleusercontent.com";
            string redirectUri = "com.buptis.app.ios:/oauth2redirect";

            account = store.FindAccountsForService("Buptis").FirstOrDefault();
            var authenticator = new OAuth2Authenticator(
                clientId,
                null,
                "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile", //https://www.googleapis.com/auth/userinfo.profile //SADECE EMAİL GELİYOR BAK BUNA
                new Uri("https://accounts.google.com/o/oauth2/auth"),
                new Uri(redirectUri),
                new Uri("https://www.googleapis.com/oauth2/v4/token"),
                null,
                true);

            authenticator.Completed += OnAuthCompleted;
            authenticator.Error     += OnAuthError;

            //GoogleVC = authenticator.GetUI();
            //this.PresentViewController(GoogleVC, true, null);

            AuthenticationState.Authenticator = authenticator;

            var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();

            presenter.Login(authenticator);
        }
예제 #7
0
        public static async Task <bool> ValidateLoginAsync()
        {
            AccountStore accountStore = AccountStore.Create();
            Account      account      = accountStore.FindAccountsForService(_servideId).SingleOrDefault();

            if (account != null)
            {
                bool result = await RestService.Instance.ValidateTokenAsync(account.Properties["Token"]);

                if (result)
                {
                    Account = new AuthModel
                    {
                        Token           = account.Properties["Token"],
                        ExpiresIn       = account.Properties["ExpiresIn"],
                        IdUser          = account.Properties["IdUser"],
                        UserName        = account.Properties["UserName"],
                        UserPhone       = account.Properties["UserPhone"],
                        IdSocialNetwork = account.Properties["IdSocialNetwork"],
                        AuthType        = (AuthType)Enum.Parse(typeof(AuthType), account.Properties["AuthType"]),
                        ExpirationDate  = DateTime.Now + TimeSpan.FromSeconds(Convert.ToDouble(account.Properties["ExpiresIn"]))
                    };
                }

                return(result);
            }

            return(false);
        }
예제 #8
0
        public string Fetch(string keyString)
        {
            try
            {
                var fetchedAccount = _accountStore.FindAccountsForService(_serviceIdstring).FirstOrDefault();
                if (fetchedAccount == null)
                {
                    return(null);
                }

                _account = fetchedAccount;

                var hasKey = _account.Properties?.ContainsKey(keyString);
                if (hasKey == false)
                {
                    return(null);
                }

                var valueString = _account.Properties?[keyString];
                return(valueString);
            }
            catch (AccountStoreException exception)
            {
                Console.WriteLine(exception.StackTrace);
                return(null);
            }
        }
예제 #9
0
        private void signinGoogle_Clicked(System.Object sender, System.EventArgs e)
        {
            string clientId    = null;
            string redirectUrl = null;

            switch (Device.RuntimePlatform)
            {
            case Device.Android:
                clientId    = Constants.AndroidClientId;
                redirectUrl = Constants.AndroidRedirectUrl;
                break;
            }

            account = store.FindAccountsForService(Constants.AppName).FirstOrDefault();

            var authenticator = new OAuth2Authenticator(
                clientId,
                null,
                Constants.Scope,
                new Uri(Constants.AuthorizeUrl),
                new Uri(redirectUrl),
                new Uri(Constants.AccessTokenUrl),
                null,
                true);

            authenticator.Completed += OnAuthCompleted;
            authenticator.Error     += OnAuthError;

            AuthenticationState.Authenticator = authenticator;

            var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();

            presenter.Login(authenticator);
        }
예제 #10
0
        public IEnumerable <LeanKitAccount> GetAll()
        {
            var accounts = _accountStore.FindAccountsForService(_applicationSettings.AppName);

            var lkAccounts = new List <LeanKitAccount>();

            foreach (var account in accounts)
            {
                long userId;
                if (long.TryParse(account.Username, out userId))
                {
                    var organization      = account.Properties["Organization"].FromJson <OrganizationLink>();
                    var authorizationType = (AuthorizationType)Enum.Parse(typeof(AuthorizationType), account.Properties["AuthorizationType"]);
                    lkAccounts.Add(new LeanKitAccount(userId,
                                                      account.Properties["UserName"],
                                                      account.Properties["Secret"],
                                                      authorizationType,
                                                      organization,
                                                      account.Properties["AvatarUrl"]));
                }
                else
                {
                    //delete the legacy accounts when username was the account "key"
                    _accountStore.Delete(account, _applicationSettings.AppName);
                }
            }

            return(lkAccounts);
        }
예제 #11
0
        public LoginPage()
        {
            InitializeComponent();

            store   = AccountStore.Create();
            account = store.FindAccountsForService(Constants.AppName).FirstOrDefault();
        }
예제 #12
0
        public AuthToken getToken()
        {
            var account = store.FindAccountsForService(context).FirstOrDefault();

            if (account == null)
            {
                return(null);
            }
            else
            {
                var token = new AuthToken();
                token.accessToken = account.Username;

                if (account.Properties.ContainsKey("expires_in"))
                {
                    token.expiresIn = account.Properties ["expires_in"];
                }
                if (account.Properties.ContainsKey("token_type"))
                {
                    token.tokenType = account.Properties ["token_type"];
                }
                if (account.Properties.ContainsKey("scope"))
                {
                    token.scope = account.Properties ["scope"];
                }
                if (account.Properties.ContainsKey("refresh_token"))
                {
                    token.refreshToken = account.Properties ["refresh_token"];
                }
                return(token);
            }
        }
예제 #13
0
 public LoginViewModel()
 {
     User    = new UserInfo();
     store   = AccountStore.Create();
     account = store.FindAccountsForService(Constants.AppName).FirstOrDefault();
     //OnGoogleButtonCommand = new Command(OnGoogleButtonClick);
 }
예제 #14
0
 static AuthenticationService()
 {
     TokenEndpoint = new Uri($"{App.Settings.Identity.Url}connect/token");
     AccountStore  = AccountStore.Create();
     AuthAccount   = AccountStore
                     .FindAccountsForService(App.Settings.ServiceId)
                     .FirstOrDefault();
 }
예제 #15
0
        public AccountService(HttpClient client)
        {
            _accountRepository      = new AccountRepository(client);
            _accountTokenRepository = new AccountTokenRepository(client);

            AccountStore   = AccountStore.Create();
            XamarinAccount = AccountStore.FindAccountsForService(Constants.AppName).FirstOrDefault();
        }
예제 #16
0
 public Login()
 {
     InitializeComponent();
     // objetos do tipo Account para um serviço podem ser recuperados
     // chamando o método FindAccountsForService, que retorna uma coleção
     // de objectos Account, com o primeiro item sendo o procurado.
     store   = AccountStore.Create();
     account = store.FindAccountsForService(Constants.AppName).FirstOrDefault();
 }
예제 #17
0
        public LoginPage()
        {
            InitializeComponent();
            _store   = AccountStore.Create();
            _account = _store.FindAccountsForService(Constants.AppName).FirstOrDefault();

            btnLogin.Clicked         += OnAuth;
            btnFacebookLogin.Clicked += OnFacebookLogin;
        }
예제 #18
0
        public static void DeleteAccount()
        {
            AccountStore accountStore = AccountStore.Create();
            Account      account      = accountStore.FindAccountsForService(_servideId).SingleOrDefault();

            if (account != null)
            {
                accountStore.Delete(account, _servideId);
            }
        }
예제 #19
0
        public Account CheckForAccount()
        {
            AccountStore store = GetAccountStore();

            var accounts = store.FindAccountsForService(serviceID);

            //store.Delete(accounts.FirstOrDefault(), serviceID);

            return(accounts.FirstOrDefault());
        }
예제 #20
0
        void OnGoogleLoginClicked(object sender, EventArgs e)
        {
            string clientId    = null;
            string redirectUri = null;

            //Xamarin.Auth.CustomTabsConfiguration.CustomTabsClosingMessage = null;

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                clientId    = Constants.GoogleiOSClientId;
                redirectUri = Constants.GoogleiOSRedirectUrl;
                break;

            case Device.Android:
                clientId    = Constants.GoogleAndroidClientId;
                redirectUri = Constants.GoogleAndroidRedirectUrl;
                break;
            }

            account = store.FindAccountsForService(Constants.AppName).FirstOrDefault();

            var authenticator = new OAuth2Authenticator(
                clientId,
                null,
                Constants.GoogleScope,
                new Uri(Constants.GoogleAuthorizeUrl),
                new Uri(redirectUri),
                new Uri(Constants.GoogleAccessTokenUrl),
                null,
                true);

            authenticator.Completed += OnAuthCompleted;
            authenticator.Error     += OnAuthError;

            AuthenticationState.Authenticator = authenticator;

            var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();

            presenter.Login(authenticator);
            btnGoogle.Text      = "Authenticating...";
            btnGoogle.IsEnabled = false;
        }
        private Task <AccessToken> GetAccessToken(string normalizedUsername, string serviceId, CancellationToken cancellationToken)
        {
            return(Task.Factory.StartNew(() =>
            {
                var account = _accountStore.FindAccountsForService(serviceId)
                              .First(a => string.Equals(a.Username, normalizedUsername, StringComparison.CurrentCultureIgnoreCase));

                return new AccessToken(account.Properties);
            }, cancellationToken));
        }
예제 #22
0
        protected override void ClearCredentials()
        {
            AccountStore          acStore  = AccountStore.Create(context);
            IEnumerable <Account> accounts = acStore.FindAccountsForService(SERVICE_ID);

            foreach (Account account in accounts)
            {
                acStore.Delete(account, SERVICE_ID);
            }
            base.ClearCredentials();
        }
예제 #23
0
        public App()
        {
            InitializeComponent();
            accountStore = AccountStore.Create();
            account      = accountStore.FindAccountsForService(APP_NAME).FirstOrDefault();
            MainPage     = new MainPage();

            //App.DB.Create(new QnectMe.Models.Account() { Name = "Art James", Number = "111-123-123", LI = "mariam-antonyan-a0a35b104", FB = "Mete0rka", Company =  "Apple", Email =  "*****@*****.**", Skype =  "MySkypeID" });
            //App.DB.Create(new QnectMe.Models.Account() { Name = "Bob Fill", Number = "222-3242-2432", LI = "mohammad-sadegh-dabestani-51b63587", FB = "flogger.morozov", Company = "Nokia", Email = "*****@*****.**", Skype = "MySkypeID" });
            //App.DB.Create(new QnectMe.Models.Account() { Name = "Gyn Man", Number = "333-23423-2423", LI = "александр-челомбитько-536a85b3", FB = "SergeySA81", Company = "UMC", Email = "*****@*****.**", Skype = "MySkypeID" });
        }
 public ArtportalenAccountStorage(ICurrentUser currentUser)
 {
     _currentUser = currentUser;
     #if __ANDROID__
     _accountStore = AccountStore.Create(Forms.Context);
     #endif
     #if __IOS__
     _accountStore = AccountStore.Create();
     #endif
     _account = _accountStore.FindAccountsForService(ServiceId).FirstOrDefault(a => a.Username == _currentUser.Id);
 }
예제 #25
0
        Account GetAccountFromStore(AccountStore store, string username)
        {
            if (store == null || username == null)
            {
                return(null);
            }

            var accounts = store.FindAccountsForService(serviceID);

            return(accounts.FirstOrDefault(a => a.Username == username));
        }
        public ArtportalenAccountStorage(ICurrentUser currentUser)
        {
            _currentUser = currentUser;
#if __ANDROID__
            _accountStore = AccountStore.Create(Forms.Context);
#endif
#if __IOS__
            _accountStore = AccountStore.Create();
#endif
            _account = _accountStore.FindAccountsForService(ServiceId).FirstOrDefault(a => a.Username == _currentUser.Id);
        }
예제 #27
0
        public Login()
        {
            InitializeComponent();
            var facebook = botonFacebook;
            var google   = botonGoogle;

            store = AccountStore.Create();
            facebook.GestureRecognizers.Add(new TapGestureRecognizer(loginFacebook));
            google.GestureRecognizers.Add(new TapGestureRecognizer(GoogleLoginClicked));

            account = store.FindAccountsForService(Constants.AppName).FirstOrDefault();
        }
예제 #28
0
        public MainPage()
        {
            InitializeComponent();

            implicitButton.Clicked          += ImplicitButtonClicked;
            authorizationCodeButton.Clicked += AuthorizationCodeButtonClicked;
            getProfileButton.Clicked        += GetProfileButtonClicked;
            refreshButton.Clicked           += RefreshButtonClicked;

            store   = AccountStore.Create();
            account = store.FindAccountsForService(ServiceId).FirstOrDefault();
        }
예제 #29
0
        public Login()
        {
            InitializeComponent();
            viewModel           = new LoginViewModel();
            this.BindingContext = viewModel;

            // objetos do tipo Account para um serviço podem ser recuperados chamando o método
            // FindAccountsForService. O método retorna uma coleção IEnumerable de objectos Account,
            // com o primeiro item sendo o Account procurado.
            store   = AccountStore.Create();
            account = store.FindAccountsForService(Constants.AppName).FirstOrDefault();
        }
        public void RemoveTokenFromSecureStore()
        {
            var accounts = AccountStore.FindAccountsForService("tasklist");

            if (accounts != null)
            {
                foreach (var acct in accounts)
                {
                    AccountStore.Delete(acct, "tasklist");
                }
            }
        }
예제 #31
0
        public void RemoveTokenFromSecureStore()
        {
            var accounts = AccountStore.FindAccountsForService(Locations.AppName);

            if (accounts != null)
            {
                foreach (var acct in accounts)
                {
                    AccountStore.Delete(acct, Locations.AppName);
                }
            }
        }
예제 #32
0
 public CredentialStore()
 {
     store = AccountStore.Create();
     var records = store.FindAccountsForService (context);
 }