Skip to content

Commit fbe4ffe

Browse files
committed
update ok.ru API urls
1 parent 9dfb671 commit fbe4ffe

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* add OSGI manifest metadata
44
* apiSecret is not mandatory parameter in config (to use on client sides and other flows without need of the API secret)
55
* implement OAuth2 Authorization Response parsing in the OAuth20Service (to extract code and state from url, useful for Android)
6+
* update ok.ru API urls, add 'state' support, add refresh token to the example
67

78
[2.4.0]
89
* APIs 2.0 can define different endpoints for access token and for refresh token (the same urls by default)

scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
public class OdnoklassnikiApi extends DefaultApi20 {
1111

1212
private static final String AUTHORIZE_URL
13-
= "http://www.odnoklassniki.ru/oauth/authorize?client_id=%s&response_type=code&redirect_uri=%s";
14-
private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL);
13+
= "https://connect.ok.ru/oauth/authorize?client_id=%s&response_type=code&redirect_uri=%s";
1514

1615
protected OdnoklassnikiApi() {
1716
}
@@ -26,19 +25,26 @@ public static OdnoklassnikiApi instance() {
2625

2726
@Override
2827
public String getAccessTokenEndpoint() {
29-
return "http://api.odnoklassniki.ru/oauth/token.do";
28+
return "https://api.ok.ru/oauth/token.do";
3029
}
3130

3231
@Override
3332
public String getAuthorizationUrl(OAuthConfig config) {
3433
Preconditions.checkValidUrl(config.getCallback(),
3534
"Valid url is required for a callback. Odnoklassniki does not support OOB");
35+
36+
final StringBuilder urlBuilder = new StringBuilder(String.format(AUTHORIZE_URL,
37+
config.getApiKey(), OAuthEncoder.encode(config.getCallback())));
38+
3639
if (config.hasScope()) {
37-
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()),
38-
OAuthEncoder.encode(config.getScope()));
39-
} else {
40-
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
40+
urlBuilder.append("&scope=").append(OAuthEncoder.encode(config.getScope()));
41+
}
42+
43+
final String state = config.getState();
44+
if (state != null) {
45+
urlBuilder.append("&state=").append(OAuthEncoder.encode(config.getState()));
4146
}
47+
return urlBuilder.toString();
4248
}
4349

4450
@Override

scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public abstract class OdnoklassnikiExample {
1414

1515
private static final String NETWORK_NAME = "Odnoklassniki.ru";
1616
private static final String PROTECTED_RESOURCE_URL
17-
= "http://api.odnoklassniki.ru/api/users/getCurrentUser?application_key=%1$s&format=JSON";
17+
= "https://api.ok.ru/api/users/getCurrentUser?application_key=%1$s&format=JSON";
1818

1919
public static void main(String... args) {
2020
// Replace these with your client id and secret
@@ -49,12 +49,19 @@ public static void main(String... args) {
4949
// Trade the Request Token and Verfier for the Access Token
5050
System.out.println("Trading the Request Token for an Access Token...");
5151

52-
final OAuth2AccessToken accessToken = service.getAccessToken(code);
52+
OAuth2AccessToken accessToken = service.getAccessToken(code);
5353
System.out.println("Got the Access Token!");
5454
System.out.println("(if your curious it looks like this: " + accessToken
5555
+ ", 'rawResponse'='" + accessToken.getRawResponse() + "')");
5656
System.out.println();
5757

58+
System.out.println("Refreshing the Access Token...");
59+
accessToken = service.refreshAccessToken(accessToken.getRefreshToken());
60+
System.out.println("Refreshed the Access Token!");
61+
System.out.println("(if your curious it looks like this: " + accessToken
62+
+ ", 'rawResponse'='" + accessToken.getRawResponse() + "')");
63+
System.out.println();
64+
5865
// Now let's go and ask for a protected resource!
5966
System.out.println("Now we're going to access a protected resource...");
6067
final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, publicKey),

0 commit comments

Comments
 (0)