Skip to content

Commit

Permalink
Update VK, OK OAuth 2.0 providers, added mail.ru OAuth 2.0 provider (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maximthomas authored Nov 26, 2024
1 parent de862f6 commit 066a5ec
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2024 3A Systems LLC.
*/

package org.forgerock.openam.authentication.modules.oauth2.profile;

import org.forgerock.openam.authentication.modules.oauth2.HttpRequestContent;
import org.forgerock.openam.authentication.modules.oauth2.OAuthConf;

import javax.security.auth.login.LoginException;
import java.util.HashMap;
import java.util.Map;

public class MailRuProfileProvider implements ProfileProvider {

private static final ProfileProvider INSTANCE = new MailRuProfileProvider();

public static ProfileProvider getInstance() {
return INSTANCE;
}
@Override
public String getProfile(OAuthConf config, String token) throws LoginException {
Map<String, String> profileServiceGetParameters = new HashMap<>();
profileServiceGetParameters.put("access_token", token);
profileServiceGetParameters.putAll(config.getProfileServiceGetParameters());
return HttpRequestContent.getInstance().getContentUsingGET(config.getProfileServiceUrl(), null,
profileServiceGetParameters);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2018-2024 3A Systems LLC.
*/

package org.forgerock.openam.authentication.modules.oauth2.profile;

import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -39,7 +55,6 @@ public String getProfile(OAuthConf config, String token) throws LoginException {
Map<String, String> parameters = new HashMap<>();
parameters.put("application_key", publicKey);
parameters.put("format", "JSON");
System.err.println(profileServiceUrl);
try {
signRequest(token, parameters, privateKey);
} catch(Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2018-2024 3A Systems LLC.
*/

package org.forgerock.openam.authentication.modules.oauth2.profile;

import org.apache.commons.lang.StringUtils;
Expand All @@ -11,6 +27,8 @@ public static ProfileProvider getProfileProvider(OAuthConf config) {
return VkontakteProvider.getInstance();
if(StringUtils.defaultString(config.getProfileServiceUrl()).contains("esia"))
return ESIAProfileProvider.getInstance();
if(StringUtils.defaultString(config.getProfileServiceUrl()).contains("mail.ru"))
return MailRuProfileProvider.getInstance();
return DefaultProfileProvider.getInstance();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2018-2024 3A Systems LLC.
*/

package org.forgerock.openam.authentication.modules.oauth2.profile;

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

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

public static final String VK_API_VERSION = "[vk-api-version]";

private static final ProfileProvider INSTANCE = new VkontakteProvider();

public static ProfileProvider getInstance() {
Expand All @@ -40,7 +58,10 @@ public String getProfile(OAuthConf config, String token) throws LoginException {
Map<String, String> parameters = new HashMap<>();
parameters.put("fields", PROFILE_FIELDS);
parameters.put("access_token", token);
parameters.put("v", "5.74");
parameters.put("v", "5.199");
if(config.getCustomProperties().get(VK_API_VERSION) != null) {
parameters.put("v", config.getCustomProperties().get(VK_API_VERSION));
}
String jsonResponse = HttpRequestContent.getInstance().getContentUsingGET(config.getProfileServiceUrl(), null,
parameters);

Expand Down

0 comments on commit 066a5ec

Please sign in to comment.