Example #1
0
        /// <summary>
        /// Attempt to re-query the credentials for the specified URI
        /// </summary>
        /// <param name="targetChannel">The web channel to update credentials for</param>
        /// <param name="forceUpdate">True to force a requery to the user even if they previously canceled requesting credentials</param>
        public static bool UpdateCredentials(WebChannel targetChannel, bool forceUpdate)
        {
            if (targetChannel == null)
            {
                throw new ArgumentNullException(nameof(targetChannel));
            }

            return(UpdateCredentials(GetEntryUri(targetChannel), Guid.Empty, forceUpdate));
        }
Example #2
0
 internal HubConnectionStatus(ServerConfiguration configuration, WebChannel channel, HubRepository repository, bool isValid, HubStatus status, string message)
 {
     Configuration = configuration;
     Channel       = channel;
     Repository    = repository;
     Status        = status;
     Message       = message;
     IsValid       = isValid;
 }
Example #3
0
        /// <summary>
        /// Perform a logout on the supplied channel
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="client"></param>
#pragma warning disable 1998
        async Task IWebAuthenticationProvider.Logout(WebChannel channel, HttpClient client)
#pragma warning restore 1998
        {
            //we have to always use a lock when handling the access token.
            lock (m_Lock)
            {
                m_AccessToken = null;
                System.Threading.Monitor.PulseAll(m_Lock);
            }
        }
Example #4
0
        /// <summary>
        /// Perform a login on the supplied channel
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="client"></param>
        async Task IWebAuthenticationProvider.Login(WebChannel channel, HttpClient client)
        {
            //we need to get the access token for our repository id
            string requestUrl = string.Format("Repositories/{0}/AccessToken.bin", RepositoryId);

            var accessToken = await client.GetStringAsync(requestUrl).ConfigureAwait(false);

            lock (m_Lock)
            {
                //and here we WOULD decrypt the access token if it was encrypted
                m_AccessToken = accessToken;
                System.Threading.Monitor.PulseAll(m_Lock);
            }
        }
Example #5
0
        /// <summary>
        /// Create a web channel to the specified server configuration.  Low level primitive that does no redirection.
        /// </summary>
        private static WebChannel CreateChannel(ServerConfiguration configuration)
        {
            WebChannel channel;

            if (configuration.UseGibraltarService)
            {
                channel = new WebChannel(Logger, true, SdsServerName, String.Format(SdsEntryPath, configuration.CustomerName), ClientProtocolVersion);
            }
            else
            {
                //we need to create the right application base directory to get into Hub.
                string entryPath = EffectiveApplicationBaseDirectory(configuration.ApplicationBaseDirectory, configuration.Repository);

                //and now we can actually create the channel!  Yay!
                channel = new WebChannel(Logger, configuration.UseSsl, configuration.Server, configuration.Port, entryPath, ClientProtocolVersion);
            }

            return(channel);
        }
Example #6
0
        /// <summary>
        /// Perform per-request authentication processing.
        /// </summary>
        /// <param name="channel">The channel object</param>
        /// <param name="client">The web client that is about to be used to execute the request.  It can't be used by the authentication provider to make requests.</param>
        /// <param name="request">The request that is about to be sent</param>
        /// <param name="resourceUrl">The resource URL (with query string) specified by the client.</param>
        /// <param name="requestSupportsAuthentication">Indicates if the request being processed supports authentication or not.</param>
        /// <remarks>If the request doesn't support authentication, it's a best practice to not provide any authentication information.</remarks>
        void IWebAuthenticationProvider.PreProcessRequest(WebChannel channel, HttpClient client, HttpRequestMessage request, string resourceUrl, bool requestSupportsAuthentication)
        {
            //figure out the effective relative URL.
            string fullUrl = resourceUrl;

            if (client.BaseAddress != null)
            {
                fullUrl = client.BaseAddress + resourceUrl;
            }

            var clientUri = new Uri(fullUrl);

            //we're doing sets not adds to make sure we overwrite any existing value.
            if (requestSupportsAuthentication)
            {
                request.Headers.TryAddWithoutValidation(AuthorizationHeader, AuthorizationPrefix + ": " + CalculateHash(clientUri.PathAndQuery));
                request.Headers.Add(ClientRepositoryHeader, RepositoryId.ToString());
            }
            else
            {
                //remove our repository header.
                request.Headers.Remove(ClientRepositoryHeader);
            }
        }
Example #7
0
 /// <summary>
 /// Get credentials for the specified URL target and repository information
 /// </summary>
 /// <param name="targetChannel">The web channel representing the endpoint that the credentials are for</param>
 /// <param name="useApiKey">True if an API key was used to originally set up the connection</param>
 /// <param name="repositoryId">The owner Id to specify to the server (for example repository Id)</param>
 /// <param name="keyContainerName">The name of the key container to retrieve the private key from</param>
 /// <param name="useMachineStore">True to use the machine store instead of the user store for the digital certificate</param>
 /// <returns></returns>
 /// <remarks>If existing credentials are available they will be provided, otherwise null will be returned.
 /// This method is Multithread safe.</remarks>
 public static IWebAuthenticationProvider GetCachedCredentials(WebChannel targetChannel, bool useApiKey, Guid repositoryId, string keyContainerName, bool useMachineStore)
 {
     return(GetCachedCredentials(GetEntryUri(targetChannel), useApiKey, repositoryId, keyContainerName, useMachineStore));
 }
Example #8
0
 /// <summary>
 /// Request user credentials, coordinating between multiple threads looking for the same credentials.
 /// </summary>
 /// <remarks>Unlike Update, this will not re-prompt the user if they previously declined to provide credentials</remarks>
 public static bool RequestCredentials(WebChannel targetChannel, Guid repositoryId)
 {
     return(RequestCredentials(GetEntryUri(targetChannel), repositoryId));
 }
Example #9
0
 /// <summary>
 /// Determine the entry URI used for credential keys
 /// </summary>
 public static string GetEntryUri(WebChannel channel)
 {
     return(GetEntryUri(channel.HostName));
 }