My asana oauth redirect URL is something like
https://testapp.appspot.com/api/redirect.asana#access_token=123456789
I am not sure how to fetch access_token now.
Note : if I am changing ? to # then its working fine by using r.FormValue("access_token").
The reason why
r.FormValue()
does not get it is because URL parameters are separated by?
but in your URL it is not.The
#
is used to separate a fragment for references, so youraccess_token
should be inr.URL.Fragment
... but it won't.You can't test it from the browser
Fragments are not sent over to the server, fragments are for the browsers. There was an issue covering this:
net/http: document fields set in Request.URL in handler #3805
It is also included in the doc of
http.Request
:Code to get it from the request
If a non-browser client does send it as part of the request path, you can use simple
string
operations to get the token value: it is the part after the=
character. You can usestrings.Index()
to find the"="
:Output:
As an alternative solution you can also use
strings.Split()
to split it by"="
, 2nd element will be the value of the token:Output:
Code to test it
Here is a code using
net/http
to call your server that will send a path being"/api/redirect.asana#access_token=123456789"
, and it will print the response body to the standard output (console):