예제 #1
0
        public async Task MultipleRefreshesWork()
        {
            var api     = new OAuthTestApi(OAuthData.SignInDataWithRefresh);
            var account = await api.Authenticate();

            Assert.IsTrue(account.IsValid());
            await Task.Delay(6000);

            Assert.IsFalse(account.IsValid());


            await api.Authenticate();

            Assert.IsTrue(api.CurrentAccount.IsValid());

            await Task.Delay(6000);

            Assert.IsFalse(api.CurrentAccount.IsValid());


            await api.Get("test");

            Assert.IsTrue(api.CurrentAccount.IsValid());

            //Make sure Show authenticator was called
            Assert.IsTrue(api.CurrentShowAuthenticatorCallCount == 1);
        }
예제 #2
0
        public async Task AuthenticatedCallsSendAuthHeader()
        {
            var api     = new OAuthTestApi(OAuthData.SignInDataWithRefresh);
            var account = await api.Authenticate();

            Assert.IsTrue(account.IsValid());
            await api.Get("authenticated");
        }
예제 #3
0
        public async Task SigningIntoApiWorks()
        {
            var api     = new OAuthTestApi(OAuthData.SignInDataWithRefresh);
            var account = await api.Authenticate();

            Assert.IsTrue(account.IsValid());
            //Make sure Show authenticator was called
            Assert.IsTrue(api.CurrentShowAuthenticatorCallCount == 1);
        }
예제 #4
0
        public async Task TokensExpireAfterAuthentication()
        {
            var api     = new OAuthTestApi(OAuthData.SignInDataWithRefresh);
            var account = await api.Authenticate();

            Assert.IsTrue(account.IsValid());
            await Task.Delay(6000);

            Assert.IsFalse(account.IsValid());
        }
예제 #5
0
        public async Task RefreshTokenOnUnauthorized()
        {
            var api     = new OAuthTestApi(OAuthData.SignInBadAccessTokenRefresh);
            var account = await api.Authenticate();

            Assert.IsTrue((api.CurrentAccount as OAuthAccount).Token == "badAccessToken");
            Assert.IsTrue(account.IsValid());
            await api.Get("authenticated");

            Assert.IsTrue((api.CurrentAccount as OAuthAccount).Token == "accessToken");
        }
예제 #6
0
        public async Task AuthenticatedApiRequestsRefreshTokens()
        {
            var api     = new OAuthTestApi(OAuthData.SignInDataWithRefresh);
            var account = await api.Authenticate();

            Assert.IsTrue(account.IsValid());
            await Task.Delay(6000);

            Assert.IsFalse(account.IsValid());

            await api.Get("test");

            Assert.IsTrue(api.CurrentAccount.IsValid());
        }
예제 #7
0
        public async Task ApiRefreshesTokensOnAuthenticate()
        {
            var api     = new OAuthTestApi(OAuthData.SignInDataWithRefresh);
            var account = await api.Authenticate();

            Assert.IsTrue(account.IsValid());

            await Task.Delay(6000);

            Assert.IsFalse(account.IsValid());

            await api.Authenticate();

            Assert.IsTrue(api.CurrentAccount.IsValid());

            Assert.IsTrue(api.CurrentShowAuthenticatorCallCount == 1);
        }
예제 #8
0
        public async Task FailedRefreshRepromptsShowAuthenticator()
        {
            var api = new OAuthTestApi(OAuthData.SignInDataFailedRefresh);

            var account = await api.Authenticate();

            Assert.IsTrue(account.IsValid());

            await Task.Delay(6000);

            Assert.IsFalse(account.IsValid());

            await api.Authenticate();

            Assert.IsTrue(api.CurrentAccount.IsValid());

            Assert.IsTrue(api.CurrentShowAuthenticatorCallCount == 2);
        }
예제 #9
0
        public async Task LoadingApiRestoresTokens()
        {
            var api     = new OAuthTestApi(OAuthData.SignInDataWithRefresh);
            var account = await api.Authenticate();

            Assert.IsTrue(account.IsValid());

            Assert.IsTrue(api.CurrentShowAuthenticatorCallCount == 1);

            //Let tokens expire
            await Task.Delay(6000);

            Assert.IsFalse(account.IsValid());

            var api2     = new OAuthTestApi(OAuthData.SignInDataWithRefresh);
            var account2 = await api.Authenticate();

            Assert.IsTrue(account2.IsValid());

            Assert.IsTrue(api2.CurrentShowAuthenticatorCallCount == 0);
        }
예제 #10
0
        public async Task NonAuthenticatedCallsDoNotRefreshAccounts()
        {
            var api     = new OAuthTestApi(OAuthData.SignInDataWithRefresh);
            var account = await api.Authenticate();

            Assert.IsTrue(account.IsValid());
            await Task.Delay(6000);

            Assert.IsFalse(account.IsValid());


            await api.Authenticate();

            Assert.IsTrue(api.CurrentAccount.IsValid());

            await Task.Delay(6000);

            Assert.IsFalse(api.CurrentAccount.IsValid());


            await api.Get("test", authenticated : false);

            Assert.IsFalse(api.CurrentAccount.IsValid());
        }