コード例 #1
0
ファイル: AuthenticationService.cs プロジェクト: rubit0/YoApp
        /// <summary>
        /// Request a new bearer token and store it on the local Account.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns>Returns success state</returns>
        public static async Task <bool> RequestToken(string username, string password)
        {
            var authenticator = new OAuth2PasswordCredentialsAuthenticator(TokenEndpoint);

            authenticator.SetCredentials(username, password);

            try
            {
                var account = await authenticator.SignInAsync();

                if (account == null)
                {
                    return(false);
                }

                account.Properties.Add("password", password);
                account.Properties.Add("date", DateTime.Now.ToString());

                await AccountStore.SaveAsync(account, App.Settings.ServiceId);

                AuthAccount = account;
                OnTokenUpdated?.Invoke(null, (string)account.Properties["access_token"]);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #2
0
        public void AuthenticatorConstructorWithCredentialsGeneratesFields()
        {
            var tokenEndpoint = new Uri("https://companistawebtesting.azurewebsites.net/Token");
            var auth          = new OAuth2PasswordCredentialsAuthenticator(tokenEndpoint);

            auth.SetCredentials("Bill", "Abc_123");

            Assert.IsTrue(auth.Fields.Count > 1);
        }
コード例 #3
0
        public void BasicFailedAuthenticationFlow()
        {
            var auth = new OAuth2PasswordCredentialsAuthenticator(new Uri("http://www.google.com"));

            auth.SetCredentials("Bob", "strongedpassword");
            var errorFired = false;

            auth.Error     += (obj, args) => errorFired = true;
            auth.Completed += (obj, args) => Assert.Fail("Complete should not be rised on failure");

            var result = auth.SignInAsync().Result;

            Assert.IsFalse(auth.HasCompleted);
            Assert.IsTrue(errorFired);
        }
コード例 #4
0
        public void BasicValidAuthenticationFlow()
        {
            var completeFired = false;
            var tokenEndpoint = new Uri("https://companistawebtesting.azurewebsites.net/Token");

            var auth = new OAuth2PasswordCredentialsAuthenticator(tokenEndpoint);

            auth.SetCredentials("Bill", "Abc_123");
            auth.Error     += (obj, args) => Assert.Fail("Error should not be rised on success");
            auth.Completed += (obj, args) => completeFired = args.IsAuthenticated;


            var account = auth.SignInAsync().Result;

            Assert.AreEqual(tokenEndpoint, auth.AccessTokenUrl);
            Assert.IsTrue(auth.HasCompleted);
            Assert.IsTrue(completeFired);
            Assert.IsNotNull(account);
        }
コード例 #5
0
        public void ExceptionMessageIsNotNull()
        {
            var auth = new OAuth2PasswordCredentialsAuthenticator(new Uri("https://Google.com"));

            auth.SetCredentials("Bill", "Abc_123");

            var completeFired = false;
            var message       = string.Empty;

            auth.Error += (obj, args) =>
            {
                completeFired = true;
                message       = args.Message;
            };

            var account = auth.SignInAsync().Result;

            Assert.IsTrue(completeFired);
            Assert.IsNotNull(message);
        }
コード例 #6
0
        public AuthDialogPage(OAuth2PasswordCredentialsAuthenticator authenticator, AuthPageConfiguration authPageConfiguration = null)
        {
            if (authenticator == null)
            {
                throw new ArgumentNullException(nameof(authenticator), "You must provide an anthenticator");
            }

            if (authPageConfiguration == null)
            {
                authPageConfiguration = new AuthPageConfiguration();
            }

            _authPageConfiguration    = authPageConfiguration;
            _authenticator            = authenticator;
            _authenticator.Completed += AuthenticatorOnCompleted;
            _authenticator.Error     += AuthenticatorOnError;

            InitializeComponent();
            AuthFieldsToEntries();
            ConfigurePage();

            _authenticationBehaviour = ControllerBag.GetBehaviour <AuthenticationBehaviour>();
        }
コード例 #7
0
 public void ThrowsExeptionOnNullUri()
 {
     var auth = new OAuth2PasswordCredentialsAuthenticator(null);
 }