Export (0) Print
Expand All

Integrating the OAuth WRAP Handler

Current information about Live Connect is now available in the Windows Live Developer Center. The information in the following sections is provided for legacy purposes only.

You can integrate the OAuth WRAP handler into your ASP.NET web application by taking the following steps:

  1. Add a reference to Microsoft.Live.AuthHandler.dll.
  2. Update your web.config file with markup to register the handler, and specify the client ID and secret key for your application.
  3. Implement a class that derives from the ISessionIdProvider.interface This requirement applies only to sites that will use HTTP; if your site uses HTTPS, this step is not required.
To add a reference to Microsoft.Live.AuthHandler.dll
  1. In Visual Studio, right-click the project node and then select Add Reference.

  2. Click the Browse tab, and then navigate to the directory into which you extracted the Windows Live SDK.

  3. Locate \Windows Live SDK\v4.1\API Toolkits\dotNET\Microsoft.Live.AuthHandler.dll, select it, and then click OK.

    For more information, see Downloading the Windows Live SDK.

To update web.config
  1. Add the following markup to the appropriate place in your web.config file. This markup registers the OAuth handler in ASP.NET. Note that this example assumes you are using Internet Information Services (IIS) 7.0 integrated pipeline mode.

          <add name="OAuthWrapHandler" verb="GET" path="OAuthWrapCallback.ashx" type="Microsoft.Live.OAuthWrapHandler, Microsoft.Live.AuthHandler, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  2. Add the following markup to the appSettings element of your web.config file.

       <add key="wl_wrap_client_secret" value="sZ4zoCasI04tDX7la3Omr0xQCSDjJws8"/>
       <add key="wl_wrap_client_id" value="12345678ABCDEFGH"/>
       <add key="wl_wrap_client_callback" value="http://<Your-Domain>/<Your-App-Name>/OAuthWrapCallback.ashx"/>

If your website uses HTTP you need to implement the ISessionIdProvider interface. Doing so involves adding a new class to your application, along with some markup that enables your ASPX page to retrieve the session ID that the SessionIdProvider class generates. The session ID is then appended to the callback URL.

The steps in this section do not apply to sites that use HTTPS.
To update web.config
  • Add the following markup to the appSettings element of your web.config file.

    <add key="wl_wrap_session_id_provider_type" value="SessionIdProvider"/>
To create the SessionIdProvider class
  1. In Visual Studio, right-click the project node, select Add ASP.NET Folder, and then choose App_Code from the menu.

  2. Right-click the App_Code folder and then select Add New Item.

  3. Select the Class template, and then create a new class named SessionIdProvider.

  4. Add a using directive for Microsoft.Live.

    using Microsoft.Live;
  5. Append : ISessionIdProvider after the class declaration, to indicate that the new class should derive from Microsoft.Live.ISessionIdProvider.

    public class SessionIdProvider : ISessionIdProvider
  6. Click the interface name. In the tag that appears, click the arrow and then select Implement interface ISessionIdProvider. This action will automatically generate the code required to implement the interface.

  7. Paste the following code into the body of the SessionIdProvider class.

    const string WlSessionId = "wl_session_id";
    public string GetSessionId(HttpContext context)
        string sessionGuid = string.Empty;
        if (context.Session[WlSessionId] != null)
            sessionGuid = context.Session[WlSessionId].ToString();
            sessionGuid = Guid.NewGuid().ToString();
            context.Session.Add(WlSessionId, sessionGuid);
        return (string)sessionGuid;
To update your ASPX page and code-behind page
  1. Open the code-behind page for your site's default ASPX page, which contains the Application Control tag.

  2. Locate the main class for the page. When you create an ASPX page, this class is a public partial class with the same name as the page. Paste the following code into the class.

    protected string SessionId
          SessionIdProvider oauth = new SessionIdProvider();
          return oauth.GetSessionId(HttpContext.Current);
  3. Open the ASPX page, and then locate the wl:app tag.

  4. Append the following query to the callback-url parameter. Doing so will append the unique identifier to your callback URL.

    ?wl_session_id=<%= this.SessionId %>

    The complete parameter should now look like the following.

    callback-url="http://YOUR-DOMAIN/OAuthWrapCallback.axd?wl_session_id=<%= this.SessionId %>"
© 2015 Microsoft