FAQ
I'm trying to do server-side auth with facebook, i can get to login dialog
and permission, but after redirect i didn't get the auth 'code' in redirect
handler. any suggestion?

FBCfg = &oauth.Config { //setup
ClientId: appId, ClientSecret: appSecret,
AuthURL: "https://www.facebook.com/dialog/oauth",
TokenURL: "https://graph.facebook.com/oauth/access_token",
RedirectURL: "http://"+domain+"/fedlogin/facebook/redir",
Scope: "",}

func FBHandleAuth(w http.ResponseWriter, r *http.Request) {
url := FBCfg.AuthCodeURL("")
http.Redirect(w, r, url, http.StatusFound)}

func FBHandleRedir(w http.ResponseWriter, r *http.Request) {
code := r.FormValue("code")
w.Write([]byte(code)) //<-- empty, no code returned.}

Note: I'm using original goauth2 latest version.

--

Search Discussions

  • Paddy Foran at Dec 20, 2012 at 3:25 am
    What URL are you being redirected to?

    Thanks,
    Paddy Foran

    On Wed, Dec 19, 2012 at 10:17 PM, kar wrote:

    I'm trying to do server-side auth with facebook, i can get to login dialog
    and permission, but after redirect i didn't get the auth 'code' in redirect
    handler. any suggestion?

    FBCfg = &oauth.Config { //setup
    ClientId: appId, ClientSecret: appSecret,
    AuthURL: "https://www.facebook.com/dialog/oauth",
    TokenURL: "https://graph.facebook.com/oauth/access_token",
    RedirectURL: "http://"+domain+"/fedlogin/facebook/redir",
    Scope: "",}

    func FBHandleAuth(w http.ResponseWriter, r *http.Request) {
    url := FBCfg.AuthCodeURL("")
    http.Redirect(w, r, url, http.StatusFound)}

    func FBHandleRedir(w http.ResponseWriter, r *http.Request) {
    code := r.FormValue("code")
    w.Write([]byte(code)) //<-- empty, no code returned.}

    Note: I'm using original goauth2 latest version.

    --

    --
  • Kar at Dec 20, 2012 at 3:30 am
    FB redirected to here "http://DOMAIN/fedlogin/facebook/redir/#_=_" which
    handled by my FBHandleRedit function
    On Thursday, December 20, 2012 11:24:51 AM UTC+8, Paddy Foran wrote:

    What URL are you being redirected to?

    Thanks,
    Paddy Foran


    On Wed, Dec 19, 2012 at 10:17 PM, kar <akma...@gmail.com <javascript:>>wrote:
    I'm trying to do server-side auth with facebook, i can get to login
    dialog and permission, but after redirect i didn't get the auth 'code' in
    redirect handler. any suggestion?

    FBCfg = &oauth.Config { //setup
    ClientId: appId, ClientSecret: appSecret,
    AuthURL: "https://www.facebook.com/dialog/oauth",
    TokenURL: "https://graph.facebook.com/oauth/access_token",
    RedirectURL: "http://"+domain+"/fedlogin/facebook/redir",
    Scope: "",}

    func FBHandleAuth(w http.ResponseWriter, r *http.Request) {
    url := FBCfg.AuthCodeURL("")
    http.Redirect(w, r, url, http.StatusFound)}

    func FBHandleRedir(w http.ResponseWriter, r *http.Request) {
    code := r.FormValue("code")
    w.Write([]byte(code)) //<-- empty, no code returned.}

    Note: I'm using original goauth2 latest version.

    --

    --
  • Andrew Gerrand at Dec 20, 2012 at 3:38 am

    On 20 December 2012 14:30, kar wrote:

    FB redirected to here "http://DOMAIN/fedlogin/facebook/redir/#_=_" which
    handled by my FBHandleRedit function
    It seems that Facebook isn't giving you the code. Does the authentication
    process appear to work otherwise?

    --
  • Kar at Dec 20, 2012 at 3:42 am
    It did, i managed to get login dialog and permission, after the approval,
    it redirect to url as mentioned above, nothing in the Body part, Get and
    Post
    On Thursday, December 20, 2012 11:38:21 AM UTC+8, Andrew Gerrand wrote:
    On 20 December 2012 14:30, kar <akma...@gmail.com <javascript:>> wrote:

    FB redirected to here "http://DOMAIN/fedlogin/facebook/redir/#_=_" which
    handled by my FBHandleRedit function
    It seems that Facebook isn't giving you the code. Does the authentication
    process appear to work otherwise?
    --
  • Andrew Gerrand at Dec 20, 2012 at 3:48 am

    On 20 December 2012 14:42, kar wrote:

    It did, i managed to get login dialog and permission, after the approval,
    it redirect to url as mentioned above, nothing in the Body part, Get and
    Post
    Is there anything else that might be intercepting or modifying the queries?

    In Facebook's docs about their login process,
    http://developers.facebook.com/docs/howtos/login/server-side-login/#step5
    they describe the response as:
    YOUR_REDIRECT_URI?
    state=YOUR_STATE_VALUE
    &code=CODE_GENERATED_BY_FACEBOOK
    and so it *must* include a code.

    Try adding some state to the FBCfg.AuthCodeURL("") call, and see if it is
    propagated through to the response.

    Andrew

    --
  • Kar at Dec 20, 2012 at 4:19 am
    same thing as before. Here is the Url generated by, url :=
    FBCfg.AuthCodeURL("foo")

    https://www.facebook.com/dialog/oauth?response_type=code&scope=&state=foo&access_type=&client_id=XXX+&approval_prompt=&redirect_uri=http%3A%2F%2FDOMAIN%3A88%2Ffedlogin%2Ffacebook%2Fredir


    On Thursday, December 20, 2012 11:47:44 AM UTC+8, Andrew Gerrand wrote:



    On 20 December 2012 14:42, kar <akma...@gmail.com <javascript:>> wrote:

    It did, i managed to get login dialog and permission, after the approval,
    it redirect to url as mentioned above, nothing in the Body part, Get and
    Post
    Is there anything else that might be intercepting or modifying the
    queries?

    In Facebook's docs about their login process,

    http://developers.facebook.com/docs/howtos/login/server-side-login/#step5
    they describe the response as:
    YOUR_REDIRECT_URI?
    state=YOUR_STATE_VALUE
    &code=CODE_GENERATED_BY_FACEBOOK
    and so it *must* include a code.

    Try adding some state to the FBCfg.AuthCodeURL("") call, and see if it is
    propagated through to the response.

    Andrew
    --
  • Andrew Gerrand at Dec 20, 2012 at 4:26 am

    On 20 December 2012 15:19, kar wrote:

    same thing as before. Here is the Url generated by, url :=
    FBCfg.AuthCodeURL("foo")

    https://www.facebook.com/dialog/oauth?response_type=code&scope=&state=foo&access_type=&client_id=XXX+&approval_prompt=&redirect_uri=http%3A%2F%2FDOMAIN%3A88%2Ffedlogin%2Ffacebook%2Fredir

    Double check that the client_id field is correct. Is there supposed to be
    a + after it? Other than that, I'm out of suggestions. The goauth2 library
    seems to be generating a valid auth code URL, but Facebook isn't returning
    a code. :-/

    Andrew

    --
  • Kar at Dec 20, 2012 at 5:44 am
    Fixed client_id (was a space there before) but no luck, i'll update here
    when i found the problem. Thanks for quick response Andrew.
    On Thursday, December 20, 2012 12:26:19 PM UTC+8, Andrew Gerrand wrote:


    On 20 December 2012 15:19, kar <akma...@gmail.com <javascript:>> wrote:

    same thing as before. Here is the Url generated by, url :=
    FBCfg.AuthCodeURL("foo")

    https://www.facebook.com/dialog/oauth?response_type=code&scope=&state=foo&access_type=&client_id=XXX+&approval_prompt=&redirect_uri=http%3A%2F%2FDOMAIN%3A88%2Ffedlogin%2Ffacebook%2Fredir

    Double check that the client_id field is correct. Is there supposed to be
    a + after it? Other than that, I'm out of suggestions. The goauth2 library
    seems to be generating a valid auth code URL, but Facebook isn't returning
    a code. :-/

    Andrew
    --
  • Kar at Dec 20, 2012 at 12:49 pm
    Solved. There's a problem with the RedirectUrl in my Go code.

    RedirectURL: "http://"+domain+"/fedlogin/facebook/redir"

    it works after i append slash to the url "/fedlogin/facebook/redir/"

    probably because of how i define the http handler for this path. Thanks for
    all the help.
    On Thursday, December 20, 2012 1:43:36 PM UTC+8, kar wrote:

    Fixed client_id (was a space there before) but no luck, i'll update here
    when i found the problem. Thanks for quick response Andrew.
    On Thursday, December 20, 2012 12:26:19 PM UTC+8, Andrew Gerrand wrote:


    On 20 December 2012 15:19, kar wrote:

    same thing as before. Here is the Url generated by, url :=
    FBCfg.AuthCodeURL("foo")

    https://www.facebook.com/dialog/oauth?response_type=code&scope=&state=foo&access_type=&client_id=XXX+&approval_prompt=&redirect_uri=http%3A%2F%2FDOMAIN%3A88%2Ffedlogin%2Ffacebook%2Fredir

    Double check that the client_id field is correct. Is there supposed to
    be a + after it? Other than that, I'm out of suggestions. The goauth2
    library seems to be generating a valid auth code URL, but Facebook isn't
    returning a code. :-/

    Andrew
    --
  • Rif at Dec 20, 2012 at 1:52 pm
    I get this error after I was using your solution for FB. What I am doing wrong?


    {
    "error": {
    "message": "Unknown OAuth 2.0 method, oauth.",
    "type": "OAuthException",
    "code": 1
    }
    }


    My url is:


    https://graph.facebook.com/oauth/oauth?access_type=&approval_prompt=&client_id=XXXX&redirect_uri=http%3A%2F%2Fwww.lov3ly.me%2Ffblogin%2F&response_type=code&scope=user_birthday%2C+email%2C+user_location&state= <https://graph.facebook.com/oauth/oauth?access_type=&approval_prompt=&client_id=367020756724332&redirect_uri=http%3A%2F%2Fwww.lov3ly.me%2Ffblogin%2F&response_type=code&scope=user_birthday%2C+email%2C+user_location&state=>



    -rif

    joi, 20 decembrie 2012, 14:49:55 UTC+2, kar a scris:
    Solved. There's a problem with the RedirectUrl in my Go code.

    RedirectURL: "http://"+domain+"/fedlogin/facebook/redir"

    it works after i append slash to the url "/fedlogin/facebook/redir/"

    probably because of how i define the http handler for this path. Thanks
    for all the help.
    On Thursday, December 20, 2012 1:43:36 PM UTC+8, kar wrote:

    Fixed client_id (was a space there before) but no luck, i'll update here
    when i found the problem. Thanks for quick response Andrew.
    On Thursday, December 20, 2012 12:26:19 PM UTC+8, Andrew Gerrand wrote:


    On 20 December 2012 15:19, kar wrote:

    same thing as before. Here is the Url generated by, url :=
    FBCfg.AuthCodeURL("foo")

    https://www.facebook.com/dialog/oauth?response_type=code&scope=&state=foo&access_type=&client_id=XXX+&approval_prompt=&redirect_uri=http%3A%2F%2FDOMAIN%3A88%2Ffedlogin%2Ffacebook%2Fredir

    Double check that the client_id field is correct. Is there supposed to
    be a + after it? Other than that, I'm out of suggestions. The goauth2
    library seems to be generating a valid auth code URL, but Facebook isn't
    returning a code. :-/

    Andrew
    --
  • Andrew Gerrand at Dec 20, 2012 at 8:39 pm
    Looks to me like your AuthURL is wrong. It should be "
    https://www.facebook.com/dialog/oauth" (yours is /oauth/oauth)

    Andrew

    --
  • Rif at Dec 20, 2012 at 8:53 pm
    This was it. Now it works with both fb and google :)

    Thanks a lot,
    -rif

    joi, 20 decembrie 2012, 22:38:45 UTC+2, Andrew Gerrand a scris:
    Looks to me like your AuthURL is wrong. It should be "
    https://www.facebook.com/dialog/oauth" (yours is /oauth/oauth)

    Andrew
    --
  • Kar at Dec 22, 2012 at 10:31 am
    Just a small question, is code below correct?

    from http://code.google.com/p/goauth2/source/browse/oauth/oauth.go

    line 310: b.ExpiresIn, _ = time.ParseDuration(vals.Get("expires") + "s")

    and

    line 324: tok.Expiry = time.Now().Add(b.ExpiresIn * time.Second)

    "expires" already suffix with "s" in time.ParseDuration, why the need to
    multiply with time.Second on the 2nd line above?
    On Friday, December 21, 2012 4:38:45 AM UTC+8, Andrew Gerrand wrote:

    Looks to me like your AuthURL is wrong. It should be "
    https://www.facebook.com/dialog/oauth" (yours is /oauth/oauth)

    Andrew
    --
  • Alexander Orlovskiy at Dec 25, 2012 at 5:10 am
    Correct.
    http://golang.org/pkg/time/#ParseDuration
    http://golang.org/pkg/time/#Duration

    суббота, 22 декабря 2012 г., 14:31:53 UTC+4 пользователь kar написал:
    Just a small question, is code below correct?

    from http://code.google.com/p/goauth2/source/browse/oauth/oauth.go

    line 310: b.ExpiresIn, _ = time.ParseDuration(vals.Get("expires") + "s")

    and

    line 324: tok.Expiry = time.Now().Add(b.ExpiresIn * time.Second)

    "expires" already suffix with "s" in time.ParseDuration, why the need to
    multiply with time.Second on the 2nd line above?
    On Friday, December 21, 2012 4:38:45 AM UTC+8, Andrew Gerrand wrote:

    Looks to me like your AuthURL is wrong. It should be "
    https://www.facebook.com/dialog/oauth" (yours is /oauth/oauth)

    Andrew
    --
  • Rif at Jan 6, 2013 at 10:47 am
    I have this weir issue with fb login:

    Sometimes (not always) I get OAuthError: updateToken: 400 Bad Request

    Scope: "user_birthday, email, user_location",
    AuthURL: "https://www.facebook.com/dialog/oauth",
    TokenURL: "https://graph.facebook.com/oauth/access_token",

    I did not use to get this error for the previous workarounds (e.g.
    https://github.com/rif/goauth2)

    Any hints?

    Thanks,
    -rif

    joi, 20 decembrie 2012, 22:38:45 UTC+2, Andrew Gerrand a scris:
    Looks to me like your AuthURL is wrong. It should be "
    https://www.facebook.com/dialog/oauth" (yours is /oauth/oauth)

    Andrew
    --
  • Jason Del Ponte at Dec 21, 2012 at 7:20 am
    Check out http://golang.org/pkg/path/#Join It is very helpful in these
    situations when concatenating path elements together.
    On Thursday, December 20, 2012 4:49:55 AM UTC-8, kar wrote:

    Solved. There's a problem with the RedirectUrl in my Go code.

    RedirectURL: "http://"+domain+"/fedlogin/facebook/redir"

    it works after i append slash to the url "/fedlogin/facebook/redir/"

    probably because of how i define the http handler for this path. Thanks
    for all the help.
    On Thursday, December 20, 2012 1:43:36 PM UTC+8, kar wrote:

    Fixed client_id (was a space there before) but no luck, i'll update here
    when i found the problem. Thanks for quick response Andrew.
    On Thursday, December 20, 2012 12:26:19 PM UTC+8, Andrew Gerrand wrote:


    On 20 December 2012 15:19, kar wrote:

    same thing as before. Here is the Url generated by, url :=
    FBCfg.AuthCodeURL("foo")

    https://www.facebook.com/dialog/oauth?response_type=code&scope=&state=foo&access_type=&client_id=XXX+&approval_prompt=&redirect_uri=http%3A%2F%2FDOMAIN%3A88%2Ffedlogin%2Ffacebook%2Fredir

    Double check that the client_id field is correct. Is there supposed to
    be a + after it? Other than that, I'm out of suggestions. The goauth2
    library seems to be generating a valid auth code URL, but Facebook isn't
    returning a code. :-/

    Andrew
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 20, '12 at 3:17a
activeJan 6, '13 at 10:47a
posts17
users6
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase