C# 无法使用OAuth和twitter外部提供程序对Asp.net WebApi进行身份验证
我已经创建了C# 无法使用OAuth和twitter外部提供程序对Asp.net WebApi进行身份验证,c#,asp.net-web-api,twitter,C#,Asp.net Web Api,Twitter,我已经创建了Asp.net WebApi并启用了twitter身份验证code 在HomeController.cs上使用了[Authorize]属性 现在,我如何在不打开登录框的情况下验证凭据并授予对授权控制器的访问权 public void ConfigureAuth(IAppBuilder app) { // Configure the db context and user manager to use a single instance per
Asp.net WebApi
并启用了twitter身份验证
code
在HomeController.cs
上使用了[Authorize]
属性
现在,我如何在不打开登录框的情况下验证凭据并授予对授权控制器的访问权
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context and user manager to use a single instance per request
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Configure the application for OAuth based flow
PublicClientId = "self";
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
// In production mode set AllowInsecureHttp = false
AllowInsecureHttp = true
};
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
app.UseTwitterAuthentication(
consumerKey: "mykey",
consumerSecret: "mysecret");
}
public void ConfigureAuth(IAppBuilder应用程序)
{
//将db上下文和用户管理器配置为每个请求使用一个实例
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext(ApplicationUserManager.Create);
//使应用程序能够使用cookie存储登录用户的信息
//以及使用cookie临时存储用户登录第三方登录提供商的信息
app.UseCookieAuthentication(新的CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
//为基于OAuth的流配置应用程序
PublicClientId=“self”;
OAuthOptions=新的OAuthAuthorizationServerOptions
{
TokenEndpointPath=新路径字符串(“/Token”),
Provider=新的ApplicationAuthProvider(PublicClientId),
AuthorizeEndpointPath=新路径字符串(“/api/Account/ExternalLogin”),
AccessTokenExpireTimeSpan=TimeSpan.FromDays(14),
//在生产模式下,设置AllowInsecureHttp=false
AllowInsecureHttp=true
};
//使应用程序能够使用承载令牌对用户进行身份验证
应用程序使用OAuthBealerTokens(OAuthOptions);
//取消注释以下行以启用使用第三方登录提供程序登录
//app.UseMicrosoftAccountAuthentication(
//客户ID:“,
//客户机密:);
app.UseTwitterAuthentication(
消费者:“我的钥匙”,
消费者信条:“我的秘密”);
}
我在twitter应用程序中添加了一个应用程序-获取消费者密钥。
和消费者的秘密
我不想打开twitter登录弹出窗口
用于授权webapi时的登录凭据