Skip to content

Commit

Permalink
Merge pull request #45 from DMHP/api
Browse files Browse the repository at this point in the history
Add display name to magic link
  • Loading branch information
DMHP authored Nov 17, 2023
2 parents d9a5a43 + 814dd81 commit 14a6419
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.BLOCKED_USERSTORE_DOMAINS_LIST;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.BLOCKED_USERSTORE_DOMAINS_SEPARATOR;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.DEFAULT_EXPIRY_TIME;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.DISPLAY_MAGIC_LINK_TOKEN;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.DISPLAY_USER_NAME;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.EXPIRY_TIME;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.LogConstants.ActionIDs.PROCESS_AUTHENTICATION_RESPONSE;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.LogConstants.ActionIDs.SEND_MAGIC_LINK;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.LogConstants.ActionIDs.VALIDATE_MAGIC_LINK_REQUEST;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.LogConstants.MAGIC_LINK_AUTH_SERVICE;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.MAGIC_LINK_TOKEN;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.USERNAME_PARAM;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.USER_NAME;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.USER_PROMPT;
Expand Down Expand Up @@ -253,10 +256,10 @@ protected void processAuthenticationResponse(HttpServletRequest request, HttpSer
.inputParams(getApplicationDetails(context));
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}
if (StringUtils.isEmpty(request.getParameter(MagicLinkAuthenticatorConstants.MAGIC_LINK_TOKEN))) {
if (StringUtils.isEmpty(request.getParameter(MAGIC_LINK_TOKEN))) {
throw new InvalidCredentialsException("MagicToken cannot be null.");
} else {
String magicToken = request.getParameter(MagicLinkAuthenticatorConstants.MAGIC_LINK_TOKEN);
String magicToken = request.getParameter(MAGIC_LINK_TOKEN);
MagicLinkAuthContextCacheKey magicLinkAuthContextCacheKey = new MagicLinkAuthContextCacheKey(magicToken);
MagicLinkAuthContextCacheEntry magicLinkAuthContextCacheEntry = MagicLinkAuthContextCache.getInstance()
.getValueFromCache(magicLinkAuthContextCacheKey);
Expand Down Expand Up @@ -330,7 +333,7 @@ public boolean canHandle(HttpServletRequest httpServletRequest) {
return canHandle;
}
boolean canHandle = StringUtils.isNotEmpty(httpServletRequest.getParameter(
MagicLinkAuthenticatorConstants.MAGIC_LINK_TOKEN));
MAGIC_LINK_TOKEN));
if (LoggerUtils.isDiagnosticLogsEnabled() && diagnosticLogBuilder != null && canHandle) {
diagnosticLogBuilder.resultMessage("Magic link authenticator is handling the authentication.");
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
Expand All @@ -341,7 +344,7 @@ public boolean canHandle(HttpServletRequest httpServletRequest) {
@Override
public String getContextIdentifier(HttpServletRequest request) {

String magicToken = request.getParameter(MagicLinkAuthenticatorConstants.MAGIC_LINK_TOKEN);
String magicToken = request.getParameter(MAGIC_LINK_TOKEN);

if (StringUtils.isEmpty(magicToken)) {
return null;
Expand Down Expand Up @@ -424,8 +427,8 @@ protected void triggerEvent(User user, AuthenticationContext context, String mag
private void setAuthParams(AuthenticatorData authenticatorData) {

List<AuthenticatorParamMetadata> authenticatorParamMetadataList = new ArrayList<>();
AuthenticatorParamMetadata usernameMetadata = new AuthenticatorParamMetadata(
MagicLinkAuthenticatorConstants.MAGIC_LINK_TOKEN, FrameworkConstants.AuthenticatorParamType.STRING,
AuthenticatorParamMetadata usernameMetadata = new AuthenticatorParamMetadata(MAGIC_LINK_TOKEN,
DISPLAY_MAGIC_LINK_TOKEN, FrameworkConstants.AuthenticatorParamType.STRING,
0, Boolean.TRUE, MagicLinkAuthenticatorConstants.MAGIC_LINK_CODE);
authenticatorParamMetadataList.add(usernameMetadata);
authenticatorData.setAuthParams(authenticatorParamMetadataList);
Expand Down Expand Up @@ -666,7 +669,7 @@ private void setAuthParamsForIdfInitiatedFromMagicLink(AuthenticatorData authent

List<AuthenticatorParamMetadata> authenticatorParamMetadataList = new ArrayList<>();
AuthenticatorParamMetadata usernameMetadata = new AuthenticatorParamMetadata(
USER_NAME, FrameworkConstants.AuthenticatorParamType.STRING,
USER_NAME, DISPLAY_USER_NAME, FrameworkConstants.AuthenticatorParamType.STRING,
0, Boolean.FALSE, USERNAME_PARAM);
authenticatorParamMetadataList.add(usernameMetadata);
authenticatorData.setAuthParams(authenticatorParamMetadataList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private MagicLinkAuthenticatorConstants() {
public static final String AUTHENTICATOR_FRIENDLY_NAME = "Magic Link";
public static final String MAGIC_LINK_NOTIFICATION_PAGE = "authenticationendpoint/magic_link_notification.do";
public static final String MAGIC_LINK_TOKEN = "mlt";
public static final String DISPLAY_MAGIC_LINK_TOKEN = "Magic Link Token";
public static final String EXPIRY_TIME = "ExpiryTime";
public static final String BLOCKED_USERSTORE_DOMAINS_LIST = "BlockedUserStoreDomains";
public static final String BLOCKED_USERSTORE_DOMAINS_SEPARATOR = ",";
Expand All @@ -41,6 +42,7 @@ private MagicLinkAuthenticatorConstants() {
public static final String IDF_HANDLER_NAME = "IdentifierExecutor";
public static final String LOCAL = "LOCAL";
public static final String USER_NAME = "username";
public static final String DISPLAY_USER_NAME = "Username";
public static final String USERNAME_PARAM = "username.param";
public static final String MAGIC_LINK_CODE = "magic.link.code.param";
public static final String USER_PROMPT = "USER_PROMPT";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertThrows;
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.USERNAME_CLAIM;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.DISPLAY_USER_NAME;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.USERNAME_PARAM;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.USER_NAME;

Expand Down Expand Up @@ -576,8 +577,8 @@ public void testGetAuthInitiationData() {

List<AuthenticatorParamMetadata> authenticatorParamMetadataList = new ArrayList<>();
AuthenticatorParamMetadata usernameMetadata = new AuthenticatorParamMetadata(
MagicLinkAuthenticatorConstants.USER_NAME, FrameworkConstants.AuthenticatorParamType.STRING,
0, Boolean.FALSE, MagicLinkAuthenticatorConstants.USERNAME_PARAM);
USER_NAME, DISPLAY_USER_NAME, FrameworkConstants.AuthenticatorParamType.STRING,
0, Boolean.FALSE, USERNAME_PARAM);
authenticatorParamMetadataList.add(usernameMetadata);


Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
<identity.application.authenticator.magiclink.exp.pkg.version>${project.version}
</identity.application.authenticator.magiclink.exp.pkg.version>
<carbon.kernel.version>4.9.10</carbon.kernel.version>
<carbon.identity.framework.version>5.25.509</carbon.identity.framework.version>
<carbon.identity.framework.version>5.25.522</carbon.identity.framework.version>
<apache.felix.scr.ds.annotations.version>1.2.10</apache.felix.scr.ds.annotations.version>
<identity.event.handler.notification.version>1.3.14</identity.event.handler.notification.version>
<identity.inbound.auth.oauth.version>6.11.172</identity.inbound.auth.oauth.version>
Expand Down

0 comments on commit 14a6419

Please sign in to comment.