【问题标题】:Authentication mobile apps function call with WCF Service使用 WCF 服务进行身份验证移动应用程序函数调用
【发布时间】:2014-05-15 08:34:58
【问题描述】:

我刚刚开始为我的移动应用程序创建 WCF 服务。目前我在单一解决方案中有多个项目。

  • 主要网站项目
  • Edmx 项目
  • WCF 库项目

认证功能

     public List<AuthenticateModel> Authenticate(string UserName, string Password)
            {
                SimpleMembershipInitializer _initialized = new SimpleMembershipInitializer();
                bool validate = System.Web.Security.Membership.ValidateUser(UserName, Password);
                AuthenticateModel model = new AuthenticateModel();
                if (validate)
                {
                    model.userID = IDUser
                }
                Return model;
            }

现在我怎么知道同一个登录用户正在调用另一个函数。如果这里有什么方法可以将会话保持为网络?或者传递任何证书或令牌进行验证(如果是如何传递令牌并实现它)?

    [OperationContract]
    [WebInvoke(UriTemplate = "GetAllrecords/?paramId={paramId}", Method = "GET", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
    List<SomeModel> GetAllrecords(int paramId)
    {
         Return something; // Return requested data
    }

任何帮助将不胜感激。

【问题讨论】:

    标签: asp.net-mvc wcf wcf-security


    【解决方案1】:

    如果你有时间,你应该阅读

    http://www.codeproject.com/Articles/630986/Cross-Platform-Authentication-With-ASP-NET-Web-API

    它专注于 web api,但讨论了令牌的使用。

    在我们的身份验证方法中,我们返回一个生成的令牌,该令牌与用户和角色一起保存在服务器上。

    webclient(在我们的例子中是用 angularjs 构建的)用请求头中的令牌组成请求。然后,我们检查 Web api 中的每个请求,提取令牌并将其与持久令牌进行比较。

    有很多解决方案,我们的不是很安全,但对我们来说已经足够了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      • 2014-12-08
      • 2015-11-22
      • 2017-01-10
      相关资源
      最近更新 更多