MVC 5,身份 2.0 Android Rest/Json Api
MVC 5, Identity 2.0 Android Rest/Json Api
我有一个 ASP.NET MVC 5 应用程序,它为 authentication/authorisation 使用 Identity 2.0。现在我想通过 Web Api 2.0.
向我的 Android 应用程序提供对我的 Web 应用程序中数据的访问
我的问题是:如何控制authorize/authenticate我的android应用程序的访问权限?
在 Android 方面,我使用 "org.springframework.web.client.RestTemplate" 并将此 HTTP header 添加到我的请求中:
HttpAuthentication authHeader = new HttpBasicAuthentication("username", "password");
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAuthorization(authHeader);
HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
我应该只创建一个过滤器还是一个 HttpModule,在那里分析 HTTP Header 并查询数据库以检查是否有现有用户?
我很清楚它在 HTML/Javascript 前端是如何工作的。每次成功登录后都会使用一个 cookie,用于所有后续调用,但我的 android 应用程序的最佳策略是什么?
更新:
找到了这两个链接,但我不确定是否应该这样做:
http://springinpractice.com/2012/04/08/sending-cookies-with-resttemplate
http://blog.mikepearce.net/2010/08/24/cookies-and-the-restful-api/
您可以按照您的建议,为您的 WebApi 控制器创建一个 Filter,以授权和验证来自您的客户端应用程序的访问。这里有一个 blog post 可以帮助你实现这样的事情。
但是,我建议使用 Oauth standard. This method of authentication and authorization is very well suited for mobile applications. You can create long life access tokens that keep your mobile client app logged in similarly to long life cookies and a browser client. Or you could use short life access tokens and long life refresh tokens. Also there is nothing stopping you from using Oauth with browser clients either, giving you a single auth implementation. Here is a great SO answer on tokens and Oauth 定义的访问令牌。
看看 IdentityServer 以下简介来自他们的 Github 存储库:
IdentityServer is a .NET/Katana-based framework and hostable component
that allows implementing single sign-on and access control for modern
web applications and APIs using protocols like OpenID Connect and
OAuth2. It supports a wide range of clients like mobile, web, SPAs and
desktop applications and is extensible to allow integration in new and
existing architectures.
我有一个 ASP.NET MVC 5 应用程序,它为 authentication/authorisation 使用 Identity 2.0。现在我想通过 Web Api 2.0.
向我的 Android 应用程序提供对我的 Web 应用程序中数据的访问我的问题是:如何控制authorize/authenticate我的android应用程序的访问权限?
在 Android 方面,我使用 "org.springframework.web.client.RestTemplate" 并将此 HTTP header 添加到我的请求中:
HttpAuthentication authHeader = new HttpBasicAuthentication("username", "password");
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAuthorization(authHeader);
HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
我应该只创建一个过滤器还是一个 HttpModule,在那里分析 HTTP Header 并查询数据库以检查是否有现有用户?
我很清楚它在 HTML/Javascript 前端是如何工作的。每次成功登录后都会使用一个 cookie,用于所有后续调用,但我的 android 应用程序的最佳策略是什么?
更新: 找到了这两个链接,但我不确定是否应该这样做: http://springinpractice.com/2012/04/08/sending-cookies-with-resttemplate http://blog.mikepearce.net/2010/08/24/cookies-and-the-restful-api/
您可以按照您的建议,为您的 WebApi 控制器创建一个 Filter,以授权和验证来自您的客户端应用程序的访问。这里有一个 blog post 可以帮助你实现这样的事情。
但是,我建议使用 Oauth standard. This method of authentication and authorization is very well suited for mobile applications. You can create long life access tokens that keep your mobile client app logged in similarly to long life cookies and a browser client. Or you could use short life access tokens and long life refresh tokens. Also there is nothing stopping you from using Oauth with browser clients either, giving you a single auth implementation. Here is a great SO answer on tokens and Oauth 定义的访问令牌。
看看 IdentityServer 以下简介来自他们的 Github 存储库:
IdentityServer is a .NET/Katana-based framework and hostable component that allows implementing single sign-on and access control for modern web applications and APIs using protocols like OpenID Connect and OAuth2. It supports a wide range of clients like mobile, web, SPAs and desktop applications and is extensible to allow integration in new and existing architectures.