Beispiel #1
0
        public static async Task Handle_Denied_Permissions(string query, string expected)
        {
            // Arrange
            var httpContext = new DefaultHttpContext();

            var request = new DefaultHttpRequest(httpContext)
            {
                QueryString = new QueryString(query)
            };

            var scheme  = new AuthenticationScheme("amazon-auth", "Amazon", typeof(AmazonAuthenticationHandler));
            var options = new RemoteAuthenticationOptions();
            var failure = new InvalidOperationException();

            var context          = new RemoteFailureContext(httpContext, scheme, options, failure);
            var provider         = Guid.NewGuid().ToString();
            var secureDataFormat = Mock.Of <ISecureDataFormat <object> >();
            var logger           = Mock.Of <ILogger>();

            // Act
            await OAuthEventsHandler.HandleRemoteFailure(context, provider, secureDataFormat, logger, PropertiesProvider);

            // Assert
            httpContext.Response.GetTypedHeaders().Location.OriginalString.ShouldBe(expected);
        }
Beispiel #2
0
        /// <summary>
        /// Tries to configure Twitter authentication.
        /// </summary>
        /// <returns>
        /// The current <see cref="ApplicationAuthorizationBuilder"/>.
        /// </returns>
        public ApplicationAuthorizationBuilder TryAddTwitter()
        {
            string name = "Twitter";

            if (TryGetProvider(name, out ExternalSignInOptions? signInOptions))
            {
                _builder.AddTwitter(
                    (options) =>
                {
                    options.ConsumerKey         = signInOptions !.ClientId;
                    options.ConsumerSecret      = signInOptions.ClientSecret;
                    options.RetrieveUserDetails = true;
                    options.StateCookie.Name    = ApplicationCookie.State.Name;

                    options.Events.OnRemoteFailure =
                        (context) => OAuthEventsHandler.HandleRemoteFailure(
                            context,
                            options.SignInScheme !,
                            options.StateDataFormat,
                            LoggerFactory.CreateLogger(name),
                            (token) => token?.Properties?.Items);

                    ConfigureRemoteAuth(name, options);

                    // Enable hook for integration tests, if configured
                    ExternalAuthEvents events = AuthEvents;

                    if (events?.OnRedirectToTwitterAuthorizationEndpoint != null)
                    {
                        options.Events.OnRedirectToAuthorizationEndpoint = events.OnRedirectToTwitterAuthorizationEndpoint;
                    }
                });
            }

            return(this);
        }