How do you send an XMLHttpRequest to GAE that identifies the logged in user?

29 views
Skip to first unread message

Brendon Duncan

unread,
Sep 2, 2015, 3:13:20 PM9/2/15
to Google App Engine

My site uses the built-in login system to get to the page, like this:


func handler(w http.ResponseWriter, r *http.Request) {
    c
:= appengine.NewContext(r)
    u
:= user.Current(c)

   
if u == nil {
        url
, err := user.LoginURL(c, r.URL.String())
       
if err != nil {
            http
.Error(w, err.Error(), http.StatusInternalServerError)
           
return
       
}

        w
.Header().Set("Location", url)
        w
.WriteHeader(http.StatusFound)
       
return
   
}

    fmt
.Fprintf(w, "Hello, %v!", u)
}
 

How do I include that user info when doing an XMLHttpRequest from that page to a different url handled by the same GAE app?


I want to make sure that only logged in users have access to the url used for the XMLHttpRequest.

Patrice (Cloud Platform Support)

unread,
Sep 3, 2015, 9:58:12 AM9/3/15
to Google App Engine
Hi Brendon,

For those kind of questions, we normally suggest posting on Stack Overflow, since this is better suited to those kind of Q&As. I noticed a question with a very similar intent and wording has been posted on Stack at about the same time as this thread has been opened. I will assume this post is yours. No need to do a cross-post here, since we do monitor both websites.

To do a quick breakdown, the Cloud Platform community has three different venues to post:

1- Stack Exchange: Some sites of the network (SuperUser, StackOverflow) can be used to post your question. We do have members of the support team looking at our tags there and answering questions, on top of the very active community. If you post there, make sure your question follows the site's guidelines.

2- Google Groups: Suited for discussions, best practices, tools recommendations, other kind of questions that don't suit Stack Exchange.

3- Issue Tracker: Used to send feature requests and defect reports about the platform.

Cheers!
Reply all
Reply to author
Forward
0 new messages