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

```

Sign-in and sign-up-or-in optionally take the provider to deliver the link with, the SSO application
to sign in to, and whether to send the link to the user's recovery address. Sign-up optionally takes
the provider and the message template to use.

```java
try {
res = els.signIn(loginId, uri, null, loginOptions, "providerId", "ssoAppId", true);
res = els.signUpOrIn(loginId, uri, "providerId", "ssoAppId", false);
res = els.signUp(loginId, uri, user, signUpOptions, "providerId", "templateId");
PhoneEnchantedLinkResponse phoneRes =
els.signInWithPhone(phoneNumber, uri, null, loginOptions, "providerId", "ssoAppId", true);
phoneRes = els.signUpOrInWithPhone(phoneNumber, uri, "providerId", "ssoAppId", false);
phoneRes = els.signUpWithPhone(phoneNumber, uri, user, signUpOptions, "providerId", "templateId");
} 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 @@ -271,6 +290,33 @@ try {

```

When the link was requested with a PKCE challenge, pass the matching verifier:

```java
try {
els.verify(token, pkceVerifier);
} catch (DescopeException de) {
// Token is invalid, handle the error
}

```

To update a user's email or phone, verified by an enchanted link, pass the user's refresh token.
The provider, message template, locale and whether to fail instead of merging with another user
that already has the address are optional.

```java
try {
EnchantedLinkResponse emailRes = els.updateUserEmail(loginId, "new@example.com", uri, refreshToken,
new UpdateOptions(true, false), null, "providerId", "templateId", "en", true);
PhoneEnchantedLinkResponse phoneRes = els.updateUserPhone(loginId, "+15555555555", uri, refreshToken,
null, null, "providerId", "templateId", "en", true);
} 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
40 changes: 40 additions & 0 deletions src/main/java/com/descope/model/auth/AuthenticationInfo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.descope.model.auth;

import com.descope.model.jwt.Token;
import com.descope.model.jwt.response.JWTResponse;
import com.descope.model.user.response.UserResponse;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand All @@ -13,8 +14,47 @@ public class AuthenticationInfo {
private UserResponse user;
private Boolean firstSeen;
private IDPResponse idpResponse;
private Integer sessionExpiration;
private String externalToken;
private String tenantSSOID;
private String trustedDeviceJwt;
private Integer nextRefreshSeconds;
private String cookieName;
private String sessionCookieName;
private String sessionCookieDomain;
private Boolean unsavedSSO;
private String knownDeviceJwt;
/** Set only when the login went through an SSO configuration classified as authentication only. */
private Boolean ssoAuthenticationOnly;
private Boolean userCreationDeferred;

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

// Keeps the pre-sessionExpiration all-args constructor available to callers that use it positionally.
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);
}

/** Builds the info from a JWT response, copying every response field. */
public static AuthenticationInfo fromJwtResponse(Token token, Token refreshToken, JWTResponse jwtResponse) {
AuthenticationInfo info = new AuthenticationInfo(token, refreshToken, jwtResponse.getUser(),
jwtResponse.getFirstSeen(), jwtResponse.getIdpResponse());
info.setSessionExpiration(jwtResponse.getSessionExpiration());
info.setExternalToken(jwtResponse.getExternalToken());
info.setTenantSSOID(jwtResponse.getTenantSSOID());
info.setTrustedDeviceJwt(jwtResponse.getTrustedDeviceJwt());
info.setNextRefreshSeconds(jwtResponse.getNextRefreshSeconds());
info.setCookieName(jwtResponse.getCookieName());
info.setSessionCookieName(jwtResponse.getSessionCookieName());
info.setSessionCookieDomain(jwtResponse.getSessionCookieDomain());
info.setUnsavedSSO(jwtResponse.getUnsavedSSO());
info.setKnownDeviceJwt(jwtResponse.getKnownDeviceJwt());
info.setSsoAuthenticationOnly(jwtResponse.getSsoAuthenticationOnly());
info.setUserCreationDeferred(jwtResponse.getUserCreationDeferred());
return info;
}
}
12 changes: 12 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,16 @@ 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;

// Keeps the pre-samlResponse all-args constructor available to callers that use it positionally.
public IDPResponse(List<String> idpGroups, Map<String, Object> idpSAMLAttributes,
Map<String, Object> idpOIDCClaims) {
this(idpGroups, idpSAMLAttributes, idpOIDCClaims, null, null, null, null, null, null);
}
}
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 @@ -19,6 +19,26 @@ public class JWTResponse {
private UserResponse user;
private Boolean firstSeen;
private IDPResponse idpResponse;
private Integer sessionExpiration;
private String externalToken;
private String tenantSSOID;
private String trustedDeviceJwt;
private Integer nextRefreshSeconds;
private String cookieName;
private String sessionCookieName;
private String sessionCookieDomain;
private Boolean unsavedSSO;
private String knownDeviceJwt;
/** Set only when the login went through an SSO configuration classified as authentication only. */
private Boolean ssoAuthenticationOnly;
private Boolean userCreationDeferred;

// Keeps the pre-sessionExpiration all-args constructor available to callers that use it positionally.
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);
}

public JWTResponse(String sessionJwt, String refreshJwt, String cookieDomain, String cookiePath,
Integer cookieMaxAge, Integer cookieExpiration, UserResponse user, Boolean firstSeen) {
Expand Down
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 ssoAppId;
private Boolean useRecovery;

// Keeps the pre-providerId all-args constructor available to callers that use it positionally.
public SignInRequest(String uri, String loginId, LoginOptions loginOptions) {
this(uri, loginId, loginOptions, null, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ 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);
}

// Keeps the pre-providerId all-args constructor available to callers that use it positionally.
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,14 @@ 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;

// Keeps the pre-providerId all-args constructor available to callers that use it positionally.
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,14 @@ 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;

// Keeps the pre-providerId all-args constructor available to callers that use it positionally.
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,10 @@
@AllArgsConstructor
public class VerifyRequest {
private String token;
private byte[] pkceVerifier;

// Keeps the pre-pkceVerifier all-args constructor available to callers that use it positionally.
public VerifyRequest(String token) {
this(token, null);
}
}
19 changes: 19 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,19 @@
package com.descope.model.user.response;

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

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserFamily {
private String familyId;
private List<String> roleNames;
private List<String> permissions;
private Map<String, Object> familyScopedAttributes;
}
51 changes: 51 additions & 0 deletions src/main/java/com/descope/model/user/response/UserResponse.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.descope.model.user.response;

import com.descope.model.auth.AssociatedTenant;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -40,4 +42,53 @@ public class UserResponse {
* this is greater than now.
*/
Long tempLockExpiration;
List<String> externalIds;
Boolean webauthn;
Boolean password;
Boolean editable;
@JsonProperty("SCIM")
Boolean scim;
Boolean push;
List<String> permissions;
@JsonProperty("OIDC")
Boolean oidc;
Long consentExpiration;
String recoveryEmail;
Boolean verifiedRecoveryEmail;
String recoveryPhone;
Boolean verifiedRecoveryPhone;
Long modifiedTime;
/** IDs of the user's roles, in no particular order relative to roleNames. */
List<String> roleIds;
/** Whether the user has set up recovery codes. */
Boolean recoveryCodes;
Boolean dependent;
List<UserFamily> userFamilies;
/** Tenant whose SCIM connection provisioned the user, empty when none or ambiguous. */
String scimTenantId;
/** Tenant whose SAML SSO created the user or merged its login into it, empty when none or ambiguous. */
String samlTenantId;
/** Tenant whose OIDC SSO created the user or merged its login into it, empty when none or ambiguous. */
String oidcTenantId;
String consentTenantId;
/** Last time the user authenticated, in unix seconds (0 when never). */
Long lastLoginTime;

// Keeps the pre-externalIds all-args constructor available to callers that use it positionally.
public UserResponse(String userId, List<String> loginIds, String email, Boolean verifiedEmail, String phone,
Boolean verifiedPhone, String name, String givenName, String middleName, String familyName,
List<String> roleNames, List<AssociatedTenant> userTenants, String status, String picture, Boolean test,
Long createdTime, Map<String, Object> customAttributes, Boolean totp, Boolean saml,
Map<String, Boolean> oauth, List<String> ssoAppIds, String lockReason, Long tempLockExpiration) {
this(userId, loginIds, email, verifiedEmail, phone, verifiedPhone, name, givenName, middleName, familyName,
roleNames, userTenants, status, picture, test, createdTime, customAttributes, totp, saml, oauth, ssoAppIds,
lockReason, tempLockExpiration, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null);
}

// The server sends "OAuth"; "oauth" is still accepted.
@JsonAlias("OAuth")
public void setOAuth(Map<String, Boolean> oauth) {
this.oAuth = oauth;
}
}
Loading
Loading