Author: [email protected]
Date: Wed Jun 29 08:41:55 2011
New Revision: 1201
Log:
Refactored OAuth twitter example
Added:
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/TwitterService.java
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TwitterClient.java
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TwitterGadgetImpl.java
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TwitterServiceImpl.java
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TwitterServiceProvider.java
Removed:
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/AmdatuTwitterClient.java
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/TweetService.java
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/TwitterServiceProvider.java
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/AmdatuTwitterClientImpl.java
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TweetGadgetImpl.java
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TweetServiceImpl.java
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TwitterServiceProviderImpl.java
Modified:
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/osgi/Activator.java
Added:
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/TwitterService.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/TwitterService.java
Wed Jun 29 08:41:55 2011
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.auth.example.oauth.twitter;
+
+/**
+ * This interface represents a Twitter service, which facilitates sending
tweets on a users behalf.
+ * It uses 3-legged OAuth to let the user log in into Twitter and send the
tweets on that
+ * users behalf.
+ * As this service is a REST service, it does not provide any methods.
+ */
+public interface TwitterService {
+}
Modified:
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/osgi/Activator.java
==============================================================================
---
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/osgi/Activator.java
(original)
+++
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/osgi/Activator.java
Wed Jun 29 08:41:55 2011
@@ -18,14 +18,10 @@
import java.util.Dictionary;
import java.util.Hashtable;
-import org.amdatu.auth.example.oauth.twitter.AmdatuTwitterClient;
-import org.amdatu.auth.example.oauth.twitter.TweetService;
-import org.amdatu.auth.example.oauth.twitter.TwitterServiceProvider;
-import org.amdatu.auth.example.oauth.twitter.service.AmdatuTwitterClientImpl;
-import org.amdatu.auth.example.oauth.twitter.service.TweetGadgetImpl;
-import org.amdatu.auth.example.oauth.twitter.service.TweetServiceImpl;
-import
org.amdatu.auth.example.oauth.twitter.service.TwitterServiceProviderImpl;
-import org.amdatu.authentication.oauth.api.OAuthServiceConsumerRegistry;
+import org.amdatu.auth.example.oauth.twitter.TwitterService;
+import org.amdatu.auth.example.oauth.twitter.service.TwitterGadgetImpl;
+import org.amdatu.auth.example.oauth.twitter.service.TwitterServiceImpl;
+import org.amdatu.auth.example.oauth.twitter.service.TwitterServiceProvider;
import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator;
import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
import org.amdatu.web.dispatcher.DispatcherService;
@@ -77,30 +73,16 @@
properties.put(ResourceSupport.RESOURCE_ALIAS_KEY, RES_ALIAS);
manager.add(createComponent().setInterface(ResourceProvider.class.getName(),
properties)
- .setImplementation(TweetGadgetImpl.class)
+ .setImplementation(TwitterGadgetImpl.class)
.add(createServiceDependency().setService(LogService.class).setRequired(true))
.add(createServiceDependency().setService(GadgetManagement.class).setRequired(true)));
// Create and register the tweet service.
manager.add(createComponent()
- .setInterface(TweetService.class.getName(), null)
- .setImplementation(TweetServiceImpl.class)
+ .setInterface(TwitterService.class.getName(), null)
+ .setImplementation(TwitterServiceImpl.class)
.add(createServiceDependency().setService(LogService.class).setRequired(true))
-
.add(createServiceDependency().setService(AmdatuTwitterClient.class).setRequired(true))
-
.add(createServiceDependency().setService(TwitterServiceProvider.class).setRequired(true)));
-
- // Create and register the Amdatu Twitter Client (the OAuth service
consumer).
- manager.add(createComponent()
- .setInterface(AmdatuTwitterClient.class.getName(), null)
- .setImplementation(AmdatuTwitterClientImpl.class)
-
.add(createServiceDependency().setService(LogService.class).setRequired(true))
-
.add(createServiceDependency().setService(OAuthServiceConsumerRegistry.class).setRequired(true)));
-
- // Create and register the Twitter Service Provider (the OAuth service
provider).
- manager.add(createComponent()
- .setInterface(TwitterServiceProvider.class.getName(), null)
- .setImplementation(TwitterServiceProviderImpl.class)
-
.add(createServiceDependency().setService(LogService.class).setRequired(true)));
+
.add(createServiceDependency().setService(TwitterServiceProvider.class).setRequired(true)));
}
@Override
Added:
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TwitterClient.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TwitterClient.java
Wed Jun 29 08:41:55 2011
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.auth.example.oauth.twitter.service;
+
+import java.util.Map;
+
+import org.amdatu.authentication.oauth.api.OAuthServiceConsumer;
+
+/**
+ * This class implements the example Twitter client and represents an OAuth
Service consumer
+ * accessing the Twitter API using 3-legged OAuth to send tweets on a users
behalf.
+ * Note that we do not need to register ourselves as an OAuth service consumer
in Amdatu's
+ * consumer registry as this registry is only used by the Amdatu OAuth server.
Since we
+ * are accessing the Twitter service provider, we have nothing to do with the
Amdatu OAuth
+ * server (The Amdatu OAuth server is used when we would try to access Amdatu
resources).
+ */
+public class TwitterClient implements OAuthServiceConsumer {
+ // Logical name of our client
+ private static final String CONSUMER_NAME = "Amdatu Twitter Client";
+
+ // The consumer key is provided by Twitter with the registration of this
application.
+ // Note that the API key and Consumer key are one and the same
+ private static final String CONSUMER_KEY = "ZdODivCUkfHAHHargOB7g";
+
+ // The consumer secret is provided by Twitter with the registration of
this application
+ private static final String CONSUMER_SECRET =
"s1pLl4jcRU9OF9Y8BcZuOa7gzpAUAnNmxWNenKh81g";
+
+ // Callback URL for OAuth negotiation. This URL will invoked by Twitter
when the user
+ // authorized the request token and so we are ready to exchange the
request token for
+ // an access token.
+ // FIXME: this callback URL should not contain hard coded hostname and
portnr, but right now
+ // there is no other way. See
http://jira.amdatu.org/jira/browse/AMDATUAUTH-60
+ private static final String OAUTH_CALLBACK_URL =
"http://localhost:3337/rest/example/twitter/oauthcallback";
+
+ public String getName() {
+ return CONSUMER_NAME;
+ }
+
+ public String getConsumerKey() {
+ return CONSUMER_KEY;
+ }
+
+ public String getConsumerSecret() {
+ return CONSUMER_SECRET;
+ }
+
+ public String getCallbackUrl() {
+ return OAUTH_CALLBACK_URL;
+ }
+
+ public Map<String, String> getProperties() {
+ return null;
+ }
+}
Added:
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TwitterGadgetImpl.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TwitterGadgetImpl.java
Wed Jun 29 08:41:55 2011
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.auth.example.oauth.twitter.service;
+
+import java.net.URL;
+
+import org.amdatu.auth.example.oauth.twitter.osgi.Activator;
+import org.amdatu.opensocial.gadgetmanagement.GadgetCategory;
+import org.amdatu.opensocial.gadgetmanagement.GadgetDefinition;
+import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
+import org.amdatu.web.httpcontext.ResourceProvider;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+/**
+ * This class provided the Tweet gadget which can be used to send tweets.
+ */
+public class TwitterGadgetImpl implements ResourceProvider {
+ // JSP for the tweet gadget
+ private static final String GADGET_JSP = "/jsp/TweetGadget.jsp";
+
+ //Default category for Amdatu example gadgets.
+ private static final GadgetCategory AMDATU_EXAMPLES = new
GadgetCategory("amdatu_examples", "Amdatu Examples");
+
+ // Service dependencies, injected by the Felix dependency manager
+ private volatile LogService m_logService;
+ private volatile BundleContext m_bundleContext;
+ private volatile GadgetManagement m_gadgetManagement;
+
+ /**
+ * The init() method is invoked by the Felix dependency manager.
+ */
+ public void start() {
+
+ // Register the gadget with the Gadget management service. Note that
we can do this as
+ // many times as we want, since the gadget URL is the unique identifier
+ String gadgetSpecUrl = Activator.ALIAS + GADGET_JSP;
+ GadgetDefinition gadgetDef = new GadgetDefinition(gadgetSpecUrl,
AMDATU_EXAMPLES, true);
+ gadgetDef.setRank(0);
+ m_gadgetManagement.addGadget(gadgetDef);
+ m_logService.log(LogService.LOG_INFO, "Tweet gadget registered on URL
'" + gadgetSpecUrl + "'");
+
+ m_logService.log(LogService.LOG_INFO, getClass().getName() + " service
started");
+ }
+
+ public URL getResource(final String name) {
+ final String pathPrefix = Activator.ALIAS + "/";
+ if (name != null && name.startsWith(pathPrefix)) {
+ return
m_bundleContext.getBundle().getResource(name.substring(pathPrefix.length()));
+ }
+ return null;
+ }
+}
Added:
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TwitterServiceImpl.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TwitterServiceImpl.java
Wed Jun 29 08:41:55 2011
@@ -0,0 +1,252 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.auth.example.oauth.twitter.service;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import net.oauth.OAuth;
+import net.oauth.OAuthAccessor;
+import net.oauth.OAuthException;
+import net.oauth.OAuthMessage;
+
+import org.amdatu.auth.example.oauth.twitter.TwitterService;
+import org.amdatu.authentication.oauth.api.OAuthAccess;
+import org.amdatu.authentication.oauth.client.OAuthServiceConsumerClient;
+import org.apache.http.HttpStatus;
+import org.json.JSONException;
+import org.osgi.service.log.LogService;
+
+/**
+ * This class implements the actual Tweet REST service.
+ * Steps involved in a regular 3-legged OAuth dance:
+ *
+ * 1. Retrieve a request token from the service provider
+ * 2. Store the token secret associated with the retrieved request token
+ * 3. Redirect the user to the authorization URL, defined by the service
provider
+ *
+ * @author ivol
+ */
+@Path("example/twitter")
+public class TwitterServiceImpl implements TwitterService {
+ // The (hard-coded) message to tweet
+ private final static String TWEET_MSG =
+ "Check out this new cool open source cloud platform named #Amdatu on
http://amdatu.org";
+
+ // The Twitter client (the OAuth service consumer) and service provider
+ private final static TwitterClient m_twitterClient = new TwitterClient();
+ private final static TwitterServiceProvider m_twitterServer = new
TwitterServiceProvider();
+
+ // The OAuth service consumer client, which provides a useful API for
OAuth consumers to
+ // access OAuth protected resources.
+ private final static OAuthServiceConsumerClient m_oauthClient = new
OAuthServiceConsumerClient(m_twitterServer,
+ m_twitterClient);
+
+ // Service dependencies, injected by the dependency manager
+ private volatile LogService m_logService;
+
+ // Map for storing token secrets with the tokens.
+ // NB: In this example this is a simple in-memory map, which will not work
in a distributed setup.
+ // In production, a distributed persistent storage (like Cassandra) should
be used instead.
+ private Map<String, String> m_tokens = new HashMap<String, String>();
+
+ public void start() {
+ m_logService.log(LogService.LOG_INFO, "Tweet service started");
+ }
+
+ /**
+ * This method can be used to check the availability of the Twitter
Service.
+ *
+ * @return The text "Twitter service online"
+ */
+ @GET
+ @Path("status")
+ @Produces({MediaType.TEXT_PLAIN})
+ public String status() {
+ return "Tweet service online";
+ }
+
+ /**
+ * This method will Twitter a message on the users behalf. So we use the
OAuth protected Twitter API to do so.
+ */
+ @POST
+ @Path("tweet")
+ public Response tweet() {
+ try {
+ // Step 1. Get a request token and token secret from Twitter
+ OAuthAccess accessor = m_oauthClient.generateRequestToken();
+ m_logService.log(LogService.LOG_INFO, "Request token received: " +
accessor.getRequestToken() + ", token secret="
+ + accessor.getTokenSecret());
+
+ // Step 2: Remember the token secret associated with this request
token
+ m_tokens.put(accessor.getRequestToken(),
accessor.getTokenSecret());
+
+ // Step 3: Let the user redirect to the authorize URL
+ // a. Generate the authorization URL
+ URI authorizeURL =
m_oauthClient.generateAuthorizeTokenURL(accessor);
+
+ // b. Send client-side redirect to the authorize URL
+ return
Response.status(HttpStatus.SC_MOVED_TEMPORARILY).location(authorizeURL).build();
+ }
+ catch (Exception e) {
+ return Response.serverError().entity(e.toString()).build();
+ }
+ }
+
+ @GET
+ @Path("oauthcallback")
+ @Produces({MediaType.TEXT_PLAIN})
+ public Response oAuthCallback(@Context final HttpServletRequest request) {
+ try {
+ String token = request.getParameter("oauth_token");
+
+ // It seems that not passing the verifier works like a charm, so
Twitter does support the
+ // oauth verifier but leaves it up to the application if it
implements it.
+ // but authorioze page displayed consumer so that should be OK. it
would only fail if I
+ // write a malicious twitter app and find a victim that is willing
to accept that this
+ // malicious app has access to his account. Doesn't sound like a
real security issue.
+ String verifier = request.getParameter("oauth_verifier");
+
+ // Create the accessor
+ OAuthAccessor accessor =
m_oauthClient.getAccessor(m_twitterClient, m_twitterServer);
+ accessor.requestToken = token;
+ accessor.tokenSecret = m_tokens.get(token);
+ accessor.setProperty(OAuth.OAUTH_VERIFIER, verifier);
+
+ // Exchange request token for access token
+ OAuthMessage message = m_oauthClient.getAccessToken(accessor);
+ String accessToken = message.getToken();
+
+ String msg = "Exchanged request token for access token:\r\n";
+ msg += " Access token = " + accessToken + "\r\n";
+ msg += " Token secret = " +
message.getParameter("oauth_token_secret") + "\r\n";
+ msg += " User id = " + message.getParameter("user_id") + "\r\n";
+ msg += " User name = " + message.getParameter("screen_name") +
"\r\n";
+ m_logService.log(LogService.LOG_INFO, msg);
+
+ // Update the accessor
+ accessor.requestToken = null;
+ accessor.accessToken = accessToken;
+ accessor.tokenSecret = message.getParameter("oauth_token_secret");
+
+ m_logService.log(LogService.LOG_INFO, "Account Totals: " +
getAccountTotals(accessor));
+ m_logService.log(LogService.LOG_INFO, "Account Verify Credentials:
"
+ + getAccountVerifyCredentials(accessor));
+
+ m_logService.log(LogService.LOG_INFO, "Result: " +
tweetMessage(accessor));
+
+ // Redirect to twitter such that we can see the Tweet
+ return Response.seeOther(new URI("http://twitter.com/")).build();
+
+ // return Response.ok("OK").build();
+ }
+ catch (Exception e) {
+ return Response.serverError().entity(e.toString()).build();
+ }
+ }
+
+ private OAuthAccess createRequestToken() throws IOException,
OAuthException,
+ URISyntaxException {
+ OAuthAccess accessor = m_oauthClient.generateRequestToken();
+ String requestToken = accessor.getRequestToken();
+ String tokenSecret = accessor.getTokenSecret();
+ m_logService.log(LogService.LOG_INFO, "Request token received: " +
requestToken + ", token secret="
+ + tokenSecret);
+ return accessor;
+ }
+
+ private String tweetMessage(OAuthAccessor accessor) throws Exception {
+ String url = "https://api.twitter.com/1/statuses/update.json";
+ url += "?status=" + URLEncoder.encode(TWEET_MSG, "UTF-8");
+ OAuthMessage message = m_oauthClient.accessResource(accessor, url,
"POST");
+ return convertStreamToString(message.getBodyAsStream());
+ }
+
+ private String getAccountTotals(OAuthAccessor accessor) throws
IOException, URISyntaxException, OAuthException {
+ String url = "http://api.twitter.com/1/account/totals.json";
+ OAuthMessage message = m_oauthClient.accessResource(accessor, url,
"GET");
+ return convertStreamToString(message.getBodyAsStream());
+ }
+
+ private String getAccountSettings(OAuthAccessor accessor) throws
IOException, URISyntaxException, OAuthException {
+ String url = "http://api.twitter.com/1/account/settings.json";
+ OAuthMessage message = m_oauthClient.accessResource(accessor, url,
"GET");
+ return convertStreamToString(message.getBodyAsStream());
+ }
+
+ private String getAccountVerifyCredentials(OAuthAccessor accessor) throws
IOException, URISyntaxException,
+ OAuthException {
+ String url =
"http://api.twitter.com/1/account/verify_credentials.json";
+ OAuthMessage message = m_oauthClient.accessResource(accessor, url,
"GET");
+ return convertStreamToString(message.getBodyAsStream());
+ }
+
+ private String updateProfile(OAuthAccessor accessor) throws IOException,
URISyntaxException, OAuthException,
+ JSONException {
+ String url = "http://api.twitter.com/1/account/update_profile.json";
+ url += "?location=Nijmegen";
+ OAuthMessage message = m_oauthClient.accessResource(accessor, url,
"POST");
+ return convertStreamToString(message.getBodyAsStream());
+ }
+
+ public String convertStreamToString(InputStream is) throws IOException {
+ /*
+ * To convert the InputStream to String we use the
+ * Reader.read(char[] buffer) method. We iterate until the
+ * Reader return -1 which means there's no more data to
+ * read. We use the StringWriter class to produce the string.
+ */
+ if (is != null) {
+ Writer writer = new StringWriter();
+
+ char[] buffer = new char[1024];
+ try {
+ Reader reader = new BufferedReader(
+ new InputStreamReader(is, "UTF-8"));
+ int n;
+ while ((n = reader.read(buffer)) != -1) {
+ writer.write(buffer, 0, n);
+ }
+ }
+ finally {
+ is.close();
+ }
+ return writer.toString();
+ }
+ else {
+ return "";
+ }
+ }
+}
\ No newline at end of file
Added:
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TwitterServiceProvider.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/twitter-example/src/main/java/org/amdatu/auth/example/oauth/twitter/service/TwitterServiceProvider.java
Wed Jun 29 08:41:55 2011
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.auth.example.oauth.twitter.service;
+
+import org.amdatu.authentication.oauth.api.OAuthServiceProvider;
+
+/**
+ * This class represents the Twitter service we will invoke from the client.
+ * It holds the three endpoints of an OAuth server; request token URL,
+ * authorize token URL and access token URL.
+ */
+public class TwitterServiceProvider implements OAuthServiceProvider {
+ // The request token URL, provided by Twitter
+ private static final String REQUEST_TOKEN_URL =
"https://api.twitter.com/oauth/request_token";
+
+ // The authorize token URL, provided by Twitter
+ private static final String AUTHORIZE_TOKEN_URL =
"https://api.twitter.com/oauth/authorize";
+
+ // The access token URL, provided by Twitter
+ private static final String ACCESS_TOKEN_URL =
"https://api.twitter.com/oauth/access_token";
+
+ public String getRequestTokenURL() {
+ return REQUEST_TOKEN_URL;
+ }
+
+ public String getAuthorizeTokenURL() {
+ return AUTHORIZE_TOKEN_URL;
+ }
+
+ public String getAccessTokenURL() {
+ return ACCESS_TOKEN_URL;
+ }
+}
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits