0
我有一个AngularJS客户端应用程序和WebApi联系数据库方法。我有一个IdentityServer3
来验证用户。我怎么能登录如何调用IdentityServer授权方法使用WebAPI Controller方法登录
- IdentityServer:
localhost:5005/core/connect/authorize?client_id=ClientA&redirect_uri=http%3A%2F%2Flocalhost%3A30005%2Fcallback&response_type=code%20id_token&scope=openid&state=94bbc0299da444468bb9cc21e5277cf1&nonce=873ea5f66fe0468faa9a362bf1a50e46"
- 的WebAPI:
localhost:5000/Auth/Login
- 角应用:
localhost:30005
我怎么能验证通过的WebAPI登录控制器方法
用户public class LoginController : ApiController
{
[HttpGet]
public string Login(UserInfo user)
{
// How to implement the logic
}
}
型号:
public class UserInfo
{
public string UserId { get; set; }
public string Password { get; set; }
}
的WebAPI启动
public class Startup
{
public void Configuration(IAppBuilder app)
{
JwtSecurityTokenHandler.InboundClaimTypeMap.Clear();
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "localhost:5005",
RequiredScopes = new[] { "idmgr" } });
app.UseWebApi(WebApiConfig.Register());
}
}
请帮助我如何构建登录方法中的WebAPI。
是的......它只是一个'https'版本......而我正在使用'AngularJs 1.xx' 我的问题是如何使用这个调用'[Authorize]'WebAPI方法。我需要在WebAPI中配置'OWIN' Auth吗?如果是,它会接受身份服务器令牌作为承载令牌? –
是的,你需要配置一个owin,并且IAppBuilder方法有一个名为“UseIdentityServerBearerTokenAuthentication”的扩展方法,它具有所需的范围和权限(你的服务器url)。 如果您将response_type表示为“token”并且您的响应令牌类型可以是承载类型或弹出类型,则IdentityServer可以为您提供authtoken。 –
@ B.Balamanigandan您可以在创建JWT令牌的位置添加一段代码吗? –