Announcement

Collapse
No announcement yet.

How to set Authorization Header with HTTP.Submit?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to set Authorization Header with HTTP.Submit?

    I’m trying to use the Google Calendar API with AMS. I am able to successfully login and get my authentication token using ClientLogin with HTTP.SubmitSecure. Once I have my authentication token, it says :

    Since all requests to private feeds require authentication, you have to set the Authorization header in the request, using the following format:

    Authorization: GoogleLogin auth=yourAuthToken

    Where yourAuthToken is the Auth string returned by the login request.
    I don’t know how to set the Authorization header to that. I have tried several mutations of my code and none of them work. Below is just one example that I have tried.

    By the way, in case it isn’t obvious, in my code the variable that holds yourAuthToken is strAuthCode

    Code:
    myauth = {["Authorization: GoogleLogin auth"]=strAuthCode}
    myvalues = {accountType="GOOGLE", service="cl", v="2", Email="[email protected]", source="jimCo-testApp"};
    strAllCals = HTTP.Submit("http://www.google.com/calendar/feeds/default/allcalendars/full", myvalues, SUBMITWEB_POST, 20, 443, myauth, nil);
    Does anyone have any ideas?

  • #2
    Since all requests to private feeds require authentication, you have to set the Authorization header in the request, using the following format:

    Authorization: GoogleLogin auth=yourAuthToken

    Where yourAuthToken is the Auth string returned by the login request.
    it means that you must setup a custom HTTP header with your request which is not possible with current HTTP.* actions of AMS

    but this is possible with LuaCom plugin using SetRequestHeader(); method of WinHttpRequest COM interface


    Code:
    local strAuthToken = "123456789abcdefghijklm"
    local strAuthHeader = string.format("GoogleLogin auth=%s",strAuthToken);
    local strUrlArguments = "?accountType=%s&service=%s&v=%s&Email=%s&source=%s"
    local strValues = string.format(strUrlArguments,"GOOGLE","cl","2","[email protected]","jimCo-testApp");
    local targetURL = "http://www.google.com/calendar/feeds/default/allcalendars/full"
                                    
    local GoogleCal = luacom.CreateObject("WinHttp.WinHttpRequest.5.1");
    
      if (GoogleCal ~= nil) then 
    
        GoogleCal:Open("GET", targetURL..strValues, 0) 
        GoogleCal:SetRequestHeader("Authorization", strAuthHeader );
        GoogleCal:Send(); 
         
         if (GoogleCal.Status == 200) then
        
            local result = GoogleCal.ResponseText
            Dialog.Message("Google's Response", result); 
            
         else
    
           Dialog.Message("Error", "Failed To Complete Http Request");
           
        end
        
     GoogleCal = nil;
     collectgarbage();
        
    end
    you can view more info about WinHttpRequest here
    This is ASP script i used to test the code obove
    Code:
    <%
    response.write "Raw HTTP Headers :"&vbCrlf&vbCrlf
    response.write request.servervariables("ALL_HTTP")&vbCrlf
    response.write "Arguments In Url  :"&vbCrlf&vbCrlf
    for each x in request.querystring()
    response.write x&" : "&request.querystring(x)&vbCrlf
    next
    response.write vbCrlf&vbCrlf
    response.write "This Is The Header That Google Expects :"&vbCrlf&vbCrlf
    response.write request.servervariables("HTTP_AUTHORIZATION")
    %>
    This is local HTTP header test result of the code above
    Attached Files
    amsplugins.com Is Closed.

    Facebook Page

    Comment


    • #3
      Alternate Method

      Hey, i have setup a php script on my server that you can perform a http submit to for ease of use and no external libarys or plugins are needed.

      Parameters: Email, Passwd, service, source
      The params are the same as google and no header is needed, the return is a auth token for use in the application.

      I hope this helps with your problem

      Nathaniel Blackburn
      LunaStudios Software Inc.
      Last edited by infinityscape; 05-03-2010, 01:45 PM.

      Comment


      • #4
        Originally posted by infinityscape View Post
        Hey, i have setup a php script on my server that you can perform a http submit to for ease of use and no external libarys or plugins are needed.





        The params are the same as google and no header is needed, the return is a auth token for use in the application.

        I hope this helps with your problem

        Nathaniel Blackburn
        LunaStudios Software Inc.
        Why use external scripts we can't look into when a lua solution is posted above?
        Bas Groothedde
        Imagine Programming :: Blog

        AMS8 Plugins
        IMXLH Compiler

        Comment


        • #5
          hey imagine, i was suggesting another method.

          and being on his post it states he was using HTTP.Submit i thought id try and make that happen for him so it would be possible to use that and also to try and take away alot of the hard work needed for this to work properly. i would of also attached the script without any problems if i was asked.

          Nathaniel Blackburn
          LunaStudios Software Inc.
          Attached Files
          Last edited by infinityscape; 05-04-2010, 01:25 AM.

          Comment


          • #6
            Originally posted by infinityscape View Post
            hey imagine, i was suggesting another method.

            and being on his post it states he was using HTTP.Submit i thought id try and make that happen for him so it would be possible to use that and also to try and take away alot of the hard work needed for this to work properly. i would of also attached the script without any problems if i was asked.

            Nathaniel Blackburn
            LunaStudios Software Inc.
            Yes and that is Nice of you to do mate, but I for one wouldn't use it because
            I don't like sending login data to third party sites first. :yes
            Bas Groothedde
            Imagine Programming :: Blog

            AMS8 Plugins
            IMXLH Compiler

            Comment


            • #7
              Download Link For &quot;gauth.php&quot; Added

              ok i added the script for people to download, enjoy and i hope it proves useful for people. my appologies for misunderstanding Imagine Programming

              Nathaniel Blackburn
              LunaStudios Software Inc.
              Attached Files
              Last edited by infinityscape; 05-04-2010, 03:26 AM.

              Comment


              • #8
                Originally posted by infinityscape View Post
                ok i added the script for people to download, enjoy and i hope it proves useful for people. my appologies for misunderstanding Imagine Programming
                Thanks, now I will probably use it :yes
                Bas Groothedde
                Imagine Programming :: Blog

                AMS8 Plugins
                IMXLH Compiler

                Comment


                • #9
                  Originally posted by Imagine Programming View Post
                  Thanks, now I will probably use it :yes
                  It dose make life a lot easy to use php for that kind of job in my eyes thanks Nath for this :yes

                  Comment


                  • #10
                    Originally posted by infinityscape View Post
                    hey imagine, i was suggesting another method.

                    and being on his post it states he was using HTTP.Submit i thought id try and make that happen for him so it would be possible to use that and also to try and take away alot of the hard work needed for this to work properly. i would of also attached the script without any problems if i was asked.

                    Nathaniel Blackburn
                    LunaStudios Software Inc.
                    i am not familiar with Google APIs but
                    i do recommend reading the question again

                    Originally posted by JimS View Post
                    I’m trying to use the Google Calendar API with AMS. I am able to successfully login and get my authentication token using ClientLogin with HTTP.SubmitSecure. Once I have my authentication token, it says :
                    so in this case you have suggested 45 lines of PHP script whereas it could be done using HTTP.Submit() (only single line and without external source) :yes

                    he actually wants to get result from google using authentication token that is returned by last login attemp using ClientLogin with HTTP.SubmitSecure
                    and this token must be injected into request header of next HTTP request to be able to get results from google
                    amsplugins.com Is Closed.

                    Facebook Page

                    Comment


                    • #11
                      Sorry to ask a question then disappear for a week. What can I say, life happens. Thank you gentlemen so much your answers. I haven’t done much with the COM object, so I didn’t even think about it, nor did I consider a php method. Frankly I expected I’d need to use one of the many libraries out there like cURL or something. Thank you guys, for showing me your solutions.
                      I just started looking at the APIs that Google offers. It’s quite an impressive collection. I’d like to figure out a way to interface with them from my AMS programs that keeps the code as clean and simple and portable as possible. I’d like to try my hand programming against several of the API’s.
                      I don’t know enough about headers, that much is obvious. Thank you guys again, you got me up and moving again on my goal.

                      Reteset you are correct that I am able to get my authorization token,:yes I just couldn’t figure out the way to correctly pass that information and the query back to the API. Your guys help gets me on my way.

                      Comment


                      • #12
                        Originally posted by reteset View Post
                        Code:
                        local strAuthToken = "123456789abcdefghijklm"
                        local strAuthHeader = string.format("GoogleLogin auth=%s",strAuthToken);
                        local strUrlArguments = "?accountType=%s&service=%s&v=%s&Email=%s&source=%s"
                        local strValues = string.format(strUrlArguments,"GOOGLE","cl","2","[email protected]","jimCo-testApp");
                        local targetURL = "http://www.google.com/calendar/feeds/default/allcalendars/full"
                                                        
                        local GoogleCal = luacom.CreateObject("WinHttp.WinHttpRequest.5.1");
                        
                          if (GoogleCal ~= nil) then 
                        
                            GoogleCal:Open("GET", targetURL..strValues, 0) 
                            GoogleCal:SetRequestHeader("Authorization", strAuthHeader );
                            GoogleCal:Send(); 
                             
                             if (GoogleCal.Status == 200) then
                            
                                local result = GoogleCal.ResponseText
                                Dialog.Message("Google's Response", result); 
                                
                             else
                        
                               Dialog.Message("Error", "Failed To Complete Http Request");
                               
                            end
                            
                         GoogleCal = nil;
                         collectgarbage();
                            
                        end
                        This is really cool, I'm gonna save this to a text file and use it next time I need to send my own headers (and maybe my own User-Agent).

                        Comment

                        Working...
                        X
                        😀
                        🥰
                        🤢
                        😎
                        😡
                        👍
                        👎