Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Frederik Østerbye 11 posts 81 karma points
    Feb 10, 2013 @ 00:50
    Frederik Østerbye
    0

    Host custom WCF-service with authentication within Umbraco

    Hi There

    I've created a custom WCF-service within Umbraco. The service resides in the Service-folder and seems to be working fine (I can call it and it responds appropriately). Now I want the users to authenticate themselves when they call the service.

    To do this i've put in this into the web.config:

    <services>
          <service name="RaceManagerAdmin.RaceManDataService" behaviorConfiguration="RaceManBehavior">
    
            <endpoint address=""
                      binding="webHttpBinding"
                      contract="System.Data.Services.IRequestHandler" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="RaceManBehavior">
              <serviceCredentials>
                <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
                                        membershipProviderName="UmbracoMembershipProvider" />
              </serviceCredentials>
            </behavior>
          </serviceBehaviors>
        </behaviors>

    When my service is called it should use the Umbraco membership provider to authenticate the users.

    My client specificies this by creating a network cridential object, like this:

    var a = new RaceEntities(new Uri("http://localhost:40406/umbraco/Webservices/RaceManDataService.svc")) { Credentials = new NetworkCredential("admin", "secret") };

    When I inspect the HTTPContext.Current I don't see any authenticated users. What am I doing wrong?

     

    - Frederik

  • Frederik Østerbye 11 posts 81 karma points
    Feb 14, 2013 @ 12:53
    Frederik Østerbye
    100

    I've kinda solved it.

    I've enabled authentication sever (se this article: http://msdn.microsoft.com/en-us/library/bb398990(v=vs.100).aspx).

    I have extended global.asax to use the umbraco membership provider (see this article: http://msdn.microsoft.com/en-us/library/bb386455(v=vs.90).aspx)

    To get the cookie from the WCF-call (you cannot get that directly in WCF because cookie are transparent in WCF) I followed this article:http://megakemp.com/2009/02/06/managing-shared-cookies-in-wcf/ 

    Now I want to send the same cookie to my WCF-service on every call I did something like this (extended my entity class with a partial implementation): http://blogs.msdn.com/b/astoriateam/archive/2010/07/21/odata-and-authentication-part-7-forms-authentication.aspx 

    If I turn on asp.net compability in web.config I am now able to access the callers membership through: HttpContext.Current.User.Identity.Name

    - Frederik

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft