-
Notifications
You must be signed in to change notification settings - Fork 113
Add oauth
support to Admin Api calls.
#230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ public class Configuration { | |
public boolean forceVersion = true; | ||
public boolean longUrlSignature = DEFAULT_IS_LONG_SIGNATURE; | ||
public SignatureAlgorithm signatureAlgorithm = DEFAULT_SIGNATURE_ALGORITHM; | ||
public String oauthToken = null; | ||
|
||
public Configuration() { | ||
} | ||
|
@@ -71,7 +72,8 @@ private Configuration( | |
boolean loadStrategies, | ||
boolean forceVersion, | ||
boolean longUrlSignature, | ||
SignatureAlgorithm signatureAlgorithm) { | ||
SignatureAlgorithm signatureAlgorithm, | ||
String oauthToken) { | ||
this.cloudName = cloudName; | ||
this.apiKey = apiKey; | ||
this.apiSecret = apiSecret; | ||
|
@@ -87,11 +89,12 @@ private Configuration( | |
this.proxyPort = proxyPort; | ||
this.secureCdnSubdomain = secureCdnSubdomain; | ||
this.useRootPath = useRootPath; | ||
this.timeout = 0; | ||
this.timeout = timeout; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was that changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bugfix (will be in the commit message on merge). |
||
this.loadStrategies = loadStrategies; | ||
this.forceVersion = forceVersion; | ||
this.longUrlSignature = longUrlSignature; | ||
this.signatureAlgorithm = signatureAlgorithm; | ||
this.oauthToken = oauthToken; | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
|
@@ -130,6 +133,7 @@ public void update(Map config) { | |
} | ||
this.longUrlSignature = ObjectUtils.asBoolean(config.get("long_url_signature"), DEFAULT_IS_LONG_SIGNATURE); | ||
this.signatureAlgorithm = SignatureAlgorithm.valueOf(ObjectUtils.asString(config.get(CONFIG_PROP_SIGNATURE_ALGORITHM), DEFAULT_SIGNATURE_ALGORITHM.name())); | ||
this.oauthToken = (String) config.get("oauth_token"); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
|
@@ -160,6 +164,7 @@ public Map<String, Object> asMap() { | |
map.put("properties", new HashMap<String,Object>(properties)); | ||
map.put("long_url_signature", longUrlSignature); | ||
map.put(CONFIG_PROP_SIGNATURE_ALGORITHM, signatureAlgorithm.toString()); | ||
map.put("oauth_token", oauthToken); | ||
return map; | ||
} | ||
|
||
|
@@ -190,6 +195,7 @@ public Configuration(Configuration other) { | |
this.properties.putAll(other.properties); | ||
this.longUrlSignature = other.longUrlSignature; | ||
this.signatureAlgorithm = other.signatureAlgorithm; | ||
this.oauthToken = other.oauthToken; | ||
} | ||
|
||
/** | ||
|
@@ -301,6 +307,7 @@ public static class Builder { | |
private boolean forceVersion = true; | ||
private boolean longUrlSignature = DEFAULT_IS_LONG_SIGNATURE; | ||
private SignatureAlgorithm signatureAlgorithm = DEFAULT_SIGNATURE_ALGORITHM; | ||
private String oauthToken = null; | ||
|
||
/** | ||
* Set the HTTP connection timeout. | ||
|
@@ -337,7 +344,8 @@ public Configuration build() { | |
loadStrategies, | ||
forceVersion, | ||
longUrlSignature, | ||
signatureAlgorithm); | ||
signatureAlgorithm, | ||
oauthToken); | ||
configuration.clientHints = clientHints; | ||
return configuration; | ||
} | ||
|
@@ -466,6 +474,11 @@ public Builder setSignatureAlgorithm(SignatureAlgorithm signatureAlgorithm) { | |
return this; | ||
} | ||
|
||
public Builder setOAuthToken(String oauthToken) { | ||
this.oauthToken = oauthToken; | ||
return this; | ||
} | ||
|
||
/** | ||
* Initialize builder from existing {@link Configuration} | ||
* | ||
|
@@ -495,6 +508,7 @@ public Builder from(Configuration other) { | |
this.forceVersion = other.forceVersion; | ||
this.longUrlSignature = other.longUrlSignature; | ||
this.signatureAlgorithm = other.signatureAlgorithm; | ||
this.oauthToken = other.oauthToken; | ||
return this; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import com.cloudinary.Api.HttpMethod; | ||
import com.cloudinary.SmartUrlEncoder; | ||
import com.cloudinary.api.ApiResponse; | ||
import com.cloudinary.utils.Base64Coder; | ||
import com.cloudinary.utils.StringUtils; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
|
@@ -31,4 +32,19 @@ protected String createApiUrl (Iterable<String> uri, String prefix, String cloud | |
public abstract ApiResponse callApi(HttpMethod method, Iterable<String> uri, Map<String, ? extends Object> params, Map options) throws Exception; | ||
|
||
public abstract ApiResponse callAccountApi(HttpMethod method, Iterable<String> uri, Map<String, ? extends Object> params, Map options) throws Exception; | ||
|
||
protected String getAuthorizationHeaderValue(String apiKey, String apiSecret, String oauthToken) { | ||
if (oauthToken != null){ | ||
return "Bearer " + oauthToken; | ||
} else { | ||
return "Basic " + Base64Coder.encodeString(apiKey + ":" + apiSecret); | ||
} | ||
} | ||
|
||
protected void validateAuthorization(String apiKey, String apiSecret, String oauthToken) { | ||
if (oauthToken == null) { | ||
if (apiKey == null) throw new IllegalArgumentException("Must supply api_key"); | ||
if (apiSecret == null) throw new IllegalArgumentException("Must supply api_secret"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if all of them are null? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If all are null then this is thrown - `IllegalArgumentException("Must supply api_key"). Same behaviour as before for people not using oauth so it doesn't break anything. |
||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.