Exemplo n.º 1
0
        /// <summary>
        /// Stores the OAuth token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="clientSecret">The client secret.</param>
        /// <returns>
        /// A Task for async execution
        /// </returns>
        private async Task StoreOAuthToken(TokenResponse token, string clientSecret)
        {
            if (this._oauthFlowController.TokenResponse != null)
            {
                // Grab results
                this._oauthToken = token;
                this.ExtractTokenProperties();

#if NETFX_CORE
                // Encrypt to stop prying eyes on Win8
                string content = EncryptionHelper.Encrypt(token.ToJToken().ToString(), clientSecret, this.ClientId);
#else
                string content = token.ToJToken().ToString();
#endif
                // store results in isostorage
                await StorageHelper.WriteTextAsync(TokenCacheFile, content);
            }
        }
Exemplo n.º 2
0
        public void TestPropertiesAndSerialisation()
        {
            TokenResponse token = new TokenResponse()
            {
                AccessToken  = "token",
                ExpiresIn    = 120,
                RefreshToken = "refresh",
                Territory    = "gb",
                UserId       = Guid.NewGuid()
            };

            JToken json = token.ToJToken();

            TokenResponse rehydrated = TokenResponse.FromJToken(json);

            Assert.AreEqual(token.AccessToken, rehydrated.AccessToken, "Expected AccessToken to match");
            Assert.AreEqual(token.ExpiresIn, rehydrated.ExpiresIn, "Expected ExpiresIn to match");
            Assert.AreEqual(token.RefreshToken, rehydrated.RefreshToken, "Expected RefreshToken to match");
            Assert.AreEqual(token.Territory, rehydrated.Territory, "Expected Territory to match");
            Assert.AreEqual(token.UserId, rehydrated.UserId, "Expected UserId to match");
        }
Exemplo n.º 3
0
        public void TestPropertiesAndSerialisation()
        {
            TokenResponse token = new TokenResponse()
            {
                AccessToken = "token",
                ExpiresIn = 120,
                RefreshToken = "refresh",
                Territory = "gb",
                UserId = Guid.NewGuid()
            };

            JToken json = token.ToJToken();

            TokenResponse rehydrated = TokenResponse.FromJToken(json, null);

            Assert.AreEqual(token.AccessToken, rehydrated.AccessToken, "Expected AccessToken to match");
            Assert.AreEqual(token.ExpiresIn, rehydrated.ExpiresIn, "Expected ExpiresIn to match");
            Assert.AreEqual(token.RefreshToken, rehydrated.RefreshToken, "Expected RefreshToken to match");
            Assert.AreEqual(token.Territory, rehydrated.Territory, "Expected Territory to match");
            Assert.AreEqual(token.UserId, rehydrated.UserId, "Expected UserId to match");
        }