public IAsyncResult BeginAuthentication(AsyncCallback callback, Object asyncState) { // Go off authenticate AuthenticationDelegate ad = DoAuthentication; return(ad.BeginInvoke(callback, ad)); }
public void ShouldAuthenticateAsUser() { Uri tokenUri = new Uri("http://testsite"); ClientCredentialsTokenRequest tokenRequest = new ClientCredentialsTokenRequest() { ClientId = "CLIENT_ID", ClientSecret = "SOME_SECRET", Username = "******", Password = "******", }; string json = @"{ ""access_token"":""token"", ""expires_in"":500, ""refresh_expires_in"":0, ""refresh_token"":""refresh_token"", ""token_type"":""bearer"", ""not-before-policy"":25, ""session_state"":""session_state"", ""scope"":""scope"" }"; var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, IgnoreNullValues = true, WriteIndented = true, }; JWTModel expected = JsonSerializer.Deserialize <JWTModel>(json, options); using ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole()); ILogger <IAuthenticationDelegate> logger = loggerFactory.CreateLogger <IAuthenticationDelegate>(); var handlerMock = new Mock <HttpMessageHandler>(); handlerMock .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ) .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(json), }) .Verifiable(); Mock <IHttpClientService> mockHttpClientService = new Mock <IHttpClientService>(); mockHttpClientService.Setup(s => s.CreateDefaultHttpClient()).Returns(() => new HttpClient(handlerMock.Object)); IAuthenticationDelegate authDelegate = new AuthenticationDelegate(logger, mockHttpClientService.Object); JWTModel actualModel = authDelegate.AuthenticateAsUser(tokenUri, tokenRequest); Assert.True(actualModel.IsDeepEqual(expected)); }
private void PassAuthentication(bool value) { if (this.InvokeRequired == false) { if (value == true) { cmd.ShowOpaqueLayer(panel1, 125, true); } else { } } else { AuthenticationDelegate myDelegate = new AuthenticationDelegate(PassAuthentication); this.Invoke(myDelegate, new object[] { value }); } }
private void PassAuthentication(bool value) { if (this.InvokeRequired == false) { if (value == true) { cmd.ShowOpaqueLayer(panel1, 125, true); //resultLabel.Text = "执行中..."; } else { btnLoadData.Text = "加载完成!"; } } else { AuthenticationDelegate myDelegate = new AuthenticationDelegate(PassAuthentication); this.Invoke(myDelegate, new object[] { value }); } }
public void EndAuthentication(IAsyncResult result) { AuthenticationDelegate ad = (AuthenticationDelegate)result.AsyncState; ad.EndInvoke(result); }