i use play-framework 1.2.1 oAuth 2.0 connect to facebookk to get access_token have problem

291 views
Skip to first unread message

MrIcE

unread,
May 10, 2011, 2:32:36 AM5/10/11
to play-framework
i copy play-framework 1.2.1 facebook-oauth2 sample to run
it always not print out facebook user name,
i print out the Authentication Request URL

for example
(1)
https://www.facebook.com/dialog/oauth
?client_id=YOUR_APP_ID
&redirect_uri=http://localhost:9000/

(2)
https://graph.facebook.com/oauth/access_token
?client_id=YOUR_APP_ID
&redirect_uri=http://localhost:9000/?code=XXXXXXXXXXXXXXXXXXXXXXXXX
&client_secret=YOUR_APP_SECRET
&code=XXXXXXXXXXXXXXXXXXXXXXXXX


i found that (2) 's redirect_uri is different with (1),it has one more
paramater code

if i cut off the (2)'s redirect_uri http://localhost:9000/?code=XXXXXXXXXXXXXXXXXXXXXXXXX
to http://localhost:9000/
facebook return access_token

i check the play.,libs.Oauth2 source code

public class OAuth2 {
:
:

public String getAccessToken() {
String callbackURL = Request.current().getBase() +
Request.current().url;
String accessCode = Params.current().get("code");
Map<String, Object> params = new HashMap<String, Object>();
params.put("client_id", clientid);
params.put("client_secret", secret);
params.put("redirect_uri", callbackURL);
params.put("code", accessCode);
Map<String, String> response =
WS.url(authorizationURL).params(params).get().getQueryString();
return response.get("access_token");
}
}

The Oauth2.getAccessToken() use Request.current().url to get full url
include facebook return code paramater

it maybe need change something,or i miss something.


Erwan Loisant

unread,
May 10, 2011, 4:03:47 AM5/10/11
to play-fr...@googlegroups.com
Hi,

The current implementation has a few issues indeed, that will be fixed
in the next version. In the mean time you can pull the correct file
from github and include it in your project.
https://github.com/playframework/play/blob/1.2.x/framework/src/play/libs/OAuth2.java

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

--
Erwan Loisant

Joseph Burns

unread,
May 30, 2011, 4:50:14 PM5/30/11
to play-framework
I pulled this as well, and noticed that a lot of the methods used in
the sample oauth2-facebook exemple are deprecated. Is there an
example floating around of how one *should* now use this small
library? I still can't seem to get it to work (no problems with
fbgraph, just wanted to try this one out).

On May 10, 4:03 am, Erwan Loisant <elois...@gmail.com> wrote:
> Hi,
>
> The current implementation has a few issues indeed, that will be fixed
> in the next version. In the mean time you can pull the correct file
> from github and include it in your project.https://github.com/playframework/play/blob/1.2.x/framework/src/play/l...
>
>
>
>
>
>
>
>
>
> On Tue, May 10, 2011 at 08:32, MrIcE <ice.aa...@gmail.com> wrote:
> > i copy play-framework 1.2.1 facebook-oauth2sample to run
> > it always not print out facebook user name,
> > i print out the Authentication Request URL
>
> > for example
> > (1)
> >https://www.facebook.com/dialog/oauth
> > ?client_id=YOUR_APP_ID
> > &redirect_uri=http://localhost:9000/
>
> > (2)
> >https://graph.facebook.com/oauth/access_token
> > ?client_id=YOUR_APP_ID
> > &redirect_uri=http://localhost:9000/?code=XXXXXXXXXXXXXXXXXXXXXXXXX
> > &client_secret=YOUR_APP_SECRET
> > &code=XXXXXXXXXXXXXXXXXXXXXXXXX
>
> > i found that (2) 's redirect_uri is different with (1),it has one more
> > paramater code
>
> > if i cut off the (2)'s redirect_urihttp://localhost:9000/?code=XXXXXXXXXXXXXXXXXXXXXXXXX
> > tohttp://localhost:9000/
> > facebook return access_token
>
> > i check the play.,libs.Oauth2source code
>
> > public classOAuth2{
> >           :
> >           :
>
> >    public String getAccessToken() {
> >        String callbackURL = Request.current().getBase() +
> > Request.current().url;
> >        String accessCode = Params.current().get("code");
> >        Map<String, Object> params = new HashMap<String, Object>();
> >        params.put("client_id", clientid);
> >        params.put("client_secret", secret);
> >        params.put("redirect_uri", callbackURL);
> >        params.put("code", accessCode);
> >        Map<String, String> response =
> > WS.url(authorizationURL).params(params).get().getQueryString();
> >        return response.get("access_token");
> >    }
> > }
>
> > TheOauth2.getAccessToken() use  Request.current().url to get full url

Erwan Loisant

unread,
May 31, 2011, 3:34:48 AM5/31/11
to play-fr...@googlegroups.com
On Mon, May 30, 2011 at 22:50, Joseph Burns <jbu...@projectscribe.com> wrote:
> I pulled this as well, and noticed that a lot of the methods used in
> the sample oauth2-facebook exemple are deprecated.  Is there an
> example floating around of how one *should* now use this small
> library?  I still can't seem to get it to work (no problems with
> fbgraph, just wanted to try this one out).

Actually now that 1.2.2RC1 has been released, I recommend you to use
this one. You no longer need to pull code from github.

Also there's an example of usage in samples-and-tests/facebook-oauth2

Joseph Burns

unread,
May 31, 2011, 9:58:33 PM5/31/11
to play-framework
I just downloaded it, works great...thanks for the heads-up!

--Joe

On May 31, 3:34 am, Erwan Loisant <elois...@gmail.com> wrote:
> On Mon, May 30, 2011 at 22:50, Joseph Burns <jbu...@projectscribe.com> wrote:
> > I pulled this as well, and noticed that a lot of the methods used in
> > the sampleoauth2-facebook exemple are deprecated.  Is there an
Reply all
Reply to author
Forward
0 new messages