2010/01/11

Windows Live ID Web Authentication(5)

Imports Microsoft.VisualBasic
Imports System.Web
Imports WindowsLive

Namespace customlogin_ext
 Public Class login_ext

  Private Shared wll As New WindowsLiveLogin(True)
  Private Shared AppId1 As String = wll.AppId

  Dim _AppId As String = AppId1
  Dim _UserId As String
  Dim _IsLoginOk As Boolean = False
  'False:未知のUserId True:既知のUserId
  Dim _logincookie As HttpCookie

  Sub New()
   Dim req As HttpRequest = HttpContext.Current.Request
   Dim logincookie As HttpCookie = req.Cookies("webauthtoken")
   If logincookie IsNot Nothing Then
    _logincookie = logincookie
    Dim token As String = logincookie.Value
    If Not String.IsNullOrEmpty(token) Then
     Dim user As WindowsLiveLogin.User = wll.ProcessToken(token)
     If user IsNot Nothing Then
       _UserId = user.Id
      If user.Id = "0000000000000000000000" Then
       _IsLoginOk = True
      End If
     End If
    End If
   End If
  End Sub

  Public ReadOnly Property UserId() As String
   Get
    Return _UserId
   End Get
  End Property

  Public ReadOnly Property AppId() As String
   Get
    Return _AppId
   End Get
  End Property

  Public ReadOnly Property IsLoginOk() As Boolean
   Get
    Return _IsLoginOk
   End Get
  End Property

  Public Sub logoutRedirect()
   If Not _IsLoginOk Then
    If _logincookie Is Nothing Then
     HttpContext.Current.Response.Redirect("~/")
    Else
      HttpContext.Current.Response.Redirect(wll.GetLogoutUrl)
    End If
    HttpContext.Current.Response.End()
   End If
  End Sub

 End Class
End Namespace

2010/01/05

Windows Live ID Web Authentication(4)

さて、どう使うか。。。
Windowslivelogin.User.Idで取得できる文字列が、
アプリケーションIDとLiveIDの組み合わせでユニークだから、これ使ってユーザを確定って話

Windows Live ID Web Authentication(3)

カスタマイズ
webauth-handler.aspx.vbの編集
 Private Const LoginPage As String = "" **ログイン後遷移先
 Private Const LogoutPage As String = "" **ログアウト後遷移先

liveIDサインインリンク編集
http://msdn.microsoft.com/ja-jp/library/bb676638.aspx
http://msdn.microsoft.com/en-us/library/bb676638.aspx
iframe-srcをお好みで変更
http://login.live.com/controls/WebAuth.htm?.....
style以降のクエリを変更可能

http://login.live.com/controls/WebAuthbutton.htm?....
ボタンに変更


http://login.live.com/controls/WebAuthlogo.htm?....
ロゴ付きテキスト

Windows Live ID Web Authentication(2)

動作確認まで
ダウンロードしたSDK展開し、必要ファイルをwwwサーバに配置。
/
default.aspx
default.aspx.vb
webauth-handler.aspx **アプリケーションIDの取得時のReturnURLがここ
webauth-handler.aspx.vb
/App_Code
WindowsLiveLogin.vb

web.config編集-appSettings key追加
key="wll_appid" value="0000000000000000"
key="wll_secret" value="00000000000000000000000000000000"
key="wll_securityalgorithm" value="wsignin1.0"

/default.aspxにアクセス
LiveIDログイン後、WindowsLiveHandler.aspx経由default.aspx
UserIDが表示されればここまでOk

Windows Live ID Web Authentication(1)

msdn
http://msdn.microsoft.com/ja-jp/library/bb676633.aspx

SDKのダウンロード
http://go.microsoft.com/fwlink/?LinkID=91761
VB C# PHP java perlなどお好きに

アプリケーションIDの取得
https://msm.live.com/app/default.aspx
Register an Applicationから登録

Service Component Label:
Service Component Description:(お好みで)
Domain:(空でいい)
Return URL:(LiveID認証後戻ってくるURL)
で、
Application IDとSecret Keyを取得