本文整理汇总了C#中IServiceCollection.ConfigureTwitterAuthentication方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.ConfigureTwitterAuthentication方法的具体用法?C# IServiceCollection.ConfigureTwitterAuthentication怎么用?C# IServiceCollection.ConfigureTwitterAuthentication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.ConfigureTwitterAuthentication方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.Get("Data:IdentityConnection:ConnectionString")));
services.Configure<IdentityDbContextOptions>(options =>
{
options.DefaultAdminUserName = Configuration.Get("DefaultAdminUsername");
options.DefaultAdminPassword = Configuration.Get("DefaultAdminPassword");
});
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.ConfigureFacebookAuthentication(options =>
{
options.AppId = "901611409868059";
options.AppSecret = "4aa3c530297b1dcebc8860334b39668b";
});
services.ConfigureGoogleAuthentication(options =>
{
options.ClientId = "514485782433-fr3ml6sq0imvhi8a7qir0nb46oumtgn9.apps.googleusercontent.com";
options.ClientSecret = "V2nDD9SkFbvLTqAUBWBBxYAL";
});
services.ConfigureTwitterAuthentication(options =>
{
options.ConsumerKey = "BSdJJ0CrDuvEhpkchnukXZBUv";
options.ConsumerSecret = "xKUNuKhsRdHD03eLn67xhPAyE1wFFEndFo1X2UJaK2m1jdAxf4";
});
services.AddMvc();
}
示例2: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add EF services to the services container.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<NerdDinnerDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddScoped<INerdDinnerRepository, NerdDinnerRepository>();
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<NerdDinnerDbContext>()
.AddDefaultTokenProviders();
services.ConfigureFacebookAuthentication(options =>
{
options.ClientId = Configuration["Authentication:Facebook:AppId"];
options.ClientSecret = Configuration["Authentication:Facebook:AppSecret"];
});
services.ConfigureGoogleAuthentication(options =>
{
options.ClientId = Configuration["Authentication:Google:AppId"];
options.ClientSecret = Configuration["Authentication:Google:AppSecret"];
});
services.ConfigureTwitterAuthentication(options =>
{
options.ConsumerKey = Configuration["Authentication:Twitter:AppId"];
options.ConsumerSecret = Configuration["Authentication:Twitter:AppSecret"];
});
//services.ConfigureMicrosoftAccountAuthentication(options =>
//{
// options.Caption = "MicrosoftAccount - Requires project changes";
// options.ClientId = Configuration["Authentication:Microsoft:AppId"];
// options.ClientSecret = Configuration["Authentication:Microsoft:AppSecret"];
//});
// Add MVC services to the services container.
services.AddMvc().Configure<MvcOptions>(options =>
{
var settings = new JsonSerializerSettings()
{
Formatting = Formatting.Indented,
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
var formatter = new JsonOutputFormatter { SerializerSettings = settings };
options.OutputFormatters.Insert(0, formatter);
// Add validation filters
options.Filters.Add(new ValidateModelFilterAttribute());
});
}
示例3: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AppSettings>(Configuration.GetConfigurationSection("AppSettings"));
var useInMemoryStore = _platform.IsRunningOnMono || _platform.IsRunningOnNanoServer;
// Add EF services to the services container
if (useInMemoryStore)
{
services.AddEntityFramework()
.AddInMemoryDatabase()
.AddDbContext<MusicStoreContext>(options =>
options.UseInMemoryDatabase());
}
else
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString")));
}
// Add Identity services to the services container
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<MusicStoreContext>()
.AddDefaultTokenProviders();
services.ConfigureCookieAuthentication(options =>
{
options.AccessDeniedPath = new PathString("/Home/AccessDenied");
});
services.ConfigureFacebookAuthentication(options =>
{
options.AppId = "550624398330273";
options.AppSecret = "10e56a291d6b618da61b1e0dae3a8954";
});
services.ConfigureGoogleAuthentication(options =>
{
options.ClientId = "977382855444.apps.googleusercontent.com";
options.ClientSecret = "NafT482F70Vjj_9q1PU4B0pN";
});
services.ConfigureTwitterAuthentication(options =>
{
options.ConsumerKey = "9J3j3pSwgbWkgPFH7nAf0Spam";
options.ConsumerSecret = "jUBYkQuBFyqp7G3CUB9SW3AfflFr9z3oQBiNvumYy87Al0W4h8";
});
services.ConfigureMicrosoftAccountAuthentication(options =>
{
options.Caption = "MicrosoftAccount - Requires project changes";
options.ClientId = "000000004012C08A";
options.ClientSecret = "GaMQ2hCnqAC6EcDLnXsAeBVIJOLmeutL";
});
services.ConfigureCors(options =>
{
options.AddPolicy("CorsPolicy", builder =>
{
builder.WithOrigins("http://example.com");
});
});
// Add MVC services to the services container
services.AddMvc();
//Add all SignalR related services to IoC.
services.AddSignalR();
//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();
// Add session related services.
services.AddCaching();
services.AddSession();
// Add the system clock service
services.AddSingleton<ISystemClock, SystemClock>();
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
{
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
});
}
示例4: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AppSettings>(Configuration.GetConfigurationSection("AppSettings"));
//Sql client not available on mono
string value;
var useInMemoryStore = Configuration.TryGet("UseInMemoryStore", out value) && value == "true" ?
true :
_runtimeEnvironment.RuntimeType.Equals("Mono", StringComparison.OrdinalIgnoreCase);
// Add EF services to the services container
if (useInMemoryStore)
{
services.AddEntityFramework()
.AddInMemoryDatabase()
.AddDbContext<MusicStoreContext>(options =>
options.UseInMemoryDatabase());
}
else
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString")));
}
// Add Identity services to the services container
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<MusicStoreContext>()
.AddDefaultTokenProviders();
services.ConfigureCookieAuthentication(options =>
{
options.AccessDeniedPath = new PathString("/Home/AccessDenied");
});
services.ConfigureFacebookAuthentication(options =>
{
options.AppId = "[AppId]";
options.AppSecret = "[AppSecret]";
options.Notifications = new OAuthAuthenticationNotifications()
{
OnAuthenticated = FacebookNotifications.OnAuthenticated,
OnReturnEndpoint = FacebookNotifications.OnReturnEndpoint,
OnApplyRedirect = FacebookNotifications.OnApplyRedirect
};
options.BackchannelHttpHandler = new FacebookMockBackChannelHttpHandler();
options.StateDataFormat = new CustomStateDataFormat();
options.Scope.Add("email");
options.Scope.Add("read_friendlists");
options.Scope.Add("user_checkins");
});
services.ConfigureGoogleAuthentication(options =>
{
options.ClientId = "[ClientId]";
options.ClientSecret = "[ClientSecret]";
options.AccessType = "offline";
options.Notifications = new OAuthAuthenticationNotifications()
{
OnAuthenticated = GoogleNotifications.OnAuthenticated,
OnReturnEndpoint = GoogleNotifications.OnReturnEndpoint,
OnApplyRedirect = GoogleNotifications.OnApplyRedirect
};
options.StateDataFormat = new CustomStateDataFormat();
options.BackchannelHttpHandler = new GoogleMockBackChannelHttpHandler();
});
services.ConfigureTwitterAuthentication(options =>
{
options.ConsumerKey = "[ConsumerKey]";
options.ConsumerSecret = "[ConsumerSecret]";
options.Notifications = new TwitterAuthenticationNotifications()
{
OnAuthenticated = TwitterNotifications.OnAuthenticated,
OnReturnEndpoint = TwitterNotifications.OnReturnEndpoint,
OnApplyRedirect = TwitterNotifications.OnApplyRedirect
};
options.StateDataFormat = new CustomTwitterStateDataFormat();
options.BackchannelHttpHandler = new TwitterMockBackChannelHttpHandler();
#if DNX451
options.BackchannelCertificateValidator = null;
#endif
});
services.ConfigureMicrosoftAccountAuthentication(options =>
{
options.Caption = "MicrosoftAccount - Requires project changes";
options.ClientId = "[ClientId]";
options.ClientSecret = "[ClientSecret]";
options.Notifications = new OAuthAuthenticationNotifications()
{
OnAuthenticated = MicrosoftAccountNotifications.OnAuthenticated,
OnReturnEndpoint = MicrosoftAccountNotifications.OnReturnEndpoint,
OnApplyRedirect = MicrosoftAccountNotifications.OnApplyRedirect
};
options.BackchannelHttpHandler = new MicrosoftAccountMockBackChannelHandler();
options.StateDataFormat = new CustomStateDataFormat();
options.Scope.Add("wl.basic");
options.Scope.Add("wl.signin");
//.........这里部分代码省略.........
示例5: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
//Sql client not available on mono
var useInMemoryStore = Type.GetType("Mono.Runtime") != null;
// Add EF services to the services container
if (useInMemoryStore)
{
services.AddEntityFramework()
.AddInMemoryStore()
.AddDbContext<MusicStoreContext>();
}
else
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString")));
}
// Add Identity services to the services container
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<MusicStoreContext>()
.AddDefaultTokenProviders();
services.ConfigureFacebookAuthentication(options =>
{
options.AppId = "550624398330273";
options.AppSecret = "10e56a291d6b618da61b1e0dae3a8954";
});
services.ConfigureGoogleAuthentication(options =>
{
options.ClientId = "977382855444.apps.googleusercontent.com";
options.ClientSecret = "NafT482F70Vjj_9q1PU4B0pN";
});
services.ConfigureTwitterAuthentication(options =>
{
options.ConsumerKey = "9J3j3pSwgbWkgPFH7nAf0Spam";
options.ConsumerSecret = "jUBYkQuBFyqp7G3CUB9SW3AfflFr9z3oQBiNvumYy87Al0W4h8";
});
services.ConfigureMicrosoftAccountAuthentication(options =>
{
options.Caption = "MicrosoftAccount - Requires project changes";
options.ClientId = "000000004012C08A";
options.ClientSecret = "GaMQ2hCnqAC6EcDLnXsAeBVIJOLmeutL";
});
// Add MVC services to the services container
services.AddMvc();
//Add all SignalR related services to IoC.
services.AddSignalR();
//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();
// Add session related services.
services.AddCaching();
services.AddSession();
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
{
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
});
}
示例6: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add Entity Framework services to the services container.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
// Configure the options for the authentication middleware.
// You can add options for Google, Twitter and other middleware as shown below.
// For more information see http://go.microsoft.com/fwlink/?LinkID=532715
services.Configure<FacebookAuthenticationOptions>(options =>
{
options.AppId = Configuration["Authentication:Facebook:AppId"];
options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
});
services.Configure<MicrosoftAccountAuthenticationOptions>(options =>
{
options.ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"];
options.ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"];
});
services.ConfigureTwitterAuthentication(opt =>
{
opt.ConsumerKey = "enter key here";
opt.ConsumerSecret = "enter secret here";
});
// Add MVC services to the services container.
services.AddMvc();
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
// services.AddWebApiConventions();
// Register application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}