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
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,29 @@ try {

```

Sign-in, sign-up and sign-up-or-in also take optional delivery settings: the messaging
provider and template, and for sign-in the SSO app and whether to send to the recovery
address. Login options can carry a tenant, an SSO app and a PKCE challenge, whose verifier
is then passed when verifying the link.

```java
try {
LoginOptions loginOptions = LoginOptions.builder().tenantId("tenant").pkceChallenge(challenge).build();
EnchantedLinkSignInOptions signInOptions = EnchantedLinkSignInOptions.builder()
.providerId("provider").templateId("template").ssoAppId("app").useRecovery(true).build();
EnchantedLinkResponse signInRes = els.signIn(loginId, uri, null, loginOptions, signInOptions);
EnchantedLinkResponse signUpOrInRes = els.signUpOrIn(loginId, uri, null, loginOptions, signInOptions);

User user = User.builder().name("name").recoveryEmail("recovery@example.com").build();
SignUpOptions signUpOptions = SignUpOptions.builder().locale("en").tenantId("tenant").build();
EnchantedLinkResponse signUpRes = els.signUp(loginId, uri, user, signUpOptions,
new EnchantedLinkSignUpOptions("provider", "template"));
} catch (DescopeException de) {
// Handle the error
}

```

After sending the link, you must poll to receive a valid session using the `PendingRef` from
the previous step. A valid session will be returned only after the user clicks the right link.

Expand Down Expand Up @@ -265,12 +288,29 @@ To verify an enchanted link, your redirect page must call the validation functio

try {
els.verify(token);
// Or, when the link was sent with a PKCE challenge
els.verify(token, verifier);
} catch (DescopeException de) {
// Token is invalid, handle the error
}

```

To update a signed-in user's email or phone through an enchanted link, pass their refresh
token. `UpdateOptions` can also set the messaging provider, template, locale and `failOnConflict`.

```java
try {
UpdateOptions options = UpdateOptions.builder()
.providerId("provider").templateId("template").locale("en").failOnConflict(true).build();
EnchantedLinkResponse emailRes = els.updateUserEmail(loginId, newEmail, uri, refreshToken, options);
PhoneEnchantedLinkResponse phoneRes = els.updateUserPhone(loginId, newPhone, uri, refreshToken, options);
} catch (DescopeException de) {
// Handle the error
}

```

The session and refresh JWTs should be returned to the caller, and passed with every request in the session. Read more on [session validation](#session-validation)

### OAuth
Expand Down
10 changes: 10 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,13 @@ public class AssociatedTenant {
private String tenantId;
private String tenantName;
private List<String> roleNames;
// Response only: never sent in requests
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private List<String> permissions;
@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);
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/descope/model/auth/AuthenticationInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

Expand All @@ -13,8 +14,31 @@ public class AuthenticationInfo {
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, refreshToken, user, firstSeen, idpResponse, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null);
}
}
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);
}
}
12 changes: 12 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,16 @@
public class UpdateOptions {
private boolean addToLoginIds;
private boolean onMergeUseExisting;
/** Sent by enchanted link updates only. */
private String providerId;
/** Sent by enchanted link updates only. */
private String templateId;
/** Sent by enchanted link updates only. */
private String locale;
/** Sent by enchanted link updates only. */
private Boolean failOnConflict;

public UpdateOptions(boolean addToLoginIds, boolean onMergeUseExisting) {
this(addToLoginIds, onMergeUseExisting, null, null, null, null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.descope.model.enchantedlink;

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

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EnchantedLinkSignInOptions {
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,15 @@
package com.descope.model.enchantedlink;

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

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EnchantedLinkSignUpOptions {
private String providerId;
private String templateId;
}
20 changes: 20 additions & 0 deletions src/main/java/com/descope/model/jwt/response/JWTResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.descope.model.auth.IDPResponse;
import com.descope.model.user.response.UserResponse;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -19,6 +20,25 @@ 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, IDPResponse idpResponse) {
this(sessionJwt, refreshJwt, cookieDomain, cookiePath, cookieMaxAge, cookieExpiration, user, firstSeen,
idpResponse, null, null, null, null, null, null, null, null, null, null, null, null, null);
}

public JWTResponse(String sessionJwt, String refreshJwt, String cookieDomain, String cookiePath,
Integer cookieMaxAge, Integer cookieExpiration, UserResponse user, Boolean firstSeen) {
Expand Down
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,17 @@ public class LoginOptions {
private String jwt;
private String locale;
private String templateId;
private String ssoAppId;
/** PKCE challenge, used by enchanted link only. */
private byte[] pkceChallenge;
private String tenantId;

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 LoginOptions(boolean stepup, boolean mfa, Map<String, Object> customClaims,
Map<String, String> templateOptions) {
Expand Down
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;
/** PKCE challenge, used by enchanted link only. */
private byte[] 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@
@AllArgsConstructor
public class VerifyRequest {
private String token;
private byte[] pkceVerifier;

public VerifyRequest(String token) {
this(token, 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