Skip to content

Commit

Permalink
Merge branch 'main' into work-magiclink
Browse files Browse the repository at this point in the history
  • Loading branch information
ashanthamara authored Jan 18, 2024
2 parents d608511 + 4e8ae6f commit 217ffcc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.wso2.carbon.identity.local.auth.magiclink</groupId>
<artifactId>identity-local-auth-magiclink</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>1.1.18-SNAPSHOT</version>
<version>1.1.20-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.RequestParams.RESTART_FLOW;
Expand Down Expand Up @@ -214,6 +215,15 @@ protected void initiateAuthenticationRequest(HttpServletRequest request, HttpSer
if (StringUtils.isNotEmpty(magicToken)) {
String expiryTime =
TimeUnit.SECONDS.toMinutes(getExpiryTime()) + " " + TimeUnit.MINUTES.name().toLowerCase();
if (Boolean.parseBoolean((String) context.getProperty(IS_API_BASED))) {
/* Setting a state param to the request for the client to be able to correlate the
magic link coming to the app in API based authentication flow. The code is written in
this manner as it is not possible to dynamically set params to the email template. */
String state = UUID.randomUUID().toString();
context.setProperty(MagicLinkAuthenticatorConstants.AUTHENTICATOR_NAME +
MagicLinkAuthenticatorConstants.STATE_PARAM_SUFFIX, state);
magicToken = magicToken + "&" + MagicLinkAuthenticatorConstants.STATE_PARAM + "=" + state;
}
triggerEvent(user, context, magicToken, expiryTime);
}
}
Expand Down Expand Up @@ -369,6 +379,12 @@ public String getName() {
return MagicLinkAuthenticatorConstants.AUTHENTICATOR_NAME;
}

@Override
public String getI18nKey() {

return MagicLinkAuthenticatorConstants.AUTHENTICATOR_MAGIC_LINK;
}

/**
* Method to Trigger the Magic Link event.
*
Expand Down Expand Up @@ -662,6 +678,13 @@ public Optional<AuthenticatorData> getAuthInitiationData(AuthenticationContext c
requiredParams.add(MLT);
authenticatorData.setRequiredParams(requiredParams);
setAuthParams(authenticatorData);
Map<String, String> additionalAuthenticationParams = new HashMap<>();
String state = (String) context.getProperty(MagicLinkAuthenticatorConstants.AUTHENTICATOR_NAME +
MagicLinkAuthenticatorConstants.STATE_PARAM_SUFFIX);
additionalAuthenticationParams.put(MagicLinkAuthenticatorConstants.STATE_PARAM, state);
AdditionalData additionalData = new AdditionalData();
additionalData.setAdditionalAuthenticationParams(additionalAuthenticationParams);
authenticatorData.setAdditionalData(additionalData);
}

return Optional.of(authenticatorData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private MagicLinkAuthenticatorConstants() {
}

public static final String AUTHENTICATOR_NAME = "MagicLinkAuthenticator";
public static final String AUTHENTICATOR_MAGIC_LINK = "authenticator.magic.link";
public static final String MLT = "mlt";
public static final String AUTHENTICATOR_FRIENDLY_NAME = "Magic Link";
public static final String MAGIC_LINK_NOTIFICATION_PAGE = "authenticationendpoint/magic_link_notification.do";
Expand Down Expand Up @@ -57,6 +58,8 @@ private MagicLinkAuthenticatorConstants() {
public static final String IS_API_BASED_AUTHENTICATION_SUPPORTED = "isAPIBasedAuthenticationSupported";
public static final String CALLBACK_URL = "callbackUrl";
public static final String MULTI_OPTION_QUERY_PARAM = "multiOptionURI";
public static final String STATE_PARAM_SUFFIX = "_state_param";
public static final String STATE_PARAM = "state";

/**
* Constants related to log management.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>identity-local-auth-magiclink</artifactId>
<groupId>org.wso2.carbon.identity.local.auth.magiclink</groupId>
<version>1.1.18-SNAPSHOT</version>
<version>1.1.20-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<groupId>org.wso2.carbon.identity.local.auth.magiclink</groupId>
<artifactId>identity-local-auth-magiclink</artifactId>
<packaging>pom</packaging>
<version>1.1.18-SNAPSHOT</version>
<version>1.1.20-SNAPSHOT</version>
<name>WSO2 Carbon - MagicLink Authenticator</name>
<scm>
<url>https://github.com/wso2-extensions/identity-local-auth-magiclink.git</url>
Expand Down

0 comments on commit 217ffcc

Please sign in to comment.