zoukankan      html  css  js  c++  java
  • 网站集成 Windows Live ID 身份验证

     

    Running the C# QuickStart Sample

    This topic explains how to install, run, and extend the QuickStart sample provided in the C# programming language.

    Important:

    The C# QuickStart sample is preconfigured to use default values for the application ID, secret key, and return URL parameters. The return URL is preconfigured to point to http://localhost/webauth/sample/webauth-handler.aspx. For more information about how to customize these parameters, see Getting Your Application ID for Web Authentication.

     Installing the Sample

    When you install the sample, you put its files in the correct locations on your Web server. In this discussion, we assume that you have direct access to your Web server and that you develop and browse your site from the server.

    Before you install the C# QuickStart sample, make sure that Microsoft Internet Information Services (IIS), the .NET Framework 2.0, and ASP.NET are installed on your server. For IIS, make sure that:

    • A default Web site exists
    • The home directory of the default site is C:\Inetpub\wwwroot

    To install the sample

    1. Run the C# sample installation file (webauth-cs-1.2.msi).
    2. Copy the C:\Program Files\Windows Live ID\WebAuth directory to C:\Inetpub\wwwroot.
    3. Create a directory named App_Code under C:\Inetpub\wwwroot, if it does not already exist.
    4. Move C:\Inetpub\wwwroot\WebAuth\App_Code\WindowsLiveLogin.cs to the default App_Code directory at C:\Inetpub\wwwroot\App_Code\.

    The C# QuickStart sample is installed.

     Running the Sample

    After you install the sample, you can run it to see a demonstration of how Windows Live ID works.

    To run the sample

    1. Go to http://localhost/webauth/sample/default.aspx.
    2. Click Sign in. You are directed to the Windows Live ID sign-in page.
    3. Type your valid Windows Live ID and password to sign in. You are redirected to the sample application. The Sign in link has now changed to Sign out.
    4. Click Sign out. You are signed out.

     

     

    参考资料:http://msdn.microsoft.com/en-us/library/bb676630.aspx

     

     

    首先,和Google AuthSub一样,你必须先在Live的云计算开发中心Azure Services Developer Portal去注册你的程序

     

    注册完成之后,就可以开始进行开发,需要说明的是,在Live ID站点上提供了一个非常简单的类WindowsLiveLogin.cs,应该可以在这个例子之中得到这个类:Running the C# QuickStart Sample,而且可能是因为有了这个类,Microsoft觉得不需要再去提供什么和服务端交互的文档了(反正我没有找到),因此,我就直接不改动任何程序的情况下使用了这个类,这样,一切就方便了很多了。

     

    先看如何得到用来让用户登录的转向地址,这个太容易了,因为这正是WindowsLiveLogin类的方法,需要说明的是,WindowsLiveLogin类有几个方法来获得转向地址的,其中GetLoginUrl方法得到的地址仅仅进行用户登录,而不向用户申请任何权限,而GetConsentUrl(string scope)方法可以指定向用户申请读取相应数据的权限,和Google AuthSub一样,我们在使用Live的登录的时候也需要读取用户的地址本信息来获得用户的登录帐号地址,因此,我们使用wll.GetConsentUrl("Contacts.View");方法来获得转向URL,("Contacts.View"代表对地址本的只读访问),当然在使用这个方法之前,要先设置好PolicyUrl属性(隐私申明地址)和ReturnUrl属性(登录完成之后的回转地址);

     

      有一点需要特别说明的是:在使用GetLoginUrl或者GetConsentUrl方法之前,Live要求用户必须必须已经指定WindowsLiveLogin的PolicyUrl属性,也就是隐私申明的地址,而且,要求指定的网址必须是能够访问的,似乎Live还会去检查这个网址是否能够访问的,我在系统之中将隐私申明的网址指定为我的登录页面,因为在那个页面有我关于保护用户隐私的申明。

     

      将用户转向到刚才获取的URL之后,用户就会被转向到Live ID的登录页:

     

     

    Live转回到登录回转地址的时候,会有多种参数(delauth,login,logout,clearcookie),根据Live接口的要求,这些类型都应该实现,具体每个类型代表如下含义:

     

      1.delauth,这个是我主要用到的类型,就是在用户登录并授与访问权限之后,回转的类型,注意,必须调用GetConsentUrl方法才会得到这种回转,从参数之中可以获取到ConsentToken参数,就是后面要用到的数据访问令牌。

     

      2.login,这是调用GetLoginUrl方法之后回转的类型,也就是说,是不需要访问用户的任何数据的情况下回转访问的参数类型;

     

      3.logout,注销

     

      4.clearcookie,清除Cookie

     

  • 相关阅读:
    Oracle 操作数据库(增删改语句)
    web----框架基础
    js----DOM对象
    易错之for循环
    python调用修改变量新方法
    js----基础
    web----Twisted
    web----Socket
    python----面向对象(2)
    python----面向对象
  • 原文地址:https://www.cnblogs.com/cdts_change/p/1622967.html
Copyright © 2011-2022 走看看