Added authorization URL to the Apis
This commit is contained in:
1 parent
c12da16a38
commit
5ac849313d
16 files changed
+121
-20
No files matched your search
@@ -117,6 +117,15 @@ public abstract class DefaultApi10a implements Api
|
||||
*/
|
||||
public abstract String getAccessTokenEndpoint();
|
||||
|
||||
/**
|
||||
* Returns the URL where you should redirect your users to authenticate
|
||||
* your application.
|
||||
*
|
||||
* @param requestToken the request token you need to authorize
|
||||
* @return the URL where you should redirect your users
|
||||
*/
|
||||
public abstract String getAuthorizationUrl(Token requestToken);
|
||||
|
||||
/**
|
||||
* Returns the {@link OAuthService} for this Api
|
||||
*
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package org.scribe.builder.api;
|
||||
|
||||
import org.scribe.model.Token;
|
||||
import org.scribe.model.Verb;
|
||||
|
||||
public class EvernoteApi extends DefaultApi10a
|
||||
{
|
||||
private static final String AUTHORIZATION_URL = "https://www.evernote.com/OAuth.action?oauth_token=%s";
|
||||
|
||||
@Override
|
||||
public Verb getRequestTokenVerb()
|
||||
{
|
||||
@@ -27,4 +30,10 @@ public class EvernoteApi extends DefaultApi10a
|
||||
{
|
||||
return "https://www.evernote.com/oauth";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthorizationUrl(Token requestToken)
|
||||
{
|
||||
return String.format(AUTHORIZATION_URL, requestToken.getToken());
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package org.scribe.builder.api;
|
||||
|
||||
import org.scribe.model.Token;
|
||||
|
||||
public class FoursquareApi extends DefaultApi10a
|
||||
{
|
||||
private static final String AUTHORIZATION_URL = "http://foursquare.com/oauth/authorize?oauth_token=%s";
|
||||
|
||||
@Override
|
||||
public String getAccessTokenEndpoint()
|
||||
{
|
||||
@@ -13,4 +17,10 @@ public class FoursquareApi extends DefaultApi10a
|
||||
{
|
||||
return "http://foursquare.com/oauth/request_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthorizationUrl(Token requestToken)
|
||||
{
|
||||
return String.format(AUTHORIZATION_URL, requestToken.getToken());
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import org.scribe.model.*;
|
||||
|
||||
public class GoogleApi extends DefaultApi10a
|
||||
{
|
||||
private static final String AUTHORIZATION_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=%s";
|
||||
|
||||
@Override
|
||||
public String getAccessTokenEndpoint()
|
||||
{
|
||||
@@ -27,4 +29,10 @@ public class GoogleApi extends DefaultApi10a
|
||||
{
|
||||
return Verb.GET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthorizationUrl(Token requestToken)
|
||||
{
|
||||
return String.format(AUTHORIZATION_URL, requestToken.getToken());
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package org.scribe.builder.api;
|
||||
|
||||
public class LinkedInApi extends DefaultApi10a
|
||||
{
|
||||
private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authorize?oauth_token=%s";
|
||||
|
||||
@Override
|
||||
protected String getAccessTokenEndpoint()
|
||||
{
|
||||
@@ -13,4 +15,11 @@ public class LinkedInApi extends DefaultApi10a
|
||||
{
|
||||
return "https://api.linkedin.com/uas/oauth/requestToken";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthorizationUrl(Token requestToken)
|
||||
{
|
||||
return String.format(AUTHORIZE_URL, requestToken.getToken());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package org.scribe.builder.api;
|
||||
|
||||
import org.scribe.model.Token;
|
||||
|
||||
public class TwitterApi extends DefaultApi10a
|
||||
{
|
||||
private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize?oauth_token=%s";
|
||||
|
||||
@Override
|
||||
public String getAccessTokenEndpoint()
|
||||
{
|
||||
@@ -13,4 +17,10 @@ public class TwitterApi extends DefaultApi10a
|
||||
{
|
||||
return "http://api.twitter.com/oauth/request_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthorizationUrl(Token requestToken)
|
||||
{
|
||||
return String.format(AUTHORIZE_URL, requestToken.getToken());
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package org.scribe.builder.api;
|
||||
|
||||
import org.scribe.model.Token;
|
||||
|
||||
public class VimeoApi extends DefaultApi10a
|
||||
{
|
||||
private static final String AUTHORIZATION_URL = "http://vimeo.com/oauth/authorize?oauth_token=%s";
|
||||
|
||||
@Override
|
||||
public String getAccessTokenEndpoint()
|
||||
{
|
||||
@@ -13,4 +17,10 @@ public class VimeoApi extends DefaultApi10a
|
||||
{
|
||||
return "http://vimeo.com/oauth/request_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthorizationUrl(Token requestToken)
|
||||
{
|
||||
return String.format(AUTHORIZATION_URL, requestToken.getToken());
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package org.scribe.builder.api;
|
||||
|
||||
import org.scribe.model.Token;
|
||||
|
||||
public class YahooApi extends DefaultApi10a
|
||||
{
|
||||
private static final String AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=%s";
|
||||
|
||||
@Override
|
||||
public String getAccessTokenEndpoint()
|
||||
{
|
||||
@@ -13,4 +17,10 @@ public class YahooApi extends DefaultApi10a
|
||||
{
|
||||
return "https://api.login.yahoo.com/oauth/v2/get_request_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthorizationUrl(Token requestToken)
|
||||
{
|
||||
return String.format(AUTHORIZE_URL, requestToken.getToken());
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package org.scribe.builder.api;
|
||||
|
||||
import org.scribe.model.Token;
|
||||
|
||||
public class YammerApi extends DefaultApi10a
|
||||
{
|
||||
private static final String AUTHORIZATION_URL = "'https://www.yammer.com/oauth/authorize?oauth_token=%s'";
|
||||
|
||||
@Override
|
||||
public String getRequestTokenEndpoint()
|
||||
@@ -14,5 +17,10 @@ public class YammerApi extends DefaultApi10a
|
||||
{
|
||||
return "https://www.yammer.com/oauth/access_token";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getAuthorizationUrl(Token requestToken)
|
||||
{
|
||||
return String.format(AUTHORIZATION_URL, requestToken.getToken());
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,14 @@ public class OAuth10aServiceImpl implements OAuthService
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getAuthorizationUrl(Token requestToken)
|
||||
{
|
||||
return api.getAuthorizationUrl(requestToken);
|
||||
}
|
||||
|
||||
private String getSignature(OAuthRequest request, Token token)
|
||||
{
|
||||
|
||||
@@ -37,4 +37,10 @@ public class OAuth2ServiceImpl implements OAuthService
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthorizationUrl(Token requestToken)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,4 +48,13 @@ public interface OAuthService
|
||||
* @param scope OAuth Api scope (optional)
|
||||
*/
|
||||
public void addScope(String scope);
|
||||
|
||||
/**
|
||||
* Returns the URL where you should redirect your users to authenticate
|
||||
* your application.
|
||||
*
|
||||
* @param requestToken the request token you need to authorize
|
||||
* @return the URL where you should redirect your users
|
||||
*/
|
||||
public String getAuthorizationUrl(Token requestToken);
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import org.scribe.oauth.*;
|
||||
|
||||
public class FoursquareExample
|
||||
{
|
||||
private static final String AUTHORIZE_URL = "http://foursquare.com/oauth/authorize?oauth_token=";
|
||||
private static final String PROTECTED_RESOURCE_URL = "http://api.foursquare.com/v1/user";
|
||||
|
||||
public static void main(String[] args)
|
||||
@@ -31,7 +30,7 @@ public class FoursquareExample
|
||||
System.out.println();
|
||||
|
||||
System.out.println("Now go and authorize Scribe here:");
|
||||
System.out.println(AUTHORIZE_URL + requestToken.getToken());
|
||||
System.out.println(service.getAuthorizationUrl(requestToken));
|
||||
System.out.println("And paste the verifier here");
|
||||
System.out.print(">>");
|
||||
Verifier verifier = new Verifier(in.nextLine());
|
||||
|
||||
@@ -9,18 +9,17 @@ import org.scribe.oauth.*;
|
||||
|
||||
public class LinkedInExample
|
||||
{
|
||||
private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authorize?oauth_token=";
|
||||
private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)";
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
OAuthService service = new ServiceBuilder()
|
||||
.provider(LinkedInApi.class)
|
||||
.apiKey("CiEgwWDkA5BFpNrc0RfGyVuSlOh4tig5kOTZ9q97qcXNrFl7zqk-Ts7DqRGaKDCV")
|
||||
.apiSecret("dhho4dfoCmiQXrkw4yslork5XWLFnPSuMR-8gscPVjY4jqFFHPYWJKgpFl4uLTM6")
|
||||
.build();
|
||||
|
||||
.provider(LinkedInApi.class)
|
||||
.apiKey("CiEgwWDkA5BFpNrc0RfGyVuSlOh4tig5kOTZ9q97qcXNrFl7zqk-Ts7DqRGaKDCV")
|
||||
.apiSecret("dhho4dfoCmiQXrkw4yslork5XWLFnPSuMR-8gscPVjY4jqFFHPYWJKgpFl4uLTM6")
|
||||
.build();
|
||||
Scanner in = new Scanner(System.in);
|
||||
|
||||
System.out.println("=== LinkedIn's OAuth Workflow ===");
|
||||
System.out.println();
|
||||
|
||||
@@ -31,7 +30,7 @@ public class LinkedInExample
|
||||
System.out.println();
|
||||
|
||||
System.out.println("Now go and authorize Scribe here:");
|
||||
System.out.println(AUTHORIZE_URL + requestToken.getToken());
|
||||
System.out.println(service.getAuthorizationUrl(requestToken));
|
||||
System.out.println("And paste the verifier here");
|
||||
System.out.print(">>");
|
||||
Verifier verifier = new Verifier(in.nextLine());
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.scribe.oauth.*;
|
||||
|
||||
public class TwitterExample
|
||||
{
|
||||
private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize?oauth_token=";
|
||||
private static final String PROTECTED_RESOURCE_URL = "http://api.twitter.com/1/account/verify_credentials.xml";
|
||||
|
||||
public static void main(String[] args)
|
||||
@@ -31,7 +30,7 @@ public class TwitterExample
|
||||
System.out.println();
|
||||
|
||||
System.out.println("Now go and authorize Scribe here:");
|
||||
System.out.println(AUTHORIZE_URL + requestToken.getToken());
|
||||
System.out.println(service.getAuthorizationUrl(requestToken));
|
||||
System.out.println("And paste the verifier here");
|
||||
System.out.print(">>");
|
||||
Verifier verifier = new Verifier(in.nextLine());
|
||||
|
||||
@@ -9,20 +9,18 @@ import org.scribe.oauth.*;
|
||||
|
||||
public class YahooExample
|
||||
{
|
||||
private static final String NETWORK_NAME = "Yahoo";
|
||||
private static final String AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=";
|
||||
private static final String PROTECTED_RESOURCE_URL = "http://social.yahooapis.com/v1/user/A6ROU63MXWDCW3Y5MGCYWVHDJI/profile/status?format=json";
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
OAuthService service = new ServiceBuilder()
|
||||
.provider(YahooApi.class)
|
||||
.apiKey("dj0yJmk9TXZDWVpNVVdGaVFmJmQ9WVdrOWMweHZXbkZLTkhVbWNHbzlNVEl5TWprd05qUTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0wMw--")
|
||||
.apiSecret("262be559f92a2be20c4c039419018f2b48cdfce9")
|
||||
.build();
|
||||
.provider(YahooApi.class)
|
||||
.apiKey("dj0yJmk9TXZDWVpNVVdGaVFmJmQ9WVdrOWMweHZXbkZLTkhVbWNHbzlNVEl5TWprd05qUTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0wMw--")
|
||||
.apiSecret("262be559f92a2be20c4c039419018f2b48cdfce9")
|
||||
.build();
|
||||
Scanner in = new Scanner(System.in);
|
||||
|
||||
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
|
||||
System.out.println("=== Yahoo's OAuth Workflow ===");
|
||||
System.out.println();
|
||||
|
||||
// Obtain the Request Token
|
||||
@@ -32,7 +30,7 @@ public class YahooExample
|
||||
System.out.println();
|
||||
|
||||
System.out.println("Now go and authorize Scribe here:");
|
||||
System.out.println(AUTHORIZE_URL + requestToken.getToken());
|
||||
System.out.println(service.getAuthorizationUrl(requestToken));
|
||||
System.out.println("And paste the verifier here");
|
||||
System.out.print(">>");
|
||||
Verifier verifier = new Verifier(in.nextLine());
|
||||
|
||||
Reference in new issue
Block a user