应该是一个简单的问题,只是找不到答案.
我有一个带有web api的SPA(AngularJS),它是由Owin自己托管的.我使用Nancy来提供页面,但我想摆脱Nancy并使用Index.html作为我的单页.
我在这里看到了这个问题:如何将除Web API以外的所有内容路由到/index.html
我不能使用已接受的答案,因为我没有MVC和HomeController,在更新的问题中建议的方式也不起作用,我得到 No HTTP resource was found that matches the request URI 'http://admin.localhost:33333/'. No route providing a controller name was found to match request URI 'http://admin.localhost:33333/'
当我在asp.net webapi 2中设置OAuth授权服务器时,如何设置令牌端点以接受json而不是表单编码的帖子?
使用样本http://www.asp.net/web-api/overview/security/individual-accounts-in-web-api
我试着发送application/json
{
"grant_type":"password",
"username":"Alice",
"password":"password123"
}
Run Code Online (Sandbox Code Playgroud)
我收到400 Bad Request的回复
{
"error" : "unsupported_grant_type"
}
Run Code Online (Sandbox Code Playgroud)
其中作为application/x-www-form-urlencoded的内容类型和grant_type=password&username=Alice&password=password123
正常工作的主体.
200好的
{
"access_token" : "08cQ33ZG728AqBcj1PBsRSs4iBPc02lLCZfpaRRWLx2mH_wpQzMwGDKS7r7VgJiKUjUFaq6Xv0uguINoiB_evVbVOtvyWaqAYvc0HRjlgrbj12uQqFbUB7bgH-jiyfhumkwuTSTVHfKUhBjCuD_pbyxEbu2K5WSJpUVge_SGxnb-htm4ZNf1qKDmpEnP9IpZVeJa-KnV0m0gEmP04slMW_JrO390LzCNvXZwVk1yMNuvDakk8tWX7Y6WkFoh7vtW6xfhw3QMbmnvS6px70yMWcTksRNG2bdmi4SenhuRTJx8IsCMnz-4Co7KiCNJGF7KLeU4WzE-LSqXv3mQ30CIQ7faXoMn53p83wZ1NoXYyhsNrQD4POUns_Isb_Pax5gvpZEdyo8zr1r7wb0dS7UXvJb0PWzLHc57Pg3u0kmcizQ",
"token_type" : "bearer",
"expires_in" : 1209599,
"userName" : "Alice",
".issued" : "Wed, 30 Oct 2013 15:16:33 GMT",
".expires" : "Wed, 13 Nov 2013 15:16:33 GMT"
}
Run Code Online (Sandbox Code Playgroud) 是否有可能将Asp.Net Mvc作为OWIN中间件运行?这有什么必要?我似乎无法找到任何关于这一点,但我不知道为什么它不可能.
可能吗?这简单吗?这个问题有意义吗?
我目前正在升级我的Google登录流程,以便在他们的OpenID登录方法之前使用OAuth.
到目前为止,我已经确定的步骤是我已将Microsoft.Owin.Security.Google软件包升级到版本2.1.0,因为此版本包含在UseGoogleAuthentication方法中包含选项的功能.
我试图在链接中使用Alex Wheat的解决方案: 从外部身份验证提供程序获取MVC5框架OAuth/OWin身份提供者的ExtraData
Startup.Auth.cs中的代码(也包括Facebook身份验证)来自于:
var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
{
AppId = "MYAPPID",
AppSecret = "MYSECRET"
};
facebookAuthenticationOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookAuthenticationOptions);
app.UseGoogleAuthentication();
Run Code Online (Sandbox Code Playgroud)
对此:
var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
{
AppId = "MYAPPID",
AppSecret = "MYSECRET"
};
facebookAuthenticationOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookAuthenticationOptions);
var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
{
ClientId = "MYCLIENTID",
ClientSecret = "MYSECRET",
CallbackPath = new PathString("/en/Account/ExternalLoginCallback"),
Provider = new GoogleOAuth2AuthenticationProvider()
{
}
};
app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);
Run Code Online (Sandbox Code Playgroud)
在我向Google身份验证添加选项后,我的应用不允许为Google或Facebook调用ExternalLoginCallback操作(不更改Facebook代码,但问题仍会影响它).
在前端,单击外部登录按钮后,页面将我重定向到下面的链接并返回一个空白屏幕
https ....../en/Account/ExternalLoginCallback #__ = _(在=符号之前实际上只有一个下划线,如果我在地址栏上显示它,则SO语法将其删除).
对于Facebook和
HTTPS ....../EN /帐号/ ExternalLoginCallback
对于谷歌.它没有像往常那样点击下面的控制器方法(我试图在这个函数中放置调试断点,并且当有google身份验证选项时它永远不会停止.
// GET: /Account/ExternalLoginCallback
[AllowAnonymous]
public …Run Code Online (Sandbox Code Playgroud) asp.net-mvc oauth google-authentication owin asp.net-identity
我正在尝试了解Asp.net Web Api个人帐户身份验证和授权.我在网上看到了几个教程,包括这个.简而言之,当用户代理提供用户名和密码时,API会发出一个令牌,客户端将在后续API调用中使用该令牌来识别自身.用户代理通过发出请求来接收令牌,通常是:http://example.com/Token.该路径似乎在Startup类中设置,如下所示:
TokenEndpointPath = new PathString("/Token")
Run Code Online (Sandbox Code Playgroud)
我的问题是,我找不到任何匹配该路径的控制器方法.这是如何运作的?
这是Configure我Startup班上的方法.
public void Configure(IApplicationBuilder app)
{
// Setup configuration sources
var configuration = new Configuration();
configuration.AddJsonFile("config.json");
configuration.AddEnvironmentVariables();
// Set up application services
app.UseServices(services =>
{
// Add EF services to the services container
services.AddEntityFramework()
.AddSqlServer();
// Configure DbContext
services.SetupOptions<DbContextOptions>(options =>
{
options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString"));
});
// Add Identity services to the services container
services.AddIdentitySqlServer<ApplicationDbContext, ApplicationUser>()
.AddAuthentication();
// Add MVC services to the services container
services.AddMvc();
});
// Enable Browser Link support
app.UseBrowserLink();
// Add static files to the …Run Code Online (Sandbox Code Playgroud) 我非常喜欢新的asp.net(asp.net 5\core 1.0)web应用程序的方法,其中wwwroot文件夹是根目录,只有静态文件才能提供.
可以通过路由或其它配置有一个asp.net 4.5项目的行为一个wwwroot文件夹以类似的方式,这样的静态文件只担任了它,并且它的web应用程序的静态文件的"根"?
(我提出这个问题的部分原因是我在VS2015中的asp.net 5项目中有一个角色应用程序,但是我需要将它转移到asp.net 4.5项目中,但是希望将现有结构保留在磁盘上)
我尝试使用一个空的ASP.NET 4.5 Web应用程序项目和OWIN.所以我的文件夹结构有我的角度应用程序,在项目文件夹的wwwroot文件夹中有一个主index.html文件.项目的根目录中没有HTML文件.
我通过nuget和以下启动文件添加了OWIN:
[assembly: OwinStartup(typeof(MyApp.UI.Startup))]
namespace MyApp.UI
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
string root = AppDomain.CurrentDomain.BaseDirectory;
var physicalFileSystem = new PhysicalFileSystem(Path.Combine(root, "wwwroot"));
var options = new FileServerOptions
{
EnableDefaultFiles = true,
FileSystem = physicalFileSystem
};
options.StaticFileOptions.FileSystem = physicalFileSystem;
options.StaticFileOptions.ServeUnknownFileTypes = false;
options.DefaultFilesOptions.DefaultFileNames = new[] {"index.html"};
app.UseFileServer(options);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这虽然失败 - 我的index.html文件的源确实负载,当我运行它,但所有的CSS,JS等文件,它引用失败有404更糟的是,如果我追加gulpfile.js到根网址是从项目文件夹的根目录加载我的gulp文件.这正是我想要避免的那种事情.
有任何想法吗?
在我的WebAPI项目中,我Owin.Security.OAuth用来添加JWT身份验证.GrantResourceOwnerCredentials我的OAuthProvider 内部使用以下行设置错误:
context.SetError("invalid_grant", "Account locked.");
Run Code Online (Sandbox Code Playgroud)
这将返回给客户:
{
"error": "invalid_grant",
"error_description": "Account locked."
}
Run Code Online (Sandbox Code Playgroud)
在用户获得身份验证并且他尝试向我的某个控制器执行"正常"请求后,当模型无效时,他会得到以下响应(使用FluentValidation):
{
"message": "The request is invalid.",
"modelState": {
"client.Email": [
"Email is not valid."
],
"client.Password": [
"Password is required."
]
}
}
Run Code Online (Sandbox Code Playgroud)
这两个请求都在返回400 Bad Request,但有时您必须查找error_description字段,有时候还要查找message
我能够创建自定义响应消息,但这仅适用于我返回的结果.
我的问题是:是否有可能取代message与error响应由返回ModelValidatorProviders,并在其他地方?
我读过ExceptionFilterAttribute但我不知道这是不是一个好的起点.FluentValidation应该不是问题,因为它只是添加错误ModelState.
编辑:
我正在尝试解决的下一件事是WebApi中返回的数据中的命名约定不一致 - 当OAuthProvider我们返回错误error_details时,但是当我们返回BadRequest时ModelState(从ApiController)返回错误modelState.正如你可以看到第一次使用snake_case …
我已经创建了一个自托管的Nancy/SignalR应用程序,它使用Microsoft.Owin.Host.HttpListener和在OWIN中自托管Microsoft.Owin.Hosting
事情在本地工作得很好但是一旦我尝试使用除localhost之外的任何东西来访问应用程序我就会收到HTTP Error 503. The service is unavailable错误.我甚至无法使用127.0.0.1或使用机器名称访问应用程序.
我已经尝试将端口添加到urlacl使用
http add urlacl http://*:8989/ user=EVERYONE 但似乎没有做任何事情.
这是我试过的OWIN启动选项,
var options = new StartOptions
{
Url = "127.0.0.1",
App = GetType().AssemblyQualifiedName,
Port = _configFileProvider.Port
};
var options = new StartOptions
{
App = GetType().AssemblyQualifiedName,
Port = _configFileProvider.Port
};
Run Code Online (Sandbox Code Playgroud)
这是启动和停止服务器的文件的源代码 https://github.com/NzbDrone/NzbDrone/blob/vnext/NzbDrone/Owin/OwinHostController.cs
您是否知道如何使用url参数中的默认asp.net web api 2 OAuth 2授权机制生成的access_token.目前,我可以通过发送带有Authorization标头的请求来成功授权,如下所示:
Accept: application/json
Content-Type: application/json
Authorization: Bearer pADKsjwMv927u...
Run Code Online (Sandbox Code Playgroud)
我想要的是通过URL参数启用授权,如下所示:
https://www.domain.com/api/MyController?access_token=pADKsjwMv927u...
Run Code Online (Sandbox Code Playgroud) owin ×10
asp.net-mvc ×3
c# ×2
katana ×2
acl ×1
asp.net ×1
asp.net-core ×1
nancy ×1
oauth ×1
oauth-2.0 ×1
routing ×1
self-hosting ×1
signalr ×1