{"id":54,"date":"2011-04-11T15:59:00","date_gmt":"2011-04-11T15:59:00","guid":{"rendered":"https:\/\/wdev-blog.azurewebsites.net\/index.php\/2011\/04\/11\/wcf-authenticate-by-apikey\/"},"modified":"2011-04-11T15:59:00","modified_gmt":"2011-04-11T15:59:00","slug":"wcf-authenticate-by-apikey","status":"publish","type":"post","link":"http:\/\/panahy.nl\/index.php\/2011\/04\/11\/wcf-authenticate-by-apikey\/","title":{"rendered":"WCF Authenticate by APIKey"},"content":{"rendered":"<p>Following my previous note, I want each service have its own authentication mechanics, maybe some public services and some sharing the same authentication manager.<\/p>\n<p>To do so, I will set up different behaviors in my web.config in the servicebehaviors section, and make sure each service points to the corresponding behavior:<\/p>\n<div>\n<pre><span style=\"color: #000000;\">&lt;system.serviceModel&gt;<br \/>  &lt;behaviors&gt;<br \/>    &lt;serviceBehaviors&gt;<br \/>      &lt;behavior name=<\/span><span style=\"color: #800000;\">\"ProductionServiceBehavior\"<\/span><span style=\"color: #000000;\">&gt; <br \/>        &lt;serviceAuthorization serviceAuthorizationManagerType=<\/span><span style=\"color: #800000;\">\"WCFWebHttp.APIKeyAuthorization, WCFWebHttp\"<\/span><span style=\"color: #000000;\"> \/&gt;<br \/>      &lt;\/behavior&gt;<br \/>      &lt;behavior name=<\/span><span style=\"color: #800000;\">\"PublicServiceBehavior\"<\/span><span style=\"color: #000000;\">&gt;<br \/>        &lt;serviceMetadata httpGetEnabled=<\/span><span style=\"color: #800000;\">\"true\"<\/span><span style=\"color: #000000;\">\/&gt;<br \/>        &lt;serviceDebug includeExceptionDetailInFaults=<\/span><span style=\"color: #800000;\">\"false\"<\/span><span style=\"color: #000000;\">\/&gt;<br \/>      &lt;\/behavior&gt;<br \/>    &lt;\/serviceBehaviors&gt;<br \/>  &lt;\/behaviors&gt;<br \/>  &lt;services&gt;<br \/>    &lt;service name=<\/span><span style=\"color: #800000;\">\"WCFWebHttp.ProductionService\"<\/span><span style=\"color: #000000;\"> behaviorConfiguration=<\/span><span style=\"color: #800000;\">\"ProductionServiceBehavior\"<\/span><span style=\"color: #000000;\">&gt;<br \/>    &lt;\/service&gt;<br \/>  &lt;\/services&gt;<\/span><\/pre>\n<p><\/div>\n<p>Now, all I need to do is to implement my APIKeyAuthorization class. This class inherits from ServiceAuthorizationManager and overrides <span style=\"font-weight:bold;\">CheckAccessCore<\/span> to validate the request and send an Error response if not validated.<br \/>For detailed information about this class see the original article on:<br \/><a href=\"http:\/\/blogs.msdn.com\/b\/rjacobs\/archive\/2010\/06\/14\/how-to-do-api-key-verification-for-rest-services-in-net-4.aspx\">MSDN<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following my previous note, I want each service have its own authentication mechanics, maybe some public services and some sharing the same authentication manager. To do so, I will set up different behaviors in my web.config in the servicebehaviors section, and make sure each service points to the corresponding behavior: &lt;system.serviceModel&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name=&#8221;ProductionServiceBehavior&#8221;&gt; &hellip; <a href=\"http:\/\/panahy.nl\/index.php\/2011\/04\/11\/wcf-authenticate-by-apikey\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;WCF Authenticate by APIKey&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[48,20],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"Pouya Panahy","author_link":"http:\/\/panahy.nl\/index.php\/author\/pouya\/"},"uagb_comment_info":0,"uagb_excerpt":"Following my previous note, I want each service have its own authentication mechanics, maybe some public services and some sharing the same authentication manager. To do so, I will set up different behaviors in my web.config in the servicebehaviors section, and make sure each service points to the corresponding behavior: &lt;system.serviceModel&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name=\"ProductionServiceBehavior\"&gt;&hellip;","_links":{"self":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/54"}],"collection":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":0,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"wp:attachment":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}