Bonjour,
Je souhaitais savoir si l'un d'entre vous saurait comment s'authentifier à owa en VB.net afin d'ajouter par la suite des rendez vous aux users.
Mon code est le suivant pour l'instant mais ne fonctionne pas.
[code]
Private Function GetRequestObject(ByVal uri As String, ByVal method As String) As HttpWebRequest
Dim webRequest1 As HttpWebRequest
Dim credentials As String()
Dim cache As CredentialCache
Dim uri2 As Uri
'Initiate a new WebRequest to the given URI.
uri2 = New Uri(uri)
webRequest1 = WebRequest.Create(uri2)
webRequest1.CookieContainer = New CookieContainer
webRequest1.Method = method
Return webRequest1
End Function
[/code]
[code]
Private Function DoFormBasedAuthentication(ByVal uri As String, ByVal credential As NetworkCredential) As CookieCollection
Dim server As String '= ConfigurationSettings.AppSettings("smtpServer")
Dim request As HttpWebRequest
Dim response As HttpWebResponse
Dim body As Byte()
Dim stream1 As Stream
Dim result As String
Try
'Get the server portion of the requested uri and appen the authentication dll from Exchange
'server = "http://" & server & "/exchweb/bin/auth/owaauth.dll"
server = uri.Substring(0, uri.IndexOf("/",
) + "/exchweb/bin/auth/owaauth.dll"
'server = "http://chronos/exchange"
request = GetRequestObject(server, "POST")
request.CookieContainer = New CookieContainer
request.ContentType = "application/x-www-form-urlencoded"
'Prepare the body of the request
body = Encoding.UTF8.GetBytes(String.Format("destination={0}&username={1}\\{2}&password={3}", uri, credential.Domain, credential.UserName, credential.Password))
request.ContentLength = body.Length
'Send the request to the server
stream1 = request.GetRequestStream
stream1.Write(body, 0, body.Length)
stream1.Close()
'Get the response
response = request.GetResponse
'Check if the login was successful
If (response.Cookies.Count < 2) Then
'Throw New Exception("Failed to login OWA.")
End If
Return response.Cookies
Catch ex As Exception
'Throw New Exception("Failed to login to OWA. The following error occured : " + ex.StackTrace)
'PublishException(ex)
Dim coco As String
coco = "coucou"
End Try
End Function
[/code]
Dans le page load:
[code]
Label1.Text = ""
Try
Label1.Text = "TEST : "
Dim cookieColl As CookieCollection
Dim netCred As NetworkCredential = New System.Net.NetworkCredential(strAlias, strPassword, strDomain)
Label1.Text += strMailboxURI & " " & netCred.Domain & " " & netCred.UserName & " " & netCred.Password & " "
cookieColl = DoFormBasedAuthentication(strMailboxURI, netCred)
Label1.Text &= "nbCo : " & cookieColl.Count.ToString & " "
'Dim item As Cookie
'For Each item In cookieColl
' Label1.Text &= " " & item.Name & item.Value
'Next
Catch ex As Exception
Label1.Text &= "ERREUR : " & ex.StackTrace
End Try
[/code]
Mon problème est que la fonction DoFormBasedAuthentication renvoie nothing.
Du coup, la ligne
[code]
Label1.Text &= "nbCo : " & cookieColl.Count.ToString & " "
[/code]
Jette une exception.
Merci.
Mickael