OAuth Popup add-on contains buttons that open an OAuth popup dialog where the user can authorize the Vaadin application to do things on the users' behalf on various services such as Facebook, Twitter, etc.
There's a fork of this addon by Bryson Dunn, with updated Scribe and other improvements:
https://github.com/bdunn44/vaadin-oauthpopup
^ Use that instead.
Available as an add-on in Vaadin Directory.
This add-on is similar to the OAuth Buttons add-on, except that this one:
Since the OAuth dialog is opened in a separate window, the application should enable server push. Otherwise the actual application UI will not be updated when the OAuth window is done, because without push the client of the application UI doesn't know that somethings's changed.
This add-on uses Scribe library for OAuth.
The OAuthPopupButton
can be used by simply giving a Scribe API and API key+secret to its constructor, or by extending it.
A couble of subclasses are already at package org.vaadin.addon.oauthpopup.buttons
.
NOTE: I'm not sure if the add-on currently works with all the Scribe APIs, probably not...
To use OAuth, you must first create an application for the service in question. Give the applications key and secret to the constructor of OAuthPopupButton (or of its subclass such as TwitterButton). For example, Twitter applications can be created here.
OAuthPopupButton ob = new TwitterButton(TW_KEY, TW_SECRET);
ob.addOAuthListener(new OAuthListener() {
@Override
public void authSuccessful(String accessToken, String accessTokenSecret) {
Notification.show("Authorized");
// TODO: do something with the access token
}
@Override
public void authDenied(String reason) {
Notification.show("Authorization denied");
}
});
layout.addComponent(ob);
For some services it's possible to set the scope of OAuth authorization. The format of scope is service-depended, often a comma-separate list of names.
ob.setScope("email");
By default, the OAuth window is opened in a new tab in most browsers. You can control that by setting the features that are redirected to the BrowserWindowOpener of the button.
ob.setPopupWindowFeatures("resizable,width=400,height=300");
If you like to use some component other than button to open the popup window,
you can extend any component with a OAuthPopupOpener
.
This component has no public roadmap or any guarantees of upcoming releases.
Feedback is welcome. Comment on Directory, add an issue on GitHub, or mail me.
Contributions are appreciated as well. Process for contributing is the following:
To get, compile and run the project:
git clone https://github.com/ahn/vaadin-oauthpopup.git
cd vaadin-oauthpopup
mvn clean install
cd oauthpopup-demo
mvn jetty:run
To see the demo, navigate to http://localhost:8080/
To create an addon package that can be uploaded to Vaadin Directory
cd oauthpopup
mvn clean package assembly:single
The basic flow goes as follows:
OAuthPopupButton
extends itself with OAuthPopupOpener
OAuthPopupOpener
is attached, it
OAuthData
instance as a session attribute, for other windows to readOAuthPopupUI
in a new windowOAuthPopupUI
OAuthData
from the session attributeOAuthCallbackRequestHandler
to the current sessionOAuthCallbackRequestHandler
is no longer needed, and is removed from sessionOAuthListener
s of are called, either authSuccessful
or authFailed
OAuthPopupOpener
is detached, it clears the session attribute where the OAuthData
wasAdd-on is distributed under Apache License 2.0. For license terms, see LICENSE.txt.