• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to read the cookies value from chrome browser when I open the chrome from my macro

Sarvesh1993

New Member
Hi Guys,
I am working on a Macro Based Excel VB Application where we have to do authentication when someone opens the Excel .The excel is downloaded into the machine from a dashboard which has SSO Implemented .I am stuck in a scenario and would like any kind of help which fits into my solution . I have tried my best to explain the scenario ,so the thing is I am opening a chrome browser from my vb codel ,what it will do ,it will redirect me to Microsoft Page in the chrome browser ,there we will do authentication and the response will be going to send in one of the aspx page in Page Load event ,Now the challenge is the response is never going to come back to my vb code in Excel and my excel would never know that user is been authenticated . Any Suggestions on same ? , another thought was to set cookies in browser when the user is authenticated successfully ,how can I make my vb code to wait and read the chrome browser cookie which I opened .I have added the comment downside where I need the help .


Code:
Public Function VCLSSOLogon(Http As Http, value1 As Boolean, value2 As Boolean) As WebResponse

Dim CLIENTSSO As New WebClient
    CLIENTSSO.BaseUrl = Worksheets("Settings").Range("ServerURL") & "api/SomeAssembly/Authenication/Login/SomeMethod"
    CLIENTSSO.EnableAutoProxy = True
    CLIENTSSO.TimeoutMs = 120000


    ' Create a WebRequest
    Dim SSOreq As New WebRequest
    SSOreq.Method = WebMethod.HTTPGet
    If Not Http.Cookies Is Nothing Then
        Set SSOreq.Cookies = Http.Cookies
    ElseIf Worksheets("Settings").Range("Cookie") <> "" Then
        SSOreq.AddCookie "ASP.NET_SessionId", Worksheets("Settings").Range("Cookie")
    End If


' Set the request format
    ' -> Sets content-type and accept headers and parses the response
    SSOreq.format = WebFormat.JSON

    ' Execute the request and work with the response
    Dim SSOResponse As WebResponse
    Set SSOResponse = CLIENTSSO.Execute(SSOreq)

     If SSOResponse.StatusCode = Ok Then
      If SSOResponse.Data("STATUS") <> "OK" Then
       CLIENTSSO.BaseUrl = Worksheets("Settings").Range("ServerURL") & "api/SomeAssembly/Authenication/Login/SomeMethod"

          Set SSOreq = New WebRequest ' need to clear out cookies from prior request
            SSOreq.Method = WebMethod.HTTPPost
            SSOreq.AddHeader "Origin", "Excel" ' needed for login code on server
            SSOreq.body = "{""Value1"":""" & Value1 & """,""Value2"":""" & Value2& """}"
            SSOreq.format = WebFormat.JSON
           Set SSOResponse = CLIENTSSO.Execute(SSOreq)
            If SSOResponse.Data("STATUS") = "OK" Then
            OpenChrome (SSOResponse.Data("SSOURL")) --here I need help ,how to make it wait ,until the browser authentciates and how I can i read the cookie value from the browser once it is set 

            End If

           End If
        End If

 Set VCLSSOLogon = SSOResponse

End Function
 
Not enough info to help you here.

Looks like you have some add-in and/or library used in your code. I'd recommend asking the author/support forum for the add-in/library.
As we have no idea what is going on in the background (normally vba isn't good at working with chrome and requires some sort of wrapper to handle it).

At least give us full detail of what references are added to your code.
 
Back
Top