Skip to content

Commit 3fb9fa8

Browse files
allow 'realm' parameter in OAuthParameters
1 parent 60aa4bb commit 3fb9fa8

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

src/main/java/org/scribe/model/OAuthRequest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44

55
/**
66
* The representation of an OAuth HttpRequest.
7-
*
8-
* Adds OAuth-related functionality to the {@link Request}
9-
*
7+
*
8+
* Adds OAuth-related functionality to the {@link Request}
9+
*
1010
* @author Pablo Fernandez
1111
*/
1212
public class OAuthRequest extends Request
1313
{
1414
private static final String OAUTH_PREFIX = "oauth_";
1515
private Map<String, String> oauthParameters;
1616
private String realm;
17-
17+
1818
/**
1919
* Default constructor.
20-
*
20+
*
2121
* @param verb Http verb/method
2222
* @param url resource URL
2323
*/
@@ -29,10 +29,10 @@ public OAuthRequest(Verb verb, String url)
2929

3030
/**
3131
* Adds an OAuth parameter.
32-
*
32+
*
3333
* @param key name of the parameter
3434
* @param value value of the parameter
35-
*
35+
*
3636
* @throws IllegalArgumentException if the parameter is not an OAuth parameter
3737
*/
3838
public void addOAuthParameter(String key, String value)
@@ -42,36 +42,36 @@ public void addOAuthParameter(String key, String value)
4242

4343
private String checkKey(String key)
4444
{
45-
if (key.startsWith(OAUTH_PREFIX) || key.equals(OAuthConstants.SCOPE))
45+
if (key.startsWith(OAUTH_PREFIX) || key.equals(OAuthConstants.SCOPE) || key.equals(OAuthConstants.REALM))
4646
{
4747
return key;
48-
}
48+
}
4949
else
5050
{
51-
throw new IllegalArgumentException(String.format("OAuth parameters must either be '%s' or start with '%s'", OAuthConstants.SCOPE, OAUTH_PREFIX));
51+
throw new IllegalArgumentException(String.format("OAuth parameters must either be '%s', '%s' or start with '%s'", OAuthConstants.SCOPE, OAuthConstants.REALM, OAUTH_PREFIX));
5252
}
5353
}
5454

5555
/**
5656
* Returns the {@link Map} containing the key-value pair of parameters.
57-
*
57+
*
5858
* @return parameters as map
5959
*/
6060
public Map<String, String> getOauthParameters()
6161
{
6262
return oauthParameters;
6363
}
6464

65-
public void setRealm(String realm)
65+
public void setRealm(String realm)
6666
{
6767
this.realm = realm;
6868
}
69-
70-
public String getRealm()
69+
70+
public String getRealm()
7171
{
7272
return realm;
7373
}
74-
74+
7575
@Override
7676
public String toString()
7777
{

src/test/java/org/scribe/model/OAuthRequestTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ public void shouldAddOAuthParamters()
2222
request.addOAuthParameter(OAuthConstants.NONCE, "nonce");
2323
request.addOAuthParameter(OAuthConstants.TIMESTAMP, "ts");
2424
request.addOAuthParameter(OAuthConstants.SCOPE, "feeds");
25+
request.addOAuthParameter(OAuthConstants.REALM, "some-realm");
2526

26-
assertEquals(4, request.getOauthParameters().size());
27+
assertEquals(5, request.getOauthParameters().size());
2728
}
2829

2930
@Test(expected = IllegalArgumentException.class)

0 commit comments

Comments
 (0)