You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oltu.apache.org by as...@apache.org on 2013/04/19 10:06:05 UTC
svn commit: r1469732 - in /oltu/trunk:
demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/
demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/
oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/reque...
Author: asanso
Date: Fri Apr 19 08:06:05 2013
New Revision: 1469732
URL: http://svn.apache.org/r1469732
Log:
OLTU-96 - Improve client API in order to support known Provider
* applied patch from Sam Gorial. Thanks!!
Added:
oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/OAuthProviderType.java
Modified:
oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/Utils.java
oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/MainController.java
oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/OAuthClientRequest.java
oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/OAuthClientTest.java
Modified: oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/Utils.java
URL: http://svn.apache.org/viewvc/oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/Utils.java?rev=1469732&r1=1469731&r2=1469732&view=diff
==============================================================================
--- oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/Utils.java (original)
+++ oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/Utils.java Fri Apr 19 08:06:05 2013
@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletReq
import org.apache.oltu.oauth2.client.demo.exception.ApplicationException;
import org.apache.oltu.oauth2.client.demo.model.OAuthParams;
import org.apache.oltu.oauth2.client.demo.model.OAuthRegParams;
+import org.apache.oltu.oauth2.common.OAuthProviderType;
/**
*
@@ -49,21 +50,21 @@ public final class Utils {
public static final String GENERIC = "generic";
- public static final String FACEBOOK = "facebook";
- public static final String FACEBOOK_AUTHZ = "https://graph.facebook.com/oauth/authorize";
- public static final String FACEBOOK_TOKEN = "https://graph.facebook.com/oauth/access_token";
+ public static final String FACEBOOK = OAuthProviderType.FACEBOOK.getProviderName();
+ public static final String FACEBOOK_AUTHZ = OAuthProviderType.FACEBOOK.getAuthzEndpoint();
+ public static final String FACEBOOK_TOKEN = OAuthProviderType.FACEBOOK.getTokenEndpoint();
- public static final String GOOGLE = "google";
- public static final String GOOGLE_AUTHZ = "https://accounts.google.com/o/oauth2/auth";
- public static final String GOOGLE_TOKEN = "https://accounts.google.com/o/oauth2/token";
-
- public static final String LINKEDIN = "linkedin";
- public static final String LINKEDIN_AUTHZ = "https://www.linkedin.com/uas/oauth2/authorization";
- public static final String LINKEDIN_TOKEN = "https://www.linkedin.com/uas/oauth2/accessToken";
-
- public static final String GITHUB = "github";
- public static final String GITHUB_AUTHZ = "https://github.com/login/oauth/authorize";
- public static final String GITHUB_TOKEN = "https://github.com/login/oauth/access_token";
+ public static final String GOOGLE = OAuthProviderType.GOOGLE.getProviderName();
+ public static final String GOOGLE_AUTHZ = OAuthProviderType.GOOGLE.getAuthzEndpoint();
+ public static final String GOOGLE_TOKEN = OAuthProviderType.GOOGLE.getTokenEndpoint();
+
+ public static final String LINKEDIN = OAuthProviderType.LINKEDIN.getProviderName();
+ public static final String LINKEDIN_AUTHZ = OAuthProviderType.LINKEDIN.getAuthzEndpoint();
+ public static final String LINKEDIN_TOKEN = OAuthProviderType.LINKEDIN.getTokenEndpoint();
+
+ public static final String GITHUB = OAuthProviderType.GITHUB.getProviderName();
+ public static final String GITHUB_AUTHZ = OAuthProviderType.GITHUB.getAuthzEndpoint();
+ public static final String GITHUB_TOKEN = OAuthProviderType.GITHUB.getTokenEndpoint();
public static final String SMART_GALLERY = "smart_gallery";
public static final String SMART_GALLERY_AUTHZ = "http://localhost:8090/oauth/authorize";
Modified: oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/MainController.java
URL: http://svn.apache.org/viewvc/oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/MainController.java?rev=1469732&r1=1469731&r2=1469732&view=diff
==============================================================================
--- oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/MainController.java (original)
+++ oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/MainController.java Fri Apr 19 08:06:05 2013
@@ -65,20 +65,20 @@ public class MainController {
boolean selected = false;
if (Utils.GENERIC.equals(app)) {
selected = true;
- }else if (Utils.GITHUB.equals(app)) {
+ }else if (Utils.GITHUB.equalsIgnoreCase(app)) {
selected = true;
oauthParams.setAuthzEndpoint(Utils.GITHUB_AUTHZ);
oauthParams.setTokenEndpoint(Utils.GITHUB_TOKEN);
- } else if (Utils.FACEBOOK.equals(app)) {
+ } else if (Utils.FACEBOOK.equalsIgnoreCase(app)) {
selected = true;
oauthParams.setAuthzEndpoint(Utils.FACEBOOK_AUTHZ);
oauthParams.setTokenEndpoint(Utils.FACEBOOK_TOKEN);
- }else if (Utils.GOOGLE.equals(app)) {
+ }else if (Utils.GOOGLE.equalsIgnoreCase(app)) {
selected = true;
oauthParams.setAuthzEndpoint(Utils.GOOGLE_AUTHZ);
oauthParams.setTokenEndpoint(Utils.GOOGLE_TOKEN);
- } else if (Utils.LINKEDIN.equals(app)) {
+ } else if (Utils.LINKEDIN.equalsIgnoreCase(app)) {
selected = true;
oauthParams.setAuthzEndpoint(Utils.LINKEDIN_AUTHZ);
oauthParams.setTokenEndpoint(Utils.LINKEDIN_TOKEN);
Modified: oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/OAuthClientRequest.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/OAuthClientRequest.java?rev=1469732&r1=1469731&r2=1469732&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/OAuthClientRequest.java (original)
+++ oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/OAuthClientRequest.java Fri Apr 19 08:06:05 2013
@@ -25,6 +25,7 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.oltu.oauth2.common.OAuth;
+import org.apache.oltu.oauth2.common.OAuthProviderType;
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
import org.apache.oltu.oauth2.common.message.OAuthMessage;
import org.apache.oltu.oauth2.common.message.types.GrantType;
@@ -55,10 +56,18 @@ public class OAuthClientRequest implemen
return new AuthenticationRequestBuilder(url);
}
+ public static AuthenticationRequestBuilder authorizationProvider(OAuthProviderType provider) {
+ return authorizationLocation(provider.getAuthzEndpoint());
+ }
+
public static TokenRequestBuilder tokenLocation(String url) {
return new TokenRequestBuilder(url);
}
+ public static TokenRequestBuilder tokenProvider(OAuthProviderType provider) {
+ return tokenLocation(provider.getTokenEndpoint());
+ }
+
public String getBody() {
return body;
}
Modified: oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/OAuthClientTest.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/OAuthClientTest.java?rev=1469732&r1=1469731&r2=1469732&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/OAuthClientTest.java (original)
+++ oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/OAuthClientTest.java Fri Apr 19 08:06:05 2013
@@ -31,6 +31,7 @@ import org.apache.oltu.oauth2.client.OAu
import org.apache.oltu.oauth2.client.URLConnectionClient;
import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
import org.apache.oltu.oauth2.client.response.GitHubTokenResponse;
+import org.apache.oltu.oauth2.common.OAuthProviderType;
import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
import org.apache.oltu.oauth2.common.message.types.GrantType;
@@ -49,7 +50,7 @@ public class OAuthClientTest {
try {
OAuthClientRequest request = OAuthClientRequest
- .authorizationLocation("https://graph.facebook.com/oauth/authorize")
+ .authorizationProvider(OAuthProviderType.FACEBOOK)
.setClientId("131804060198305")
.setRedirectURI("http://localhost:8080/")
.buildQueryMessage();
@@ -62,7 +63,7 @@ public class OAuthClientTest {
String code = br.readLine();
request = OAuthClientRequest
- .tokenLocation("https://graph.facebook.com/oauth/access_token")
+ .tokenProvider(OAuthProviderType.FACEBOOK)
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setClientId("131804060198305")
.setClientSecret("3acb294b071c9aec86d60ae3daf32a93")
Added: oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/OAuthProviderType.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/OAuthProviderType.java?rev=1469732&view=auto
==============================================================================
--- oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/OAuthProviderType.java (added)
+++ oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/OAuthProviderType.java Fri Apr 19 08:06:05 2013
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oltu.oauth2.common;
+
+/**
+ * An enumeration of pre-identified and well known OAuth 2 providers, along
+ * with their authorization and token endpoints.
+ */
+public enum OAuthProviderType {
+
+ FACEBOOK(
+ "facebook",
+ "https://graph.facebook.com/oauth/authorize",
+ "https://graph.facebook.com/oauth/access_token"),
+
+ FOURSQUARE(
+ "foursquare",
+ "https://foursquare.com/oauth2/authenticate",
+ "https://foursquare.com/oauth2/access_token"),
+
+ GITHUB(
+ "GitHub",
+ "https://github.com/login/oauth/authorize",
+ "https://github.com/login/oauth/access_token"),
+
+ GOOGLE(
+ "Google",
+ "https://accounts.google.com/o/oauth2/auth",
+ "https://accounts.google.com/o/oauth2/token"),
+
+ INSTAGRAM(
+ "Instagram",
+ "https://api.instagram.com/oauth/authorize",
+ "https://api.instagram.com/oauth/access_token"),
+
+ LINKEDIN(
+ "LinkedIn",
+ "https://www.linkedin.com/uas/oauth2/authorization",
+ "https://www.linkedin.com/uas/oauth2/accessToken"),
+
+ MICROSOFT(
+ "Microsoft",
+ "https://login.live.com/oauth20_authorize.srf",
+ "POST https://login.live.com/oauth20_token.srf"),
+
+ PAYPAL(
+ "PayPal",
+ "https://identity.x.com/xidentity/resources/authorize",
+ "https://identity.x.com/xidentity/oauthtokenservice"),
+
+ REDDIT(
+ "reddit",
+ "https://ssl.reddit.com/api/v1/authorize",
+ "https://ssl.reddit.com/api/v1/access_token"),
+
+ SALESFORCE(
+ "salesforce",
+ "https://login.salesforce.com/services/oauth2/authorize",
+ "https://login.salesforce.com/services/oauth2/token"),
+
+ YAMMER(
+ "Yammer",
+ "https://www.yammer.com/dialog/oauth",
+ "https://www.yammer.com/oauth2/access_token.json");
+
+ private String providerName;
+
+ private String authzEndpoint;
+
+ private String tokenEndpoint;
+
+ /**
+ * Get the provider name
+ *
+ * @return Returns the provider name
+ */
+ public String getProviderName() {
+ return providerName;
+ }
+
+ /**
+ * Get the authorization endpoint
+ *
+ * @return Returns the authorization endpoint
+ */
+ public String getAuthzEndpoint() {
+ return authzEndpoint;
+ }
+
+ /**
+ * Get the access token endpoint
+ *
+ * @return Returns the access token endpoint
+ */
+ public String getTokenEndpoint() {
+ return tokenEndpoint;
+ }
+
+ /**
+ * Full private constructor
+ *
+ * @param providerName The provider name
+ * @param authzEndpoint The authorization endpoint
+ * @param tokenEndpoint The token endpoint
+ */
+ private OAuthProviderType(
+ final String providerName,
+ final String authzEndpoint,
+ final String tokenEndpoint) {
+
+ this.providerName = providerName;
+ this.authzEndpoint = authzEndpoint;
+ this.tokenEndpoint = tokenEndpoint;
+ }
+
+}
\ No newline at end of file