public static SheetsService GetSheetsService(ClaimsPrincipal user)
 {
     return(new SheetsService(new BaseClientService.Initializer
     {
         HttpClientInitializer = CredentialService.GetCredentials(user, Scopes),
         ApplicationName = "creatingcompetitionlists",
     }));
 }
Ejemplo n.º 2
0
        public static void InitializeHttpHandlerResourceV3(CredentialService credentialService)
        {
            // Set up proxy handling for v3 sources.
            // We need to sync the v2 proxy cache and v3 proxy cache so that the user will not
            // get prompted twice for the same authenticated proxy.
            var v2ProxyCache = ProxyCache.Instance;

            NuGet.Protocol.Core.v3.HttpHandlerResourceV3.PromptForProxyCredentials = async(uri, proxy, cancellationToken) => {
                var v2Credentials = v2ProxyCache?.GetProxy(uri)?.Credentials;
                if (v2Credentials != null && proxy.Credentials != v2Credentials)
                {
                    // if cached v2 credentials have not been used, try using it first.
                    return(v2Credentials);
                }

                return(await credentialService
                       .GetCredentials(uri, proxy, isProxy : true, cancellationToken : cancellationToken));
            };

            NuGet.Protocol.Core.v3.HttpHandlerResourceV3.ProxyPassed = proxy => {
                // add the proxy to v2 proxy cache.
                v2ProxyCache?.Add(proxy);
            };

            NuGet.Protocol.Core.v3.HttpHandlerResourceV3.PromptForCredentials = async(uri, cancellationToken) => {
                // Get the proxy for this URI so we can pass it to the credentialService methods
                // this lets them use the proxy if they have to hit the network.
                var proxyCache = ProxyCache.Instance;
                var proxy      = proxyCache?.GetProxy(uri);

                return(await credentialService
                       .GetCredentials(uri, proxy : proxy, isProxy : false, cancellationToken : cancellationToken));
            };

            NuGet.Protocol.Core.v3.HttpHandlerResourceV3.CredentialsSuccessfullyUsed = (uri, credentials) => {
                NuGet.CredentialStore.Instance.Add(uri, credentials);
                NuGet.Configuration.CredentialStore.Instance.Add(uri, credentials);
            };
        }
		public static void InitializeHttpHandlerResourceV3 (CredentialService credentialService)
		{
			// Set up proxy handling for v3 sources.
			// We need to sync the v2 proxy cache and v3 proxy cache so that the user will not
			// get prompted twice for the same authenticated proxy.
			var v2ProxyCache = ProxyCache.Instance;
			NuGet.Protocol.Core.v3.HttpHandlerResourceV3.PromptForProxyCredentials = async (uri, proxy, cancellationToken) => {
				var v2Credentials = v2ProxyCache?.GetProxy (uri)?.Credentials;
				if (v2Credentials != null && proxy.Credentials != v2Credentials) {
					// if cached v2 credentials have not been used, try using it first.
					return v2Credentials;
				}

				return await credentialService
					.GetCredentials (uri, proxy, isProxy: true, cancellationToken: cancellationToken);
			};

			NuGet.Protocol.Core.v3.HttpHandlerResourceV3.ProxyPassed = proxy => {
				// add the proxy to v2 proxy cache.
				v2ProxyCache?.Add (proxy);
			};

			NuGet.Protocol.Core.v3.HttpHandlerResourceV3.PromptForCredentials = async (uri, cancellationToken) => {
				// Get the proxy for this URI so we can pass it to the credentialService methods
				// this lets them use the proxy if they have to hit the network.
				var proxyCache = ProxyCache.Instance;
				var proxy = proxyCache?.GetProxy (uri);

				return await credentialService
					.GetCredentials (uri, proxy: proxy, isProxy: false, cancellationToken: cancellationToken);
			};

			NuGet.Protocol.Core.v3.HttpHandlerResourceV3.CredentialsSuccessfullyUsed = (uri, credentials) => {
				NuGet.CredentialStore.Instance.Add (uri, credentials);
				NuGet.Configuration.CredentialStore.Instance.Add (uri, credentials);
			};
		}
Ejemplo n.º 4
0
        /// <summary>
        /// Executes the specified options.
        /// </summary>
        /// <param name="options">The options.</param>
        public override void Execute(Options options)
        {
            var credentials = CredentialService.GetCredentials();
            var user        = UserService.GetUser(options.UserId);

            if (user == null)
            {
                Out.WriteLine("Couldn't find user with id {0}.", options.UserId);

                return;
            }

            credentials.Name     = user.Name;
            credentials.JabberId = UserService.GetJabberIdForUser(user);

            CredentialService.SetCredentials(credentials);

            Out.WriteLine("Bot will use {0} ({1}).", credentials.Name, credentials.JabberId);
        }