Joke? Authenticate webservice

I tried to connect to my test-webservice with a .net app.

All works fine as long as I’m anonymous but do we like anonymous access? Sometimes perhaps but not in my case.

I have tried the to set the credentials with the .net class NetworkCredential and PreAuthenticate = true;

The domino server returns an error (in html?) demanding username and password.

Is there an easy solution to my problem or is the domino-webservice-thing only for unreal scenarios?

I’m so f tired of all restrictions and “can’t do-things” in the domino world…

/Lars

Subject: Joke? Authenticate webservice

No Joke, Why don’t you read about integrated authentication? Let IIS pass the windows (.net) authentication to Domino? We use this feature and our .net developpers and users are happy and I do not allow anonymous access to our servers

Subject: We use it too and it works fine.

Subject: Joke? Authenticate webservice

You are probably frustrated with Domino becuase you don’t fully understand the product. Some education would be helpful.

Take a class on domino or hire a real domino developer.

You first mention you don’t like anonymous access but then you say domino is asking for a user name and password - well then give it a domino user name and password.

What is the error? What user name and password are you trying? Is it a domino user or a .net user?

Subject: RE: Joke? Authenticate webservice

Hi Tom,

Only a joke place a comment like you do :slight_smile:

I have managed very well as a Visual Studio and Domino developer for some time now.

I found out that when the Session authentication: is set to disabled the Basic authentication work.

Perhaps you my friend can tell me why and if there is a sollution to authenticate with Session ON?

/Lars

Subject: RE: Joke? Authenticate webservice

I am pretty sure you can add a cookie to Webservice request in .Net, so all you have to do is generate the token if you have a username and password. See this thread for help

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/41986b31b02c48b585257155004aadb5?OpenDocument

Subject: SOLUTION: Joke? Authenticate webservice

Hi Lars I posted this on Interop, but figured I would post it here too in case someone else was ever looking for it.

It appears like I have this working. I add the following constructor and function to the reference.vb file that is created when you inport a wsdl to VS

Public Sub New(ByVal securityCookie As String)

        MyBase.New()

        Me.Url = "http://myhost.com/web.nsf/webservice"

        _authCookieValue = securityCookie

    End Sub



    Protected Overrides Function GetWebRequest(ByVal Uri As Uri) As 

System.Net.WebRequest

        Dim request As System.Net.WebRequest

        request = MyBase.GetWebRequest(Uri)

        request.Headers.Add("Cookie", "LtpaToken=" & _authCookieValue)

        Return request

    End Function

securityCookie in the constructor is the LtpaToken of the user or admin depending on how you want to do it. If I am running as a user other than the current user, I have a function that I use to generate an admin LtpaToken.

‘’’

''' Generates a Notes Security Cookie for the specified user/password combo

''' </summary>

''' <param name="loginUrl">The url to post to. (ex http://mycompany.com/names.nsf?Login)</param>

''' <param name="cookieName">The name of the returning cookine. (ex LtpaToken)</param>

''' <param name="userName">The username of the account to log in with</param>

''' <param name="password">The password of the account to log in with</param>    

''' <returns type="System.Web.HttpCookie">The cookie generated with the login credentials</returns>

Public Shared Function GenerateLtpaToken(ByVal loginUrl As String, ByVal cookieName As String, ByVal userName As String, ByVal password As String) As System.Web.HttpCookie

    'Put user code to initialize the page here

    Dim req As HttpWebRequest

    Dim res As System.Net.HttpWebResponse

    Dim sr As System.IO.StreamReader

    Dim cookieContainer As New System.Net.CookieContainer

    Dim securityToken As String

    Dim postDataByte As Byte()

    Dim postStream As Stream

    Dim retCode As Boolean = False

    Dim authorizationCookie As System.web.HttpCookie



    Try

        System.Net.ServicePointManager.Expect100Continue = False



        req = CType(WebRequest.Create(loginUrl), HttpWebRequest)

        req.CookieContainer = New CookieContainer



        'enncode the form data string into a byte array '

        postDataByte = System.Text.Encoding.ASCII.GetBytes("username=" & userName & "&password=" & password)



        'indicate that you will be posting the data 

        req.Method = "POST"

        req.ContentType = "application/x-www-form-urlencoded"

        req.ContentLength = postDataByte.Length

        req.AllowAutoRedirect = False



        'send the form 

        postStream = req.GetRequestStream()

        postStream.Write(postDataByte, 0, postDataByte.Length)



        ' Close the post

        postStream.Close()



        res = CType(req.GetResponse(), HttpWebResponse)

        res.Cookies = req.CookieContainer.GetCookies(req.RequestUri)





        'read in the page 

        'sr = New System.IO.StreamReader(res.GetResponseStream())



        ' Get the specified cookie

        If Not res.Cookies(cookieName) Is Nothing Then

            '_AuthorizationCookie = CType(res.Cookies.Item(_authorizationCookieName), System.Web.HttpCookie)

            Dim responseCookie As Cookie = res.Cookies.Item(cookieName)

            Dim passThruCookie As New System.Web.HttpCookie(cookieName)



            ' Convert the cookie to an httpCookie

            passThruCookie.Domain = responseCookie.Domain

            passThruCookie.Value = responseCookie.Value

            passThruCookie.Expires = responseCookie.Expires

            passThruCookie.Path = responseCookie.Path



            authorizationCookie = passThruCookie



        End If

        Return authorizationCookie

    Catch ex As Exception

        Throw ex

    End Try

End Function