Ejemplo n.º 1
0
        private static OAuth2AccessTokenResponse GetUserAccessToken(string cacheKey, SecurityTokens tokens, Uri hostUri, ClientConfiguration clientConfig)
        {
            var userAccessToken = TokenHelper.GetACSAccessTokens(tokens.RefreshToken, targetPrincipal, hostUri.Authority,
                                                                 tokens.Realm, tokens.ClientId, clientConfig.AcsClientConfig.ClientSecret);

            tokens.AccessToken        = userAccessToken.AccessToken;
            tokens.AccessTokenExpires = userAccessToken.ExpiresOn;
            StoreSecurityTokens(tokens, cacheKey);
            return(userAccessToken);
        }
        /// <summary>
        /// Saves the tokens to storage
        /// </summary>
        /// <param name="tokens">The tokens</param>
        /// <param name="cacheKey">The user's cache key</param>
        /// <param name="storageAccount">The storage account</param>
        /// <param name="storageKey">The storage account key</param>
        public static void StoreSecurityTokens(SecurityTokens tokens, string cacheKey, string storageAccount, string storageKey)
        {
            var containerName = tokens.ClientId.ToLowerInvariant();
            var container     = GetContainer(storageAccount, storageKey, containerName, true);

            if (container == null)
            {
                throw new Exception("Unable to get or create storage container.");
            }

            var blob = container.GetBlockBlobReference($"{cacheKey}/{SecurityTokensBlobName}");

            blob.UploadText((new JavaScriptSerializer()).Serialize(tokens));
        }
 /// <summary>
 /// Saves the tokens to storage based on the app's config file
 /// </summary>
 /// <param name="tokens">The tokens to save</param>
 /// <param name="cacheKey">The user's cache key</param>
 public static void StoreSecurityTokens(SecurityTokens tokens, string cacheKey)
 {
     StoreSecurityTokens(tokens, cacheKey, ConfigurationManager.AppSettings["ConfigurationStorageAccount"],
                         ConfigurationManager.AppSettings["ConfigurationStorageAccountKey"]);
 }