我们有一个基于默认Visual Studio SPA模板的ASP.NET MVC应用程序 . 用户成功登录后,javascript会重新加载页面以使用此URL调用OAuth授权 endpoints
window.location = "/Account/Authorize?client_id=web&response_type=token&state=" + encodeURIComponent(window.location.hash);
这是处理承载令牌的服务器端代码
PublicClientId = "web";
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
AuthorizeEndpointPath = new PathString("/Account/Authorize"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AllowInsecureHttp = true
};
OAuth授权 endpoints 使用url中的访问令牌进行302重定向响应,例如
https://example.com/#access_token=wKB_9sVptsGr ...
Javascript从重定向URL中提取令牌,并使用它来通过WebApi进行身份验证 . 这样可以很好地工作,因为它允许我们在MVC端和WebApi端进行身份验证 . 但是,这种返回承载令牌的方法在最近的网络安全审计中被识别为一个问题,因为令牌存储在浏览器历史记录中,将 access_token
暴露给其他用户 .
是否有更好的方法来返回持票人令牌?我们需要对MVC和WebApi部分进行身份验证 .
EDIT
只是为了澄清事情,这个问题是关于 first time the server passes the access token to the browser . 不是浏览器将令牌传递回服务器 .