public void CogniStreamerAuthenticationProvider_CallApplyRedirect_ShouldInvokeOnApplyRedirect() { var callbacksMock = new Mock <IProviderCallbacks>(); var options = new CogniStreamerAuthenticationOptions(); var properties = new AuthenticationProperties(); var context = new CogniStreamerApplyRedirectContext(this.owinContextMock.Object, options, properties, "https://www.test.org"); this.providerUnderTest.OnApplyRedirect = callbacksMock.Object.OnApplyRedirect; this.providerUnderTest.ApplyRedirect(context); callbacksMock.Verify(x => x.OnApplyRedirect(context), Times.Once); }
protected override Task ApplyResponseChallengeAsync() { if (this.Response.StatusCode != 401) { return(Task.FromResult <object>(null)); } var challenge = Helper.LookupChallenge(this.Options.AuthenticationType, this.Options.AuthenticationMode); if (challenge != null) { string baseUri = this.Request.Scheme + Uri.SchemeDelimiter + this.Request.Host + this.Request.PathBase; string currentUri = baseUri + this.Request.Path + this.Request.QueryString; string redirectUri = baseUri + this.Options.CallbackPath; var properties = challenge.Properties; if (string.IsNullOrEmpty(properties.RedirectUri)) { properties.RedirectUri = currentUri; } // OAuth2 10.12 CSRF this.GenerateCorrelationId(properties); string scope = string.Join(" ", this.Options.Scope); string state = this.Options.StateDataFormat.Protect(properties); string authorizationEndpoint = new Uri(this.Options.PortalBaseUrl, AuthorizeEndpoint.Value).ToString() + "?response_type=code" + "&client_id=" + Uri.EscapeDataString(this.Options.ClientId) + "&redirect_uri=" + Uri.EscapeDataString(redirectUri) + "&scope=" + Uri.EscapeDataString(scope) + "&state=" + Uri.EscapeDataString(state); var redirectContext = new CogniStreamerApplyRedirectContext(this.Context, this.Options, properties, authorizationEndpoint); this.Options.Provider.ApplyRedirect(redirectContext); } return(Task.FromResult <object>(null)); }
public void CogniStreamerApplyRedirectContext_PassArguments_ShouldAssignProperties() { var owinContext = new Mock <IOwinContext>().Object; var options = new CogniStreamerAuthenticationOptions(); var properties = new AuthenticationProperties(); var context = new CogniStreamerApplyRedirectContext(owinContext, options, properties, "https://someredirecturi.com/test"); Assert.That(context.OwinContext, Is.EqualTo(owinContext)); Assert.That(context.Options, Is.EqualTo(options)); Assert.That(context.Properties, Is.EqualTo(properties)); Assert.That(context.RedirectUri, Is.EqualTo("https://someredirecturi.com/test")); }
public void CogniStreamerAuthenticationProvider_DefaultOnApplyRedirectImplementation_ShouldRedirectResponse() { var options = new CogniStreamerAuthenticationOptions(); var properties = new AuthenticationProperties(); var context = new CogniStreamerApplyRedirectContext(this.owinContextMock.Object, options, properties, "https://www.test.org"); var responseMock = new Mock <IOwinResponse>(); this.owinContextMock.SetupGet(x => x.Response).Returns(responseMock.Object); Assert.That(() => this.providerUnderTest.ApplyRedirect(context), Throws.Nothing); responseMock.Verify(x => x.Redirect("https://www.test.org"), Times.Once); }