Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,56 @@ try {

```

Sign in, sign up or sign up or in accept optional request options, such as the messaging provider and template:

```java
try {
String uri = "http://myapp.com/verify-magic-link";
MagicLinkSignInOptions signInOptions = MagicLinkSignInOptions.builder()
.providerId("my-provider")
.templateId("my-template")
.build();
LoginOptions loginOptions = LoginOptions.builder().tenantId("my-tenant").build();
String maskedAddress = mls.signIn(DeliveryMethod.EMAIL, loginId, uri, null, loginOptions, signInOptions);
maskedAddress = mls.signUpOrIn(DeliveryMethod.EMAIL, loginId, uri, loginOptions, signInOptions);

// The phone option applies to SMS and WhatsApp sign-up only
String phone = "+12125551234";
MagicLinkSignUpOptions signUpRequestOptions = MagicLinkSignUpOptions.builder()
.phone(phone)
.providerId("my-provider")
.templateId("my-template")
.build();
SignUpOptions signUpOptions = SignUpOptions.builder().locale("en").tenantId("my-tenant").build();
maskedAddress = mls.signUp(DeliveryMethod.SMS, phone, uri, User.builder().phone(phone).build(), signUpOptions,
signUpRequestOptions);
} catch (DescopeException de) {
// Handle the error
}

```

To update a user's email or phone through a magic link, pass the refresh token of the user's session. Update options
can also set the messaging provider, template, locale, and whether to fail instead of merging on a conflict:

```java
try {
UpdateOptions updateOptions = UpdateOptions.builder()
.addToLoginIds(true)
.providerId("my-provider")
.templateId("my-template")
.locale("en")
.failOnConflict(true)
.build();
String maskedEmail = mls.updateUserEmail(loginId, "new@descope.com", uri, refreshToken, updateOptions);
String maskedPhone = mls.updateUserPhone(DeliveryMethod.SMS, loginId, "+12125551234", uri, refreshToken,
updateOptions);
} catch (DescopeException de) {
// Handle the error
}

```

To verify a magic link, your redirect page must call the validation function on the token (`t`) parameter (`https://your-redirect-address.com/verify?t=<token>`):

```java
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/descope/model/auth/AssociatedTenant.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.descope.model.auth;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -14,4 +15,14 @@ public class AssociatedTenant {
private String tenantId;
private String tenantName;
private List<String> roleNames;
// Response only: user create and update requests don't accept them
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private List<String> permissions;
/** Not in the same order as roleNames; don't pair them by index. */
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private List<String> roleIds;

public AssociatedTenant(String tenantId, String tenantName, List<String> roleNames) {
this(tenantId, tenantName, roleNames, null, null);
}
}
29 changes: 27 additions & 2 deletions src/main/java/com/descope/model/auth/AuthenticationInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,44 @@

import com.descope.model.jwt.Token;
import com.descope.model.user.response.UserResponse;
import lombok.AllArgsConstructor;
import java.util.Map;
import lombok.Data;

@Data
@AllArgsConstructor
public class AuthenticationInfo {
private Token token; // session token
private Token refreshToken;
private UserResponse user;
private Boolean firstSeen;
private IDPResponse idpResponse;
private String cookieDomain;
private String cookiePath;
private Integer cookieMaxAge;
private Integer cookieExpiration;
private Integer sessionExpiration;
private String externalToken;
private Map<String, Object> claims;
private String tenantSSOID;
private String trustedDeviceJwt;
private Integer nextRefreshSeconds;
private String cookieName;
private String sessionCookieName;
private String sessionCookieDomain;
private Boolean unsavedSSO;
private String knownDeviceJwt;
private Boolean ssoAuthenticationOnly;
private Boolean userCreationDeferred;

public AuthenticationInfo(Token token, Token refreshToken, UserResponse user, Boolean firstSeen) {
this(token, refreshToken, user, firstSeen, null);
}

public AuthenticationInfo(Token token, Token refreshToken, UserResponse user, Boolean firstSeen,
IDPResponse idpResponse) {
this.token = token;
this.refreshToken = refreshToken;
this.user = user;
this.firstSeen = firstSeen;
this.idpResponse = idpResponse;
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/descope/model/auth/IDPResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,15 @@ public class IDPResponse {
private List<String> idpGroups;
private Map<String, Object> idpSAMLAttributes;
private Map<String, Object> idpOIDCClaims;
private String samlResponse;
private String samlGeneratedUser;
private String samlGeneratedRoles;
private String oidcResponse;
private String oidcGeneratedUser;
private String oidcGeneratedRoles;

public IDPResponse(List<String> idpGroups, Map<String, Object> idpSAMLAttributes,
Map<String, Object> idpOIDCClaims) {
this(idpGroups, idpSAMLAttributes, idpOIDCClaims, null, null, null, null, null, null);
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/descope/model/auth/UpdateOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@
public class UpdateOptions {
private boolean addToLoginIds;
private boolean onMergeUseExisting;
// Sent by the magic link update methods only
private String providerId;
private String templateId;
private String locale;
private Boolean failOnConflict;

public UpdateOptions(boolean addToLoginIds, boolean onMergeUseExisting) {
this(addToLoginIds, onMergeUseExisting, null, null, null, null);
}
}
30 changes: 28 additions & 2 deletions src/main/java/com/descope/model/jwt/response/JWTResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import com.descope.model.auth.IDPResponse;
import com.descope.model.user.response.UserResponse;
import lombok.AllArgsConstructor;
import java.util.Map;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class JWTResponse {
private String sessionJwt;
private String refreshJwt;
Expand All @@ -19,10 +18,37 @@ public class JWTResponse {
private UserResponse user;
private Boolean firstSeen;
private IDPResponse idpResponse;
private Integer sessionExpiration;
private String externalToken;
private Map<String, Object> claims;
private String tenantSSOID;
private String trustedDeviceJwt;
private Integer nextRefreshSeconds;
private String cookieName;
private String sessionCookieName;
private String sessionCookieDomain;
private Boolean unsavedSSO;
private String knownDeviceJwt;
private Boolean ssoAuthenticationOnly;
private Boolean userCreationDeferred;

public JWTResponse(String sessionJwt, String refreshJwt, String cookieDomain, String cookiePath,
Integer cookieMaxAge, Integer cookieExpiration, UserResponse user, Boolean firstSeen) {
this(sessionJwt, refreshJwt, cookieDomain, cookiePath, cookieMaxAge, cookieExpiration, user,
firstSeen, null);
}

public JWTResponse(String sessionJwt, String refreshJwt, String cookieDomain, String cookiePath,
Integer cookieMaxAge, Integer cookieExpiration, UserResponse user, Boolean firstSeen,
IDPResponse idpResponse) {
this.sessionJwt = sessionJwt;
this.refreshJwt = refreshJwt;
this.cookieDomain = cookieDomain;
this.cookiePath = cookiePath;
this.cookieMaxAge = cookieMaxAge;
this.cookieExpiration = cookieExpiration;
this.user = user;
this.firstSeen = firstSeen;
this.idpResponse = idpResponse;
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/descope/model/magiclink/LoginOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class LoginOptions {
private String jwt;
private String locale;
private String templateId;
private String ssoAppId;
/** Base64 PKCE challenge; only enchanted links use it, other methods ignore it. */
private String pkceChallenge;
private String tenantId;

public LoginOptions(boolean stepup, boolean mfa, Map<String, Object> customClaims,
Map<String, String> templateOptions) {
Expand All @@ -41,6 +45,13 @@ public LoginOptions(boolean stepup, boolean mfa, Map<String, Object> customClaim
this.jwt = jwt;
}

public LoginOptions(boolean stepup, boolean mfa, Map<String, Object> customClaims,
Map<String, String> templateOptions, boolean revokeOtherSessions,
String[] revokeOtherSessionsTypes, String jwt, String locale, String templateId) {
this(stepup, mfa, customClaims, templateOptions, revokeOtherSessions, revokeOtherSessionsTypes, jwt, locale,
templateId, null, null, null);
}

public boolean isJWTRequired() {
return this.isStepup() || this.isMfa();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.descope.model.magiclink;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/** Request options sent alongside {@link LoginOptions} by magic link sign-in and sign-up-or-in. */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MagicLinkSignInOptions {
private String providerId;
private String templateId;
private String ssoAppId;
private Boolean useRecovery;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.descope.model.magiclink;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/** Request options sent alongside {@link SignUpOptions} by magic link sign-up. */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MagicLinkSignUpOptions {
/** The user's phone, for SMS and WhatsApp delivery only. */
private String phone;
private String providerId;
private String templateId;
}
9 changes: 9 additions & 0 deletions src/main/java/com/descope/model/magiclink/SignUpOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@
public class SignUpOptions {
private Map<String, Object> customClaims;
private Map<String, String> templateOptions;
private String locale;
/** Base64 PKCE challenge; only enchanted links use it, other methods ignore it. */
private String pkceChallenge;
private String templateId;
private String tenantId;

public SignUpOptions(Map<String, Object> customClaims, Map<String, String> templateOptions) {
this(customClaims, templateOptions, null, null, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ public class SignInRequest {

private String loginId;
private LoginOptions loginOptions;
private String providerId;
private String templateId;
private String ssoAppId;
private Boolean useRecovery;

public SignInRequest(String uri, String loginId, LoginOptions loginOptions) {
this(uri, loginId, loginOptions, null, null, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ public class SignUpRequest {
private String uri;
private SignUpOptions loginOptions;
private String phone;
private String providerId;
private String templateId;

public SignUpRequest(String email, String loginId, User user, String uri,
SignUpOptions loginOptions) {
this(email, loginId, user, uri, loginOptions, null);
}

public SignUpRequest(String email, String loginId, User user, String uri,
SignUpOptions loginOptions, String phone) {
this(email, loginId, user, uri, loginOptions, phone, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@ public class UpdateEmailRequest {
private boolean addToLoginIds;
private boolean onMergeUseExisting;
private Map<String, String> templateOptions;
private String providerId;
private String templateId;
private String locale;
private Boolean failOnConflict;

public UpdateEmailRequest(String email, String loginId, String uri, boolean crossDevice, boolean addToLoginIds,
boolean onMergeUseExisting, Map<String, String> templateOptions) {
this(email, loginId, uri, crossDevice, addToLoginIds, onMergeUseExisting, templateOptions, null, null, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@ public class UpdatePhoneRequest {
private boolean addToLoginIds;
private boolean onMergeUseExisting;
private Map<String, String> templateOptions;
private String providerId;
private String templateId;
private String locale;
private Boolean failOnConflict;

public UpdatePhoneRequest(String phone, String loginId, String uri, boolean crossDevice, boolean addToLoginIds,
boolean onMergeUseExisting, Map<String, String> templateOptions) {
this(phone, loginId, uri, crossDevice, addToLoginIds, onMergeUseExisting, templateOptions, null, null, null, null);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/descope/model/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ public class User {
private String givenName;
private String middleName;
private String familyName;
private String loginId;
private String recoveryEmail;
private String recoveryPhone;

public User(String name, String email, String phone) {
this(name, email, phone, null, null, null);
}

public User(String name, String email, String phone, String givenName, String middleName, String familyName) {
this(name, email, phone, givenName, middleName, familyName, null, null, null);
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/descope/model/user/response/UserFamily.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.descope.model.user.response;

import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserFamily {
private String familyId;
private List<String> roleNames;
private List<String> permissions;
private Map<String, Object> familyScopedAttributes;
}
Loading