Directory

← Back

OAuth2 Popup Add-on

Embed OAuth authorization flows into your Vaadin application.

Author

Contributors

Rating

OAuth Popup Add-on for Vaadin 7.1+

Add OAuth support to your Vaadin applications by embedding a button that does the work for you. This addon uses the terrific Scribe library under the covers, which supports all major OAuth services out-of-the-box.

The API for this add-on aims to make configuration as simple as possible without hiding any functionality to allow fine-tuning for unsupported OAuth services. The button provided by this add-on opens a popup window which handles the OAuth authentication.

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 has been closed.

NOTE

This project was forked from @ahn's initial implementation and is available as a separate add-on in the Vaadin Directory (http://vaadin.com/addon/oauth-popup-add-on). Major differences between the two projects include:

  • Use of the latest Scribe library to support all major OAuth 1.0a and 2.0 services out-of-the-box.
  • Add extensive Javadoc documentation.
  • Add flexibility allowing fine-grained control of OAuth parameters.
  • Create an OAuth Popup button for any OAuth API supported by Scribe without subclassing.

Sample code

import com.github.scribejava.core.model.OAuth1AccessToken;
import com.github.scribejava.core.model.OAuth2AccessToken;
...

OAuthPopupButton twitter = new OAuthPopupButton(
				com.github.scribejava.apis.TwitterApi.instance(), "my-key", "my-secret");
twitter.addOAuthListener(new OAuthListener() {

	@Override
	public void authSuccessful(Token token, boolean isOAuth20) {
		// Do something useful with the OAuth token, like persist it
		if (token instanceof OAuth2AccessToken) {
			((OAuth2AccessToken) token).getAccessToken();
			((OAuth2AccessToken) token).getRefreshToken();
			((OAuth2AccessToken) token).getExpiresIn();
		} else {
			((OAuth1AccessToken) token).getToken();
			((OAuth1AccessToken) token).getTokenSecret();
		}
	}

	@Override
	public void authDenied(String reason) {
		Notification.show("Failed to authenticate!", Notification.Type.ERROR_MESSAGE);
	}
});
layout.addComponent(twitter);
OAuthPopupConfig config = OAuthPopupConfig.getStandardOAuth20Config("my-key", "my-secret");
config.setGrantType("authorization_code");
config.setScope("https://www.googleapis.com/auth/plus.login");
config.setCallbackUrl("urn:ietf:wg:oauth:2.0:oob");
OAuthPopupButton google = new OAuthPopupButton(GoogleApi20.instance(), config);
...

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

  • Upgrade to Vaadin 8
  • Add support for url based popup for use in conjuction with UIs annotated with @springui
Released
2017-05-25
Maturity
STABLE
License
Apache License 2.0

Compatibility

Framework
Vaadin 8.0+
Vaadin 7.1+ in 0.1.0
Browser
N/A
Online