Skip to content

Commit 066a5ec

Browse files
authored
Update VK, OK OAuth 2.0 providers, added mail.ru OAuth 2.0 provider (#813)
1 parent de862f6 commit 066a5ec

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* The contents of this file are subject to the terms of the Common Development and
3+
* Distribution License (the License). You may not use this file except in compliance with the
4+
* License.
5+
*
6+
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7+
* specific language governing permission and limitations under the License.
8+
*
9+
* When distributing Covered Software, include this CDDL Header Notice in each file and include
10+
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11+
* Header, with the fields enclosed by brackets [] replaced by your own identifying
12+
* information: "Portions copyright [year] [name of copyright owner]".
13+
*
14+
* Copyright 2024 3A Systems LLC.
15+
*/
16+
17+
package org.forgerock.openam.authentication.modules.oauth2.profile;
18+
19+
import org.forgerock.openam.authentication.modules.oauth2.HttpRequestContent;
20+
import org.forgerock.openam.authentication.modules.oauth2.OAuthConf;
21+
22+
import javax.security.auth.login.LoginException;
23+
import java.util.HashMap;
24+
import java.util.Map;
25+
26+
public class MailRuProfileProvider implements ProfileProvider {
27+
28+
private static final ProfileProvider INSTANCE = new MailRuProfileProvider();
29+
30+
public static ProfileProvider getInstance() {
31+
return INSTANCE;
32+
}
33+
@Override
34+
public String getProfile(OAuthConf config, String token) throws LoginException {
35+
Map<String, String> profileServiceGetParameters = new HashMap<>();
36+
profileServiceGetParameters.put("access_token", token);
37+
profileServiceGetParameters.putAll(config.getProfileServiceGetParameters());
38+
return HttpRequestContent.getInstance().getContentUsingGET(config.getProfileServiceUrl(), null,
39+
profileServiceGetParameters);
40+
}
41+
}

openam-authentication/openam-auth-oauth2/src/main/java/org/forgerock/openam/authentication/modules/oauth2/profile/OdnoklassnikiProvider.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* The contents of this file are subject to the terms of the Common Development and
3+
* Distribution License (the License). You may not use this file except in compliance with the
4+
* License.
5+
*
6+
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7+
* specific language governing permission and limitations under the License.
8+
*
9+
* When distributing Covered Software, include this CDDL Header Notice in each file and include
10+
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11+
* Header, with the fields enclosed by brackets [] replaced by your own identifying
12+
* information: "Portions copyright [year] [name of copyright owner]".
13+
*
14+
* Copyright 2018-2024 3A Systems LLC.
15+
*/
16+
117
package org.forgerock.openam.authentication.modules.oauth2.profile;
218

319
import java.io.UnsupportedEncodingException;
@@ -39,7 +55,6 @@ public String getProfile(OAuthConf config, String token) throws LoginException {
3955
Map<String, String> parameters = new HashMap<>();
4056
parameters.put("application_key", publicKey);
4157
parameters.put("format", "JSON");
42-
System.err.println(profileServiceUrl);
4358
try {
4459
signRequest(token, parameters, privateKey);
4560
} catch(Exception e) {

openam-authentication/openam-auth-oauth2/src/main/java/org/forgerock/openam/authentication/modules/oauth2/profile/ProfileProviderFactory.java

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* The contents of this file are subject to the terms of the Common Development and
3+
* Distribution License (the License). You may not use this file except in compliance with the
4+
* License.
5+
*
6+
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7+
* specific language governing permission and limitations under the License.
8+
*
9+
* When distributing Covered Software, include this CDDL Header Notice in each file and include
10+
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11+
* Header, with the fields enclosed by brackets [] replaced by your own identifying
12+
* information: "Portions copyright [year] [name of copyright owner]".
13+
*
14+
* Copyright 2018-2024 3A Systems LLC.
15+
*/
16+
117
package org.forgerock.openam.authentication.modules.oauth2.profile;
218

319
import org.apache.commons.lang.StringUtils;
@@ -11,6 +27,8 @@ public static ProfileProvider getProfileProvider(OAuthConf config) {
1127
return VkontakteProvider.getInstance();
1228
if(StringUtils.defaultString(config.getProfileServiceUrl()).contains("esia"))
1329
return ESIAProfileProvider.getInstance();
30+
if(StringUtils.defaultString(config.getProfileServiceUrl()).contains("mail.ru"))
31+
return MailRuProfileProvider.getInstance();
1432
return DefaultProfileProvider.getInstance();
1533
}
1634
}

openam-authentication/openam-auth-oauth2/src/main/java/org/forgerock/openam/authentication/modules/oauth2/profile/VkontakteProvider.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* The contents of this file are subject to the terms of the Common Development and
3+
* Distribution License (the License). You may not use this file except in compliance with the
4+
* License.
5+
*
6+
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7+
* specific language governing permission and limitations under the License.
8+
*
9+
* When distributing Covered Software, include this CDDL Header Notice in each file and include
10+
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11+
* Header, with the fields enclosed by brackets [] replaced by your own identifying
12+
* information: "Portions copyright [year] [name of copyright owner]".
13+
*
14+
* Copyright 2018-2024 3A Systems LLC.
15+
*/
16+
117
package org.forgerock.openam.authentication.modules.oauth2.profile;
218

319
import java.util.HashMap;
@@ -17,6 +33,8 @@ public class VkontakteProvider implements ProfileProvider {
1733

1834
private static Debug DEBUG = Debug.getInstance("amAuthOAuth2");
1935

36+
public static final String VK_API_VERSION = "[vk-api-version]";
37+
2038
private static final ProfileProvider INSTANCE = new VkontakteProvider();
2139

2240
public static ProfileProvider getInstance() {
@@ -40,7 +58,10 @@ public String getProfile(OAuthConf config, String token) throws LoginException {
4058
Map<String, String> parameters = new HashMap<>();
4159
parameters.put("fields", PROFILE_FIELDS);
4260
parameters.put("access_token", token);
43-
parameters.put("v", "5.74");
61+
parameters.put("v", "5.199");
62+
if(config.getCustomProperties().get(VK_API_VERSION) != null) {
63+
parameters.put("v", config.getCustomProperties().get(VK_API_VERSION));
64+
}
4465
String jsonResponse = HttpRequestContent.getInstance().getContentUsingGET(config.getProfileServiceUrl(), null,
4566
parameters);
4667

0 commit comments

Comments
 (0)