/// <summary>
 /// Creates a new context object.
 /// </summary>
 /// <param name="context">The HTTP request context.</param>
 /// <param name="options">The Twitter middleware options.</param>
 /// <param name="properties">The authentication properties of the challenge.</param>
 /// <param name="redirectUri">The initial redirect URI.</param>
 public TwitterRedirectToAuthorizationEndpointContext(HttpContext context, TwitterOptions options,
                                                      AuthenticationProperties properties, string redirectUri)
     : base(context, options)
 {
     RedirectUri = redirectUri;
     Properties  = properties;
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a <see cref="TwitterCreatingTicketContext"/>
 /// </summary>
 /// <param name="context">The HTTP environment</param>
 /// <param name="options">The options for Twitter</param>
 /// <param name="userId">Twitter user ID</param>
 /// <param name="screenName">Twitter screen name</param>
 /// <param name="accessToken">Twitter access token</param>
 /// <param name="accessTokenSecret">Twitter access token secret</param>
 public TwitterCreatingTicketContext(
     HttpContext context,
     TwitterOptions options,
     string userId,
     string screenName,
     string accessToken,
     string accessTokenSecret)
     : base(context, options)
 {
     UserId            = userId;
     ScreenName        = screenName;
     AccessToken       = accessToken;
     AccessTokenSecret = accessTokenSecret;
 }
        private static TestServer CreateServer(TwitterOptions options, Func <HttpContext, bool> handler = null)
        {
            var builder = new WebHostBuilder()
                          .Configure(app =>
            {
                app.UseCookieAuthentication(new CookieAuthenticationOptions
                {
                    AuthenticationScheme = "External"
                });
                app.UseTwitterAuthentication(options);
                app.Use(async(context, next) =>
                {
                    var req = context.Request;
                    var res = context.Response;
                    if (req.Path == new PathString("/signIn"))
                    {
                        await Assert.ThrowsAsync <NotSupportedException>(() => context.Authentication.SignInAsync("Twitter", new ClaimsPrincipal()));
                    }
                    else if (req.Path == new PathString("/signOut"))
                    {
                        await Assert.ThrowsAsync <NotSupportedException>(() => context.Authentication.SignOutAsync("Twitter"));
                    }
                    else if (req.Path == new PathString("/forbid"))
                    {
                        await Assert.ThrowsAsync <NotSupportedException>(() => context.Authentication.ForbidAsync("Twitter"));
                    }
                    else if (handler == null || !handler(context))
                    {
                        await next();
                    }
                });
            })
                          .ConfigureServices(services =>
            {
                services.AddAuthentication();
                services.Configure <SharedAuthenticationOptions>(authOptions =>
                {
                    authOptions.SignInScheme = "External";
                });
            });

            return(new TestServer(builder));
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a <see cref="BaseTwitterContext"/>
 /// </summary>
 /// <param name="context">The HTTP environment</param>
 /// <param name="options">The options for Twitter</param>
 public BaseTwitterContext(HttpContext context, TwitterOptions options)
     : base(context)
 {
     Options = options;
 }
Beispiel #5
0
 private void ConfigureDefaults(TwitterOptions o)
 {
     o.ConsumerKey    = "whatever";
     o.ConsumerSecret = "whatever";
     o.SignInScheme   = "auth1";
 }