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

0 件のコメント: