You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Stephen Walsh <st...@connectwithawalsh.com> on 2013/02/18 04:28:19 UTC

Anyone using Wicket-Stuff Facebook

https://github.com/wicketstuff/core/wiki/Facebook

Anyone using this that can point me in the right direction on how to use
the behaviors?

I followed the example on getting a login button and it seems like that
works well, but I have no idea to tell if the user has validated and how to
capture that validation.  Clearly it's in the behaviors section of the jar,
but I'm not quite sure how to use it.

Thanks.
_______________________________________
Stephen Walsh | http://connectwithawalsh.com

Re: Anyone using Wicket-Stuff Facebook

Posted by Stephen Walsh <st...@connectwithawalsh.com>.
This was the code that I implemented to get the access Token.  Obviously it
isn't finished yet because I need to implement some error handling, actual
saving and of the user, etc., but it's a framework that hopefully can help
someone else that wants to use OAuth in the Scribe package.

Note: I'm also using RestFB instead of the wicket-stuff package.  It made a
lot more sense to me and seemed to have better user support.  I'm sure
wicket-facebook would work just as well here.


public class LoggedOutPanel extends Panel {

private static final String apiKey = "my_api_key";
 private static final String apiSecret = "my_api_secret";
private static final Token EMPTY_TOKEN = null;
 private static final OAuthService service = new ServiceBuilder()
.provider(FacebookApi.class)
 .apiKey(apiKey)
.apiSecret(apiSecret)
 .callback("http://localhost:8080/project-1.0-SNAPSHOT/signin")
 .build();
 public LoggedOutPanel (String id, PageParameters parameters) {
super(id);
 final ExternalLink fbLogin = new ExternalLink("fb-login",
service.getAuthorizationUrl(EMPTY_TOKEN));
 fbLogin.add(new Image("fb-login-img", new
ContextRelativeResource("/images/facebook_login.png")));
 add(fbLogin);
 }
}

public final class SignIn extends BasePage {
 private static final String apiKey = "my_api_key";
 private static final String apiSecret = "my_api_secret";
private static final Token EMPTY_TOKEN = null;
 private static final OAuthService service = new ServiceBuilder()
.provider(FacebookApi.class)
 .apiKey(apiKey)
.apiSecret(apiSecret)
 .callback("http://localhost:8080/project-1.0-SNAPSHOT/signin")
 .build();
private String ACCESS_TOKEN;
 public SignIn(final PageParameters parameters) {
 if(parameters.isEmpty()) {
// TODO Try logging in again
 } else {
Verifier verifier = new Verifier(parameters.get("code").toString());
 Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
ACCESS_TOKEN = accessToken.getToken().toString();
 FacebookClient fb = new DefaultFacebookClient(ACCESS_TOKEN);
Person user = fb.fetchObject("me", Person.class, Parameter.with("fields",
"username"));
 System.out.println("User name: " + user.getUsername());
}
 }
}

_______________________________________
Stephen Walsh | http://connectwithawalsh.com


On Thu, Feb 21, 2013 at 12:27 AM, Stephen Walsh <
stephen@connectwithawalsh.com> wrote:

> I got this figure out. I'll post my solution tomorrow when I have a few
> minutes.
>
> Basically, I wasn't understanding that the code was coming back in a page
> parameter. Once I understood that it was fairly easy to implement.
>
>
> On Monday, February 18, 2013, Stephen Walsh wrote:
>
>> That's where I'm headed right now.  I had a signin page with
>> PageParameters that picked it up by accident...  I think I'm headed in the
>> right direction now.
>>
>> I'll post my solution when I get it finished.  I'd still be interested to
>> see your solution also.
>>
>> Thanks again.
>>
>> _______________________________________
>> Stephen Walsh | http://connectwithawalsh.com
>>
>>
>> On Mon, Feb 18, 2013 at 6:29 PM, Michael Chandler <
>> Michael.Chandler@onassignment.com> wrote:
>>
>>> > The browser gets a token back that makes perfect sense and the example
>>> is completed.
>>> > How do I "consume" the token?  I'll play around with it a bit and let
>>> you know what
>>> > I come up with.  Thanks for the help.
>>>
>>> Based on the path I was taking, the redirect URI is the key.  Facebook
>>> redirects as such:
>>>
>>> YOUR_REDIRECT_URI?
>>>     access_token=USER_ACCESS_TOKEN
>>>    &expires_in=NUMBER_OF_SECONDS_UNTIL_TOKEN_EXPIRES
>>>    &state=YOUR_STATE_VALUE
>>>
>>> Of course, if the request fails authentication, they redirect as follows:
>>>
>>> YOUR_REDIRECT_URI?
>>>     error_reason=user_denied
>>>    &error=access_denied
>>>    &error_description=The+user+denied+your+request.
>>>    &state=YOUR_STATE_VALUE
>>>
>>> So your redirect page could start out like this:
>>>
>>> public class FacebookResponseListener extends WebPage {
>>>
>>>         private static final long serialVersionUID = 1L;
>>>
>>>         public FacebookResponseListener(PageParameters params) {
>>>                 // if there is an error, handle it
>>>                 if (params.get("error_reason") != null) {
>>>                         // handle the error here!
>>>                 } else {
>>>                         String accessToken =
>>> params.get("access_token").toString();
>>>                         int expiresIn = params.get("expires_in").toInt();
>>>
>>>                         // etc... etc...
>>>
>>>                 }
>>>
>>>         }
>>> }
>>>
>>> Mike
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>
> --
> _______________________________________
> Stephen Walsh | http://connectwithawalsh.com
>
>

Re: Anyone using Wicket-Stuff Facebook

Posted by Stephen Walsh <st...@connectwithawalsh.com>.
I got this figure out. I'll post my solution tomorrow when I have a few
minutes.

Basically, I wasn't understanding that the code was coming back in a page
parameter. Once I understood that it was fairly easy to implement.

On Monday, February 18, 2013, Stephen Walsh wrote:

> That's where I'm headed right now.  I had a signin page with
> PageParameters that picked it up by accident...  I think I'm headed in the
> right direction now.
>
> I'll post my solution when I get it finished.  I'd still be interested to
> see your solution also.
>
> Thanks again.
>
> _______________________________________
> Stephen Walsh | http://connectwithawalsh.com
>
>
> On Mon, Feb 18, 2013 at 6:29 PM, Michael Chandler <
> Michael.Chandler@onassignment.com <javascript:_e({}, 'cvml',
> 'Michael.Chandler@onassignment.com');>> wrote:
>
>> > The browser gets a token back that makes perfect sense and the example
>> is completed.
>> > How do I "consume" the token?  I'll play around with it a bit and let
>> you know what
>> > I come up with.  Thanks for the help.
>>
>> Based on the path I was taking, the redirect URI is the key.  Facebook
>> redirects as such:
>>
>> YOUR_REDIRECT_URI?
>>     access_token=USER_ACCESS_TOKEN
>>    &expires_in=NUMBER_OF_SECONDS_UNTIL_TOKEN_EXPIRES
>>    &state=YOUR_STATE_VALUE
>>
>> Of course, if the request fails authentication, they redirect as follows:
>>
>> YOUR_REDIRECT_URI?
>>     error_reason=user_denied
>>    &error=access_denied
>>    &error_description=The+user+denied+your+request.
>>    &state=YOUR_STATE_VALUE
>>
>> So your redirect page could start out like this:
>>
>> public class FacebookResponseListener extends WebPage {
>>
>>         private static final long serialVersionUID = 1L;
>>
>>         public FacebookResponseListener(PageParameters params) {
>>                 // if there is an error, handle it
>>                 if (params.get("error_reason") != null) {
>>                         // handle the error here!
>>                 } else {
>>                         String accessToken =
>> params.get("access_token").toString();
>>                         int expiresIn = params.get("expires_in").toInt();
>>
>>                         // etc... etc...
>>
>>                 }
>>
>>         }
>> }
>>
>> Mike
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org<javascript:_e({}, 'cvml', 'users-unsubscribe@wicket.apache.org');>
>> For additional commands, e-mail: users-help@wicket.apache.org<javascript:_e({}, 'cvml', 'users-help@wicket.apache.org');>
>>
>>
>

-- 
_______________________________________
Stephen Walsh | http://connectwithawalsh.com

Re: Anyone using Wicket-Stuff Facebook

Posted by Stephen Walsh <st...@connectwithawalsh.com>.
That's where I'm headed right now.  I had a signin page with PageParameters
that picked it up by accident...  I think I'm headed in the right direction
now.

I'll post my solution when I get it finished.  I'd still be interested to
see your solution also.

Thanks again.

_______________________________________
Stephen Walsh | http://connectwithawalsh.com


On Mon, Feb 18, 2013 at 6:29 PM, Michael Chandler <
Michael.Chandler@onassignment.com> wrote:

> > The browser gets a token back that makes perfect sense and the example
> is completed.
> > How do I "consume" the token?  I'll play around with it a bit and let
> you know what
> > I come up with.  Thanks for the help.
>
> Based on the path I was taking, the redirect URI is the key.  Facebook
> redirects as such:
>
> YOUR_REDIRECT_URI?
>     access_token=USER_ACCESS_TOKEN
>    &expires_in=NUMBER_OF_SECONDS_UNTIL_TOKEN_EXPIRES
>    &state=YOUR_STATE_VALUE
>
> Of course, if the request fails authentication, they redirect as follows:
>
> YOUR_REDIRECT_URI?
>     error_reason=user_denied
>    &error=access_denied
>    &error_description=The+user+denied+your+request.
>    &state=YOUR_STATE_VALUE
>
> So your redirect page could start out like this:
>
> public class FacebookResponseListener extends WebPage {
>
>         private static final long serialVersionUID = 1L;
>
>         public FacebookResponseListener(PageParameters params) {
>                 // if there is an error, handle it
>                 if (params.get("error_reason") != null) {
>                         // handle the error here!
>                 } else {
>                         String accessToken =
> params.get("access_token").toString();
>                         int expiresIn = params.get("expires_in").toInt();
>
>                         // etc... etc...
>
>                 }
>
>         }
> }
>
> Mike
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

RE: Anyone using Wicket-Stuff Facebook

Posted by Michael Chandler <Mi...@onassignment.com>.
> The browser gets a token back that makes perfect sense and the example is completed.
> How do I "consume" the token?  I'll play around with it a bit and let you know what
> I come up with.  Thanks for the help.

Based on the path I was taking, the redirect URI is the key.  Facebook redirects as such:

YOUR_REDIRECT_URI?
    access_token=USER_ACCESS_TOKEN
   &expires_in=NUMBER_OF_SECONDS_UNTIL_TOKEN_EXPIRES
   &state=YOUR_STATE_VALUE

Of course, if the request fails authentication, they redirect as follows:

YOUR_REDIRECT_URI?
    error_reason=user_denied
   &error=access_denied
   &error_description=The+user+denied+your+request.
   &state=YOUR_STATE_VALUE

So your redirect page could start out like this:

public class FacebookResponseListener extends WebPage {

	private static final long serialVersionUID = 1L;
	
	public FacebookResponseListener(PageParameters params) {
		// if there is an error, handle it
		if (params.get("error_reason") != null) {
			// handle the error here!
		} else {
			String accessToken = params.get("access_token").toString();
			int expiresIn = params.get("expires_in").toInt();
			
			// etc... etc...
			
		}
		
	}
}

Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Anyone using Wicket-Stuff Facebook

Posted by Stephen Walsh <st...@connectwithawalsh.com>.
On Mon, Feb 18, 2013 at 5:27 PM, Michael Chandler <
Michael.Chandler@onassignment.com> wrote:

> Facebook should post the access token to your OAuth Accept Redirect URL
> which you can consume and set to a Token instance.


The browser gets a token back that makes perfect sense and the example is
completed.  How do I "consume" the token?  I'll play around with it a bit
and let you know what I come up with.  Thanks for the help.

_______________________________________
Stephen Walsh | http://connectwithawalsh.com

RE: Anyone using Wicket-Stuff Facebook

Posted by Michael Chandler <Mi...@onassignment.com>.
Hi Stephen

>> you should be able to define a return URL when a user successfully 
>> authenticates that you host

> This is the part that I don't understand.  I guess I create a separate OAuth
> class page that launches when the user authenticates, but how I get the code 
> out of the URL?  I need the code to send back to Facebook so I can get an
> access token.

Right.  In the Scribe example, you are working in the console so a "code" is provided that you punch in to your console which gets consumed by a Verifier.  I don't believe it will work that way in an actual seemless integration.  Instead, you should be able to define a "OAuth Accept Redirect URL" which effectively informs Facebook to post back the credentials to that URL you specify.  Here is where I am assuming since I haven't completed the integration... instead of getting an access token by sending the Verifer instance back to Facebook with the request token, Facebook should post the access token to your OAuth Accept Redirect URL which you can consume and set to a Token instance.  Again, I'm assuming at this point.  It's possible that your OAuth Accept Redirect URL consumes that code and then you're expected to request the access token at that point...

Go to your Facebook App in the Developers console and define a URL for the OAuth Redirect URI.  Put something together and try it.  I believe it will send back an access token in the query string if memory serves.

When I have something working, I'll gladly share it with you to provide clarification.

Mike

-----Original Message-----
From: Stephen Walsh [mailto:stephen@connectwithawalsh.com] 
Sent: Monday, February 18, 2013 12:26 PM
To: users@wicket.apache.org
Subject: Re: Anyone using Wicket-Stuff Facebook

On Mon, Feb 18, 2013 at 1:59 PM, Michael Chandler < Michael.Chandler@onassignment.com> wrote:

> you should be able to define a return URL when a user successfully 
> authenticates that you host


This is the part that I don't understand.  I guess I create a separate OAuth class page that launches when the user authenticates, but how I get the code out of the URL?  I need the code to send back to Facebook so I can get an access token.

The other part that is confusing to me is that I had an identical JUnit test set up to do what you did above, but I'm getting an error:

     java.lang.UnsupportedOperationException: Unsupported operation, please use 'getAuthorizationUrl' and redirect your users there

on this line Token requestToken = service.getRequestToken();

I'd be really interested to see how you implement with LinkedIn as I assume it will be very similar for my implementation.

Thanks, Mike.

_______________________________________
Stephen Walsh | http://connectwithawalsh.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Anyone using Wicket-Stuff Facebook

Posted by Stephen Walsh <st...@connectwithawalsh.com>.
On Mon, Feb 18, 2013 at 1:59 PM, Michael Chandler <
Michael.Chandler@onassignment.com> wrote:

> you should be able to define a return URL when a user successfully
> authenticates that you host


This is the part that I don't understand.  I guess I create a separate
OAuth class page that launches when the user authenticates, but how I get
the code out of the URL?  I need the code to send back to Facebook so I can
get an access token.

The other part that is confusing to me is that I had an identical JUnit
test set up to do what you did above, but I'm getting an error:

     java.lang.UnsupportedOperationException: Unsupported operation, please
use 'getAuthorizationUrl' and redirect your users there

on this line Token requestToken = service.getRequestToken();

I'd be really interested to see how you implement with LinkedIn as I assume
it will be very similar for my implementation.

Thanks, Mike.

_______________________________________
Stephen Walsh | http://connectwithawalsh.com

RE: Anyone using Wicket-Stuff Facebook

Posted by Michael Chandler <Mi...@onassignment.com>.
I also plan to use Scribe and spent a little time with it this weekend.  My particular example uses LinkedIn, but the implementations would probably be near identical.  In this particular example, I'm trying to retrieve the Authorize URL that a user would use to authenticate with LinkedIn.  The following method returns the API hyperlink that I would use for a "Login with LinkedIn" button:

private String getLinkedInAuth() {
	OAuthService service = new ServiceBuilder()
        .provider(LinkedInApi.class)
        .apiKey("your_api_key").apiSecret("your_api_secret_hash").build();
		
	Token requestToken = service.getRequestToken();
	String link = service.getAuthorizationUrl(requestToken);
		
	return link;
}

I haven't done much from there, but I believe you should be able to define a return URL when a user successfully authenticates that you host (check your Facebook app config on Facebook.com).  That URL should be prepared to accept a response that will include the user's access token which you will use to sign any of your graph api requests.

I haven't completed my integration so hopefully I am not over simplifying.

Mike

-----Original Message-----
From: Stephen Walsh [mailto:stephen@connectwithawalsh.com] 
Sent: Monday, February 18, 2013 10:47 AM
To: users@wicket.apache.org
Subject: Re: Anyone using Wicket-Stuff Facebook

I'm also using Scribe, Martin.  I'm following up with the developer to figure out how to use it.  He has a copy and paste in his example which obviously won't work for an actual user.

https://github.com/fernandezpablo85/scribe-java/blob/master/src/test/java/org/scribe/examples/FacebookExample.java

_______________________________________
Stephen Walsh | http://connectwithawalsh.com


On Mon, Feb 18, 2013 at 1:53 AM, Martin Grigorov <mg...@apache.org>wrote:

> Hi,
>
> If you need to implement OAuth authentication then I can recommend you 
> https://github.com/fernandezpablo85/scribe-java
> It is easy to implement both OAuth v.1 and v.2 with it
>
>
> On Mon, Feb 18, 2013 at 5:28 AM, Stephen Walsh < 
> stephen@connectwithawalsh.com> wrote:
>
> > https://github.com/wicketstuff/core/wiki/Facebook
> >
> > Anyone using this that can point me in the right direction on how to 
> > use the behaviors?
> >
> > I followed the example on getting a login button and it seems like 
> > that works well, but I have no idea to tell if the user has 
> > validated and how
> to
> > capture that validation.  Clearly it's in the behaviors section of 
> > the
> jar,
> > but I'm not quite sure how to use it.
> >
> > Thanks.
> > _______________________________________
> > Stephen Walsh | http://connectwithawalsh.com
> >
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com <http://jweekend.com/>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Anyone using Wicket-Stuff Facebook

Posted by Stephen Walsh <st...@connectwithawalsh.com>.
I'm also using Scribe, Martin.  I'm following up with the developer to
figure out how to use it.  He has a copy and paste in his example which
obviously won't work for an actual user.

https://github.com/fernandezpablo85/scribe-java/blob/master/src/test/java/org/scribe/examples/FacebookExample.java

_______________________________________
Stephen Walsh | http://connectwithawalsh.com


On Mon, Feb 18, 2013 at 1:53 AM, Martin Grigorov <mg...@apache.org>wrote:

> Hi,
>
> If you need to implement OAuth authentication then I can recommend you
> https://github.com/fernandezpablo85/scribe-java
> It is easy to implement both OAuth v.1 and v.2 with it
>
>
> On Mon, Feb 18, 2013 at 5:28 AM, Stephen Walsh <
> stephen@connectwithawalsh.com> wrote:
>
> > https://github.com/wicketstuff/core/wiki/Facebook
> >
> > Anyone using this that can point me in the right direction on how to use
> > the behaviors?
> >
> > I followed the example on getting a login button and it seems like that
> > works well, but I have no idea to tell if the user has validated and how
> to
> > capture that validation.  Clearly it's in the behaviors section of the
> jar,
> > but I'm not quite sure how to use it.
> >
> > Thanks.
> > _______________________________________
> > Stephen Walsh | http://connectwithawalsh.com
> >
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com <http://jweekend.com/>
>

Re: Anyone using Wicket-Stuff Facebook

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

If you need to implement OAuth authentication then I can recommend you
https://github.com/fernandezpablo85/scribe-java
It is easy to implement both OAuth v.1 and v.2 with it


On Mon, Feb 18, 2013 at 5:28 AM, Stephen Walsh <
stephen@connectwithawalsh.com> wrote:

> https://github.com/wicketstuff/core/wiki/Facebook
>
> Anyone using this that can point me in the right direction on how to use
> the behaviors?
>
> I followed the example on getting a login button and it seems like that
> works well, but I have no idea to tell if the user has validated and how to
> capture that validation.  Clearly it's in the behaviors section of the jar,
> but I'm not quite sure how to use it.
>
> Thanks.
> _______________________________________
> Stephen Walsh | http://connectwithawalsh.com
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: Anyone using Wicket-Stuff Facebook

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Hi Stephen.

I don't know the answer to your question...

I want just to point out that a few months ago I tried to use the API and I
was hit by this bug on facebook API

https://developers.facebook.com/bugs/391962640871463

Hope it has been fixed in the mean time?

On Mon, Feb 18, 2013 at 4:28 AM, Stephen Walsh <
stephen@connectwithawalsh.com> wrote:

> https://github.com/wicketstuff/core/wiki/Facebook
>
> Anyone using this that can point me in the right direction on how to use
> the behaviors?
>
> I followed the example on getting a login button and it seems like that
> works well, but I have no idea to tell if the user has validated and how to
> capture that validation.  Clearly it's in the behaviors section of the jar,
> but I'm not quite sure how to use it.
>
> Thanks.
> _______________________________________
> Stephen Walsh | http://connectwithawalsh.com
>



-- 
Regards - Ernesto Reinaldo Barreiro
Antilia Soft
http://antiliasoft.com/ <http://antiliasoft.com/antilia>