如果您在 Identity Server 应用程序中使用 .Net Framework 4.5.1,您可能已经将 TokenEndpointPath 定义为“/Token”。查看 App_Start 文件夹中的 Startup.Auth.cs 文件。
调用客户端可以通过向端点发送有效的用户名/密码来从 /Token 端点检索承载令牌。我创建了一个简单的 codepen,以使用新的 Windows Identity Foundation 基础结构来试验我自己的 ASP.NET Web Api 2 项目。您可能会在其中找到一些有用的东西:
http://codepen.io/randomfactor/pen/bNpBoP?editors=101
# THIS IS CoffeeScript (because we are not barbarians)
# start by trying to get an access token
$.ajax {
type: 'POST'
url: "#{appUrl}/Token"
contentType: 'application/x-www-form-urlencoded; charset=UTF-8'
data: {
grant_type: 'password'
username: $('#login-name').val()
password: $('#password').val()
}
}
.then (data) ->
请注意,根据定义,codepen 正在向您的 Identity Server 项目发出跨域资源共享请求。要使其工作,您需要修改您的 Identity Server 项目以支持 CORS,如 codepen 上的注释中所述。
如果您愿意将您的 Identity Server 与受保护的网站和 .Net 4.5.1 下的 Web Api 项目结合起来(强烈推荐!),它将简化一些事情并且您不需要 CORS 修改。