|
4 | 4 | import org.scribe.extractors.AccessTokenExtractor; |
5 | 5 | import org.scribe.extractors.JsonTokenExtractor; |
6 | 6 | import org.scribe.model.OAuthConfig; |
| 7 | +import org.scribe.model.OAuthConstants; |
7 | 8 | import org.scribe.model.Verb; |
8 | 9 | import org.scribe.oauth.OAuth20ServiceImpl; |
9 | 10 | import org.scribe.oauth.OAuthService; |
@@ -32,25 +33,25 @@ public String getAccessTokenEndpoint() |
32 | 33 |
|
33 | 34 | private static final String AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%s&redirect_uri=%s"; |
34 | 35 | private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; |
| 36 | + private static final String PARAM_FORMAT = "&%s=%s"; |
35 | 37 |
|
36 | 38 | @Override |
37 | 39 | public String getAuthorizationUrl(OAuthConfig config) |
38 | 40 | { |
39 | | - // Preconditions.checkValidUrl(config.getCallback(), |
40 | | - // "Must provide a valid url as callback. Facebook does not support OOB"); |
41 | | - |
42 | 41 | // Append scope if present |
| 42 | + StringBuilder sb = new StringBuilder(); |
| 43 | + sb.append(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()))); |
| 44 | + |
43 | 45 | if (config.hasScope()) |
44 | | - { |
45 | | - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), |
46 | | - OAuthEncoder.encode(config.getCallback()), |
47 | | - OAuthEncoder.encode(config.getScope())); |
48 | | - } |
49 | | - else |
50 | | - { |
51 | | - return String.format(AUTHORIZE_URL, config.getApiKey(), |
52 | | - OAuthEncoder.encode(config.getCallback())); |
53 | | - } |
| 46 | + sb.append(String.format(PARAM_FORMAT, OAuthConstants.SCOPE, config.getScope())); |
| 47 | + if (config.hasState()) |
| 48 | + sb.append(String.format(PARAM_FORMAT, OAuthConstants.STATE, config.getState())); |
| 49 | + if (config.hasAccessType()) |
| 50 | + sb.append(String.format(PARAM_FORMAT, OAuthConstants.ACCESS_TYPE, config.getAccessType())); |
| 51 | + if (config.hasApprovalPrompt()) |
| 52 | + sb.append(String.format(PARAM_FORMAT, OAuthConstants.APPROVAL_PROMPT, config.getApprovalPrompt())); |
| 53 | + |
| 54 | + return sb.toString(); |
54 | 55 | } |
55 | 56 |
|
56 | 57 | } |
0 commit comments