WCF 中基于令牌的身份验证

本文介绍了WCF 中基于令牌的身份验证的处理方法,对大家解决问题具有一定的参考价值

问题描述

我正在创建一个包含 ASP.NET 页面和 Flash 小程序的网站.我想将我的业务逻辑封装在 WCF 服务中,该服务将通过两个端点公开:一个可通过 HTTP(S) 通过 Internet 访问,供 Flash 客户端使用,另一个可在数据中心内访问,供应用程序服务器使用.如果这看起来不是一个好方法,那么请阻止我;否则,我会继续前进...

I am creating a website which will contain both ASP.NET pages and a Flash applet. I want to encapsulate my business logic in a WCF service which will be exposed through two endpoints: One accesssible over the Internet through HTTP(S), for use by the Flash client, and one accessible within the data center for use by the application servers. If this does not seem like a good approach, then stop me here; otherwise, I'll move on...

问题是如何验证来自 Flash 客户端的请求.由于我不想将用户的密码存储在浏览器 cookie 中,不想每次请求都发送密码,也不想在初次登录后使用 HTTPS,我打算使用令牌-基于身份验证的系统.我也不希望用户在已经登录到站点本身后还必须登录 Flash 客户端,因此我计划在 Flash 客户端启动时使用 Javascript 将令牌传递给它.

The question is how to authenticate requests coming from the Flash client. Since I don't want to store the user's password in a browser cookie, don't want to send the password with every request, and don't want to have to use HTTPS after the initial login, I plan on using a token-based authentication system. I also don't want the user to have to log into the Flash client after already logging into the site itself, so I plan on using Javascript to pass the token to the Flash client when it starts.

我知道 WCF 支持使用 .NET Framework 的内置安全框架 (System.Security) 来实施访问控制,我想利用这一点.

I know WCF supports using the .NET Framework's built-in security framework (System.Security) to enforce access control, and I would like to take advantage of this.

那么,问题是:当 Flash 调用 WCF 服务时,如何将令牌传递给 WCF 服务,以及如何在服务器上处理令牌?

  • WCF 具有颁发的令牌"身份验证模式,但它似乎旨在用于具有安全令牌服务和 SAML 令牌的成熟的联合方案——我真正想要的有点复杂.可以将这种模式与我自己的简单随机字符串"令牌一起使用吗?如果是这样,如何?请记住,这需要与 Flash 兼容.
  • 我可能会在标头(SOAP 标头或 HTTP 标头)中传递令牌.在这种情况下,一旦我确定发出请求的是哪个用户,我该如何通知框架以便 System.Security 检查起作用?
  • 我应该考虑完全不同的方法吗?任何避免在每个请求中都发送密码、让我使用 System.Security 并与 Flash 配合使用的东西都是可能的.

推荐答案

看起来原来的问题已经得到解答,我会保持简短,但一种方法确实是在 http 标头中传递身份验证令牌并覆盖自定义 ServiceAuthorizationManager 中的 CheckAccess(OperationContext operationContext, ref Message message) .

As it seems the original question has been answered I'll keep this brief, but one approach would indeed be to pass the authentication token in an http header and override CheckAccess(OperationContext operationContext, ref Message message) in a custom ServiceAuthorizationManager .

您之前已将服务配置为使用实现 IAuthorizationPolicy 的自定义策略.

You will have previously configured the service to use a custom policy that implements IAuthorizationPolicy.

剩下的就是实现简单的 IIdentityIPrincipal 类来存储您的授权状态.

All that remains is to implement simple IIdentity and IPrincipal classes to store your authorization state.

有很多关于这个主题的好文章:

A number of good articles exist on this subject:

http://msdn.microsoft.com/en-us/library/system.identitymodel.policy.iauthorizationpolicy.aspx

http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceauthorizationmanager.aspx

我想这可能仍然感觉像是一个自己动手"的解决方案,但是当您遵循既定的模式时,它至少让人放心.它确实具有将您的授权代码从您的服务方法中黑盒化的优势.

I guess this may still feel like a "roll-your-own" solution, but its at least reassuring when you're following an established pattern. It does have the advantage of black-boxing your authorization code from your service methods.

这篇关于WCF 中基于令牌的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2

admin_action_{$_REQUEST[‘action’]}

do_action( "admin_action_{$_REQUEST[‘action’]}" )动作钩子::在发送“Action”请求变量时激发。Action Hook: Fires when an ‘action’ request variable is sent.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$_REQUEST['action']引用从GET或POST请求派生的操作。源码(Source)更新版本源码位置使用被使用2.6.0 wp-admin/admin.php:...

日期:2020-09-02 17:44:16 浏览:1127

admin_footer-{$GLOBALS[‘hook_suffix’]}

do_action( "admin_footer-{$GLOBALS[‘hook_suffix’]}", string $hook_suffix )操作挂钩:在默认页脚脚本之后打印脚本或数据。Action Hook: Print scripts or data after the default footer scripts.目录锚点:#说明#参数#源码说明(Description)钩子名的动态部分,$GLOBALS['hook_suffix']引用当前页的全局钩子后缀。参数(Parameters)参数类...

日期:2020-09-02 17:44:20 浏览:1033

customize_save_{$this->id_data[‘base’]}

do_action( "customize_save_{$this->id_data[‘base’]}", WP_Customize_Setting $this )动作钩子::在调用WP_Customize_Setting::save()方法时激发。Action Hook: Fires when the WP_Customize_Setting::save() method is called.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_data...

日期:2020-08-15 15:47:24 浏览:775

customize_value_{$this->id_data[‘base’]}

apply_filters( "customize_value_{$this->id_data[‘base’]}", mixed $default )过滤器::过滤未作为主题模式或选项处理的自定义设置值。Filter Hook: Filter a Customize setting value not handled as a theme_mod or option.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_date['base'],指的是设置...

日期:2020-08-15 15:47:24 浏览:866

get_comment_author_url

过滤钩子:过滤评论作者的URL。Filter Hook: Filters the comment author’s URL.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/comment-template.php:32610...

日期:2020-08-10 23:06:14 浏览:904

network_admin_edit_{$_GET[‘action’]}

do_action( "network_admin_edit_{$_GET[‘action’]}" )操作挂钩:启动请求的处理程序操作。Action Hook: Fires the requested handler action.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$u GET['action']引用请求的操作的名称。源码(Source)更新版本源码位置使用被使用3.1.0 wp-admin/network/edit.php:3600...

日期:2020-08-02 09:56:09 浏览:848

network_sites_updated_message_{$_GET[‘updated’]}

apply_filters( "network_sites_updated_message_{$_GET[‘updated’]}", string $msg )筛选器挂钩:在网络管理中筛选特定的非默认站点更新消息。Filter Hook: Filters a specific, non-default site-updated message in the Network admin.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分$_GET['updated']引用了非默认的...

日期:2020-08-02 09:56:03 浏览:834

pre_wp_is_site_initialized

过滤器::过滤在访问数据库之前是否初始化站点的检查。Filter Hook: Filters the check for whether a site is initialized before the database is accessed.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/ms-site.php:93910...

日期:2020-07-29 10:15:38 浏览:809

WordPress 的SEO 教学:如何在网站中加入关键字(Meta Keywords)与Meta 描述(Meta Description)?

你想在WordPress 中添加关键字和meta 描述吗?关键字和meta 描述使你能够提高网站的SEO。在本文中,我们将向你展示如何在WordPress 中正确添加关键字和meta 描述。为什么要在WordPress 中添加关键字和Meta 描述?关键字和说明让搜寻引擎更了解您的帖子和页面的内容。关键词是人们寻找您发布的内容时,可能会搜索的重要词语或片语。而Meta Description则是对你的页面和文章的简要描述。如果你想要了解更多关于中继标签的资讯,可以参考Google的说明。Meta 关键字和描...

日期:2020-10-03 21:18:25 浏览:1622

谷歌的SEO是什么

SEO (Search Engine Optimization)中文是搜寻引擎最佳化,意思近于「关键字自然排序」、「网站排名优化」。简言之,SEO是以搜索引擎(如Google、Bing)为曝光媒体的行销手法。例如搜寻「wordpress教学」,会看到本站的「WordPress教学:12个课程…」排行Google第一:关键字:wordpress教学、wordpress课程…若搜寻「网站架设」,则会看到另一个网页排名第1:关键字:网站架设、架站…以上两个网页,每月从搜寻引擎导入自然流量,达2万4千:每月「有机搜...

日期:2020-10-30 17:23:57 浏览:1264