none
Programatic log on to Sharepoint behind UAG

    Question

  • I am trying to programatically gain access to a Sharepoint site behind a UAG gateway.

    I am doing this with Python, using urllib2 and a cookie container.

    The situation is very similar to the one posted here: http://social.technet.microsoft.com/Forums/forefront/en-US/9c499638-73b3-4a37-bf70-7f807bec05ee/uag-authentication-from-code

    The sequence I go through is:

    1. Request Sharepoint URL
    2. Redirected to a uniquesigxxxx/InitParams.aspx page
    3. Redirected to a uniquesigxxx/Login.asp page
    4. Emulate javascript in response (POST credentials to uniquesigxxx/Validate.asp page)
    5. Emulate javascript in response (GET uniquesigxxx/RedirectToOrigURL.asp?zzzz page)
    6. Redirected to the original url
    7. Redirected to the original url again

    In the browser, step 7 is when the originally requested url is delivered and various Sharepoint session cookies are returned.

    The 3 session cookies I am getting and passing back from the original response are:

    • ASPSESSIONIDxxx=yyy
    • uniquesigxxxxx=yyy
    • NLSessionSportal=xxxx

    I also make a request to /InternalSite/?WhlST before validate.asp which sets a WhlST cookie.

    The only difference between the browser login process and the script login process that I can glean is that the browser sends back different values for the ASPSESSIONIDxxx and uniquesigxxx cookies in the response to step 6 above. I don't get that with the script for some reason.

    Is anyone able to help? I have used Fiddler extensively to try and debug this but I am well and truely stuck.

    Thursday, July 25, 2013 11:18 AM

All replies

  • Hiya, 

    How about programming it through an Internet explorer COM object using Powershell? 
    It will depend on how your pages are build, if they are using standard functions etc, however it should be pretty straight forward to do.

    Something like the below:
    #----------------------------------------------------
    #–Define Credentials to login. You should convert to secure string for password.
    $UserName = '<UserName>'
    $Password = '<Password>' 

    #–Define Logon page
    $LogonPage = "<My SP Site>

    $ie = New-Object -ComObject “InternetExplorer.Application”
    $ie.Navigate($LogonPage)
    $ie.Visible = $true

    #wait for Logon page to load
    while ($ie.ReadyState -ne 4)
    {
    sleep -Milliseconds 100
    }
    $LogonButton = $ie.Document.getElementsByName('<Name of Logon button>')
    $LogonButton.click()
    #wait for Logon page to load
    while ($ie.ReadyState -ne 4)
    {
    sleep -Milliseconds 100
    }
    #--Define elemenets for typing in username and password
    $Username= $ie.Document.getElementsByName('<Name of Username input box>')
    $Password= $ie.Document.getElementsByName('<Name of password input box>')

    $Username.value = $UserName
    $Password.value = $Password

    $LoginButton = $ie.Document.getElementsByName('<The Ok, Confirm og Login button name>')

    Sleep -seconds 2
    #Stop-Process -Name iexplore
    #----------------------------

    I used inspiration from my own script here:
    http://jesperarnecke.wordpress.com/2013/07/24/sharepoint-2010-mysite-preferred-search-center-setting-powershell/

    Friday, July 26, 2013 4:05 PM
  • Thanks for this, it helped me think outside the initial problem space.

    However, I am struggling to proceed with how to consume Sharepoint services through the InternetExplorer.Application object. Presumably this would be best achieved with SOAP/REST web services? The former I guess would be some sort of XMLHttpRequest from the Browser application object. The latter doesn't seem to be set up on our server - although I may be able to get it set up..

    Tuesday, July 30, 2013 9:02 PM
  • Hiya, 

    Glad it was a help! :)

    It depends what SharePoint service your after? - each of the service applications, have an end point defined.  Which is presented through the SharePoint Web Services web site.

    You can find the end point Uri under each service application using powershell. 

    Example getting secure store Uri

    Get-SpServiceApplication | Where-Object {$_.DisplayName -like "Secure Store*"} | select Uri

    Wednesday, July 31, 2013 6:29 AM