private static async Task TryAuthentication() { var channel = GrpcChannel.ForAddress("https://localhost:6001"); var authorizationClient = new AuthorizationServiceClient(channel); var registerIdentity = new RegisterParameterRequest() { UserName = "******", Password = "******" }; await authorizationClient.RegisterAsync(registerIdentity); Console.WriteLine("\nRegistration done"); await authorizationClient.LogoutAsync(new Empty()); Console.WriteLine("\nLogout done"); var loginIdentity = new LoginRequest() { UserName = "******", Password = "******" }; LoginResult login = await authorizationClient.LoginAsync(loginIdentity); Console.WriteLine("\nLogin done"); }
protected override async ValueTask <ICacheService> CreateCacheServiceAsync(CancellationToken cancellationToken) { // Directly access VS' CacheService through their library and not as a brokered service. Then create our // wrapper CloudCacheService directly on that instance. var authorizationServiceClient = new AuthorizationServiceClient(new AuthorizationServiceMock()); var solutionService = new SolutionServiceMock(); var fileSystem = new FileSystemServiceMock(); var serviceBroker = new ServiceBrokerMock() { BrokeredServices = { { VisualStudioServices.VS2019_10.SolutionService.Moniker, solutionService }, { VisualStudioServices.VS2019_10.FileSystem.Moniker, fileSystem }, { FrameworkServices.Authorization.Moniker, new AuthorizationServiceMock() }, }, }; var someContext = new CacheContext { RelativePathBase = _relativePathBase }; var pool = new SqliteConnectionPool(); var activeContext = await pool.ActivateContextAsync(someContext, default); var cacheService = new CacheService(activeContext, serviceBroker, authorizationServiceClient, pool); return(cacheService); }
public async Task ProfferServicesAsync_WithAuthorizingBrokeredServiceFactoryService_ProffersService( ServiceRpcDescriptor serviceDescriptor, Type serviceType) { using (await NuGetBrokeredServiceFactory.ProfferServicesAsync(this)) { Assert.True( _authorizingServiceFactories.TryGetValue( serviceDescriptor, out AuthorizingBrokeredServiceFactory factory)); using (var authorizationServiceClient = new AuthorizationServiceClient(new MockAuthorizationService())) { object service = await factory( serviceDescriptor.Moniker, default(ServiceActivationOptions), new MockServiceBroker(), authorizationServiceClient, CancellationToken.None); using (service as IDisposable) { Assert.IsType(serviceType, service); } } } }
//<Authorization> // <Action>ReturnChangeUserPassword</Action> // <UserId></UserId> // <Application></Application> // <Message></Message> //</Authorization>"; public Hashtable ChangeUserPassword(string _userId, string _oldpassword, string _newpassword, string _application) { try { AuthorizationServiceClient client = new AuthorizationServiceClient(); string _ResultXmlText = client.ChangeUserPassword(CreateParamter_ChangeUserPassword(_userId, _oldpassword, _newpassword, _application)); //Parse XmlDocument doc = new XmlDocument(); Hashtable result = new Hashtable(); doc.LoadXml(_ResultXmlText); result["Action"] = doc.SelectSingleNode("/Authorization/Action").InnerText.ToString(); result["UserId"] = doc.SelectSingleNode("/Authorization/UserId").InnerText.ToString(); result["Application"] = doc.SelectSingleNode("/Authorization/Application").InnerText.ToString(); result["Message"] = doc.SelectSingleNode("/Authorization/Message").InnerText.ToString(); return(result); } catch (UtilException ex) { throw ex; } catch (Exception ex) { throw new UtilException(ex.Message, ex); } }
private NuGetPackageSearchService SetupSearchService() { ClearSearchCache(); var packageSourceProvider = new Mock <IPackageSourceProvider>(); packageSourceProvider.Setup(x => x.LoadPackageSources()).Returns(new List <PackageSource> { _sourceRepository.PackageSource }); var sourceRepositoryProvider = new Mock <ISourceRepositoryProvider>(); sourceRepositoryProvider.Setup(x => x.CreateRepository(It.IsAny <PackageSource>())).Returns(_sourceRepository); sourceRepositoryProvider.Setup(x => x.CreateRepository(It.IsAny <PackageSource>(), It.IsAny <FeedType>())).Returns(_sourceRepository); sourceRepositoryProvider.SetupGet(x => x.PackageSourceProvider).Returns(packageSourceProvider.Object); var solutionManager = new Mock <IVsSolutionManager>(); solutionManager.SetupGet(x => x.SolutionDirectory).Returns("z:\\SomeRandomPath"); var settings = new Mock <ISettings>(); var deleteOnRestartManager = new Mock <IDeleteOnRestartManager>(); _componentModel.Setup(x => x.GetService <IDeleteOnRestartManager>()).Returns(deleteOnRestartManager.Object); _componentModel.Setup(x => x.GetService <IVsSolutionManager>()).Returns(solutionManager.Object); _componentModel.Setup(x => x.GetService <ISolutionManager>()).Returns(solutionManager.Object); _componentModel.Setup(x => x.GetService <ISettings>()).Returns(settings.Object); _componentModel.Setup(x => x.GetService <ISourceRepositoryProvider>()).Returns(sourceRepositoryProvider.Object); _componentModel.Setup(x => x.GetService <INuGetProjectContext>()).Returns(new Mock <INuGetProjectContext>().Object); _componentModel.Setup(x => x.GetService <IRestoreProgressReporter>()).Returns(new Mock <IRestoreProgressReporter>().Object); var service = Package.GetGlobalService(typeof(SAsyncServiceProvider)) as IAsyncServiceProvider; ServiceLocator.InitializePackageServiceProvider(service); var serviceActivationOptions = default(ServiceActivationOptions); var serviceBroker = new Mock <IServiceBroker>(); var authorizationService = new AuthorizationServiceClient(Mock.Of <IAuthorizationService>()); var sharedState = new SharedServiceState(sourceRepositoryProvider.Object); var projectManagerService = new Mock <INuGetProjectManagerService>(); projectManagerService.Setup(x => x.GetInstalledAndTransitivePackagesAsync( It.IsAny <IReadOnlyCollection <string> >(), It.IsAny <CancellationToken>())) .Returns(new ValueTask <IInstalledAndTransitivePackages>(new InstalledAndTransitivePackages(_installedPackages.ToList(), _transitivePackages.ToList()))); projectManagerService.Setup(x => x.GetPackageFoldersAsync( It.IsAny <IReadOnlyCollection <string> >(), It.IsAny <CancellationToken>())) .Returns(new ValueTask <IReadOnlyCollection <string> >(Array.Empty <string>())); #pragma warning disable ISB001 // Dispose of proxies serviceBroker.Setup(x => x.GetProxyAsync <INuGetProjectManagerService>( NuGetServices.ProjectManagerService, It.IsAny <ServiceActivationOptions>(), It.IsAny <CancellationToken>())) .Returns(new ValueTask <INuGetProjectManagerService>(projectManagerService.Object)); #pragma warning restore ISB001 // Dispose of proxies return(new NuGetPackageSearchService(serviceActivationOptions, serviceBroker.Object, authorizationService, sharedState)); }
public AuthorizationController() { #if DEBUG AppContext.SetSwitch( "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); #endif var channel = GrpcChannel.ForAddress("http://localhost:6000"); _client = new AuthorizationServiceClient(channel); }
private ValueTask <object> CreateSourceProviderServiceAsync( ServiceMoniker moniker, ServiceActivationOptions options, IServiceBroker serviceBroker, AuthorizationServiceClient authorizationServiceClient, CancellationToken cancellationToken) { #pragma warning disable CA2000 // Dispose objects before losing scope return(new ValueTask <object>(new NuGetSourcesService(options, serviceBroker, authorizationServiceClient))); #pragma warning restore CA2000 // Dispose objects before losing scope }
public NuGetPackageSearchService(ServiceActivationOptions options, IServiceBroker sb, AuthorizationServiceClient ac, ISharedServiceState state) { _options = options; _serviceBroker = sb; _authorizationServiceClient = ac; _sharedServiceState = state; _packagesFolderLocalRepositoryLazy = new Microsoft.VisualStudio.Threading.AsyncLazy <SourceRepository>( GetPackagesFolderSourceRepositoryAsync, NuGetUIThreadHelper.JoinableTaskFactory); _globalPackageFolderRepositoriesLazy = new Microsoft.VisualStudio.Threading.AsyncLazy <IReadOnlyList <SourceRepository> >( GetGlobalPackageFolderRepositoriesAsync, NuGetUIThreadHelper.JoinableTaskFactory); }
public NuGetPackageFileService( ServiceActivationOptions options, IServiceBroker serviceBroker, AuthorizationServiceClient authorizationServiceClient, INuGetTelemetryProvider nuGetTelemetryProvider) { _options = options; _serviceBroker = serviceBroker; _authorizationServiceClient = authorizationServiceClient; _nuGetTelemetryProvider = nuGetTelemetryProvider; Assumes.NotNull(_serviceBroker); Assumes.NotNull(_authorizationServiceClient); Assumes.NotNull(_nuGetTelemetryProvider); }
private async ValueTask <object> CreateSolutionManagerServiceAsync( ServiceMoniker moniker, ServiceActivationOptions options, IServiceBroker serviceBroker, AuthorizationServiceClient authorizationServiceClient, CancellationToken cancellationToken) { NuGetSolutionManagerService service = await NuGetSolutionManagerService.CreateAsync( options, serviceBroker, authorizationServiceClient, cancellationToken); return(service); }
public NuGetProjectUpgraderService( ServiceActivationOptions options, IServiceBroker serviceBroker, AuthorizationServiceClient authorizationServiceClient, ISharedServiceState state) { Assumes.NotNull(serviceBroker); Assumes.NotNull(authorizationServiceClient); Assumes.NotNull(state); _options = options; _serviceBroker = serviceBroker; _authorizationServiceClient = authorizationServiceClient; _state = state; }
public NuGetSourcesService( ServiceActivationOptions options, IServiceBroker serviceBroker, AuthorizationServiceClient authorizationServiceClient, ISharedServiceState state) { Assumes.NotNull(serviceBroker); Assumes.NotNull(authorizationServiceClient); Assumes.NotNull(state); _options = options; _serviceBroker = serviceBroker; _authorizationServiceClient = authorizationServiceClient; _sharedServiceState = state; _sharedServiceState.SourceRepositoryProvider.PackageSourceProvider.PackageSourcesChanged += PackageSourceProvider_PackageSourcesChanged; }
public static async ValueTask <NuGetSolutionManagerService> CreateAsync( ServiceActivationOptions options, IServiceBroker sb, AuthorizationServiceClient ac, CancellationToken cancellationToken) { Assumes.NotNull(sb); Assumes.NotNull(ac); cancellationToken.ThrowIfCancellationRequested(); IComponentModel componentModel = await ServiceLocator.GetGlobalServiceFreeThreadedAsync <SComponentModel, IComponentModel>(); Assumes.NotNull(componentModel); return(new NuGetSolutionManagerService(options, sb, ac, componentModel)); }
private async ValueTask <object> CreateSourceProviderServiceAsync( ServiceMoniker moniker, ServiceActivationOptions options, IServiceBroker serviceBroker, AuthorizationServiceClient authorizationServiceClient, CancellationToken cancellationToken) { await _lazyInitializer.InitializeAsync(cancellationToken); #pragma warning disable CA2000 // Dispose objects before losing scope var service = new NuGetSourcesService( options, serviceBroker, authorizationServiceClient, _sharedServiceState); #pragma warning restore CA2000 // Dispose objects before losing scope return(service); }
private NuGetSolutionManagerService( ServiceActivationOptions options, IServiceBroker sb, AuthorizationServiceClient ac, IComponentModel componentModel) { Assumes.NotNull(sb); Assumes.NotNull(ac); _options = options; _serviceBroker = sb; _authorizationServiceClient = ac; componentModel.DefaultCompositionService.SatisfyImportsOnce(this); Assumes.NotNull(SolutionManager); RegisterEventHandlers(); }
private async ValueTask <object> CreatePackageFileServiceAsync( ServiceMoniker moniker, ServiceActivationOptions options, IServiceBroker serviceBroker, AuthorizationServiceClient authorizationServiceClient, CancellationToken cancellationToken) { await _lazyInitializer.InitializeAsync(cancellationToken); INuGetTelemetryProvider telemetryProvider = await _lazyTelemetryProvider.GetValueAsync(cancellationToken); #pragma warning disable CA2000 // Dispose objects before losing scope var service = new NuGetPackageFileService( options, serviceBroker, authorizationServiceClient, telemetryProvider); #pragma warning restore CA2000 // Dispose objects before losing scope return(service); }
protected void Page_Load(object sender, EventArgs e) { Message.Text = ""; find_player_button.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(find_player_button, null) + "; game = {}; $('#data').html('');"); HttpCookie token_cookie = Request.Cookies.Get("token_cookie"); if (token_cookie != null) { token.Value = token_cookie.Value; try { using (AuthorizationServiceClient authZClient = new AuthorizationServiceClient()) { User user = authZClient.AuthorizeUser(token_cookie.Value); IsLoggedIn = true; Session["username"] = user.Username; } } catch (FaultException <AuthorizationFault> ) { Response.Cookies["token_cookie"].Expires = DateTime.Now.AddDays(-1); } } /* * if (IsPostBack) * { * string parameter = Request["__EVENTARGUMENT"]; * if (parameter == "rldsavedgames") * { * show_saved_games_button_ClickAsync(sender, e); * } * } */ }
public NuGetSourcesService(ServiceActivationOptions options, IServiceBroker serviceBroker, AuthorizationServiceClient authorizationServiceClient) { _options = options; _serviceBroker = serviceBroker; _authorizationServiceClient = authorizationServiceClient; }
public async Task GetTotalCountAsync_WithGreaterThanOrEqualToMaxCountResults_ReturnsMaxCount() { var source1 = new PackageSource("https://dotnet.myget.org/F/nuget-volatile/api/v3/index.json", "NuGetVolatile"); var source2 = new PackageSource("https://api.nuget.org/v3/index.json", "NuGet.org"); var sources = new List <PackageSource> { source1, source2 }; var sourceRepository = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(new[] { source1, source2 }); var solutionManager = new Mock <IVsSolutionManager>(); solutionManager.SetupGet(x => x.SolutionDirectory).Returns("z:\\SomeRandomPath"); var settings = new Mock <ISettings>(); var deleteOnRestartManager = new Mock <IDeleteOnRestartManager>(); AddService <IDeleteOnRestartManager>(Task.FromResult <object>(deleteOnRestartManager.Object)); AddService <IVsSolutionManager>(Task.FromResult <object>(solutionManager.Object)); AddService <ISettings>(Task.FromResult <object>(settings.Object)); AddService <ISourceRepositoryProvider>(Task.FromResult <object>(sourceRepository)); var serviceActivationOptions = default(ServiceActivationOptions); var serviceBroker = new Mock <IServiceBroker>(); var authorizationService = new AuthorizationServiceClient(Mock.Of <IAuthorizationService>()); var sharedState = new SharedServiceState(sourceRepository); var projectManagerService = new Mock <INuGetProjectManagerService>(); var installedPackages = new List <IPackageReferenceContextInfo>(); var projects = new List <IProjectContextInfo> { new ProjectContextInfo( Guid.NewGuid().ToString(), ProjectModel.ProjectStyle.PackageReference, NuGetProjectKind.PackageReference) }; projectManagerService.Setup(x => x.GetInstalledPackagesAsync( It.IsAny <IReadOnlyCollection <string> >(), It.IsAny <CancellationToken>())) .Returns(new ValueTask <IReadOnlyCollection <IPackageReferenceContextInfo> >(installedPackages)); #pragma warning disable ISB001 // Dispose of proxies serviceBroker.Setup(x => x.GetProxyAsync <INuGetProjectManagerService>( NuGetServices.ProjectManagerService, It.IsAny <ServiceActivationOptions>(), It.IsAny <CancellationToken>())) .Returns(new ValueTask <INuGetProjectManagerService>(projectManagerService.Object)); #pragma warning restore ISB001 // Dispose of proxies using (var searchService = new NuGetPackageSearchService( serviceActivationOptions, serviceBroker.Object, authorizationService, sharedState)) { const int MaxCount = 100; int totalCount = await searchService.GetTotalCountAsync( MaxCount, projects, sources.Select(s => PackageSourceContextInfo.Create(s)).ToList(), targetFrameworks : new List <string>() { "net45", "net5.0" }, new SearchFilter(includePrerelease : true), NuGet.VisualStudio.Internal.Contracts.ItemFilter.All, CancellationToken.None); Assert.Equal(MaxCount, totalCount); } }