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

```

Optional authorize parameters, such as prompt and login hint, can be passed with `OAuthAuthorizeOptions`. `startSignIn` and `startSignUp` take the same arguments:

```java
OAuthAuthorizeOptions options = OAuthAuthorizeOptions.builder()
.prompt(Arrays.asList(OAuthPrompt.LOGIN, OAuthPrompt.CONSENT))
.loginHint("user@example.com")
.build();

try {
String url = oas.start("google", "https://my-app.com/handle-oauth", loginOptions, null, options);
} catch (DescopeException de) {
// Handle the error
}

```

To add an OAuth provider to a logged-in user, start an update with the user's refresh token. Set `allowAllMerge` to add the provider even when its email isn't one of the user's login IDs:

```java
try {
String url = oas.updateUser("google", "https://my-app.com/handle-oauth", refreshToken, false, loginOptions);
} catch (DescopeException de) {
// Handle the error
}

```

The user will authenticate with the authentication provider, and will be redirected back to the redirect URL, with an appended `code` HTTP URL parameter. Exchange it to validate the user:

```java
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/descope/enums/OAuthPrompt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.descope.enums;

import lombok.Getter;

public enum OAuthPrompt {
NONE("none"),
LOGIN("login"),
CONSENT("consent"),
SELECT_ACCOUNT("select_account");

@Getter
private final String value;

OAuthPrompt(String value) {
this.value = value;
}
}
1 change: 1 addition & 0 deletions src/main/java/com/descope/literals/Routes.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static class AuthEndPoints {
public static final String COMPOSE_OAUTH_LINK = "/v1/auth/oauth/authorize";
public static final String COMPOSE_OAUTH_LINK_SIGN_IN = "/v1/auth/oauth/authorize/signin";
public static final String COMPOSE_OAUTH_LINK_SIGN_UP = "/v1/auth/oauth/authorize/signup";
public static final String COMPOSE_OAUTH_LINK_UPDATE_USER = "/v1/auth/oauth/authorize/update";
public static final String EXCHANGE_OAUTH_LINK = "/v1/auth/oauth/exchange";

// SAML
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);
}
}
27 changes: 27 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,34 @@ 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 = 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);
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/descope/model/auth/OAuthAuthorizeOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.descope.model.auth;

import com.descope.enums.OAuthPrompt;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/** Optional query parameters for starting an OAuth authorization. */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OAuthAuthorizeOptions {
/** Prompt values to pass to the OAuth provider. */
private List<OAuthPrompt> prompt;
/** Login hint to pass to the OAuth provider. */
private String loginHint;
/** Email address the authentication was initiated with. */
private String initiatedEmail;
}
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,10 +20,29 @@ 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, refreshJwt, cookieDomain, cookiePath, cookieMaxAge, cookieExpiration, user,
firstSeen, idpResponse, 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/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-encoded PKCE challenge (32 bytes), relevant only for enchanted links. */
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
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;
}
63 changes: 63 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,7 @@
package com.descope.model.user.response;

import com.descope.model.auth.AssociatedTenant;
import com.fasterxml.jackson.annotation.JsonAlias;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -40,4 +41,66 @@ public class UserResponse {
* this is greater than now.
*/
Long tempLockExpiration;
List<String> externalIds;
Boolean webauthn;
Boolean password;
Boolean editable;
Boolean SCIM;
Boolean push;
List<String> permissions;
Boolean OIDC;
Long consentExpiration;
String recoveryEmail;
Boolean verifiedRecoveryEmail;
String recoveryPhone;
Boolean verifiedRecoveryPhone;
Long modifiedTime;
/** Role IDs; order doesn't match roleNames. */
List<String> roleIds;
Boolean recoveryCodes;
Boolean dependent;
List<UserFamily> userFamilies;
String scimTenantId;
String samlTenantId;
String oidcTenantId;
String consentTenantId;
/** Previous sign-in time in unix seconds, 0 when none. */
Long lastLoginTime;

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 spec's upper-case keys; the getters keep serializing the lower-case names
@JsonAlias("TOTP")
public void setTOTP(Boolean totp) {
this.TOTP = totp;
}

@JsonAlias("SAML")
public void setSAML(Boolean saml) {
this.SAML = saml;
}

@JsonAlias("OAuth")
public void setOAuth(Map<String, Boolean> oauth) {
this.oAuth = oauth;
}

@JsonAlias("SCIM")
public void setSCIM(Boolean scim) {
this.SCIM = scim;
}

@JsonAlias("OIDC")
public void setOIDC(Boolean oidc) {
this.OIDC = oidc;
}
}
Loading