Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/main/java/com/descope/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ public class ErrorCode {

// rate limit
public static final String RATE_LIMIT_EXCEEDED = "E130429";

// No keys
public static final String INVALID_SIGNING_KEY = "J010001";
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.descope.exception.ErrorCode.ERR_MISSING_ARGUMENTS;
import static com.descope.exception.ErrorCode.ERR_REFRESH_TOKEN;
import static com.descope.exception.ErrorCode.INVALID_ARGUMENT;
import static com.descope.exception.ErrorCode.INVALID_SIGNING_KEY;

import lombok.ToString;

Expand All @@ -27,6 +28,10 @@ public static ServerCommonException missingArguments(String error) {
return new ServerCommonException(error, ERR_MISSING_ARGUMENTS);
}

public static ServerCommonException invalidSigningKey(String error) {
return new ServerCommonException(error, INVALID_SIGNING_KEY);
}

public static ServerCommonException genericServerError(String message, String code) {
return new ServerCommonException(message, code);
}
Expand Down
70 changes: 35 additions & 35 deletions src/main/java/com/descope/literals/Routes.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,53 @@ public static class AuthEndPoints {
public static final String LOG_OUT_ALL_LINK = "/v1/auth/logoutall";

// MagicLink
public static final String SIGN_IN_MAGIC_LINK = "/auth/magiclink/signin";
public static final String SIGN_UP_MAGIC_LINK = "/auth/magiclink/signup";
public static final String VERIFY_MAGIC_LINK = "/auth/magiclink/verify";
public static final String SIGN_UP_OR_IN_MAGIC_LINK = "/auth/magiclink/signup-in";
public static final String UPDATE_EMAIL_MAGIC_LINK = "/auth/magiclink/update/email";
public static final String UPDATE_USER_PHONE_MAGIC_LINK = "/auth/magiclink/update/phone";
public static final String SIGN_IN_MAGIC_LINK = "/v1/auth/magiclink/signin";
public static final String SIGN_UP_MAGIC_LINK = "/v1/auth/magiclink/signup";
public static final String VERIFY_MAGIC_LINK = "/v1/auth/magiclink/verify";
public static final String SIGN_UP_OR_IN_MAGIC_LINK = "/v1/auth/magiclink/signup-in";
public static final String UPDATE_EMAIL_MAGIC_LINK = "/v1/auth/magiclink/update/email";
public static final String UPDATE_USER_PHONE_MAGIC_LINK = "/v1/auth/magiclink/update/phone";

// OTP
public static final String SIGN_IN_OTP_LINK = "/auth/otp/signin";
public static final String SIGN_UP_OTP_LINK = "/auth/otp/signup";
public static final String SIGN_UP_OR_IN_OTP_LINK = "/auth/otp/signup-in";
public static final String VERIFY_OTP_LINK = "/auth/otp/verify";
public static final String OTP_UPDATE_EMAIL_LINK = "/auth/otp/update/email";
public static final String OTP_UPDATE_PHONE_LINK = "/auth/otp/update/phone";
public static final String SIGN_IN_OTP_LINK = "/v1/auth/otp/signin";
public static final String SIGN_UP_OTP_LINK = "/v1/auth/otp/signup";
public static final String SIGN_UP_OR_IN_OTP_LINK = "/v1/auth/otp/signup-in";
public static final String VERIFY_OTP_LINK = "/v1/auth/otp/verify";
public static final String OTP_UPDATE_EMAIL_LINK = "/v1/auth/otp/update/email";
public static final String OTP_UPDATE_PHONE_LINK = "/v1/auth/otp/update/phone";

// EnchantedLink
public static final String SIGN_IN_ENCHANTED_LINK = "/auth/enchantedlink/signin";
public static final String SIGN_UP_ENCHANTED_LINK = "/auth/enchantedlink/signup";
public static final String SIGN_UP_OR_IN_ENCHANTED_LINK = "/auth/enchantedlink/signup-in";
public static final String VERIFY_ENCHANTED_LINK = "/auth/enchantedlink/verify";
public static final String ENCHANTED_LINK_SESSION = "/auth/enchantedlink/pending-session";
public static final String UPDATE_EMAIL_ENCHANTED_LINK = "/auth/enchantedlink/update/email";
public static final String SIGN_IN_ENCHANTED_LINK = "/v1/auth/enchantedlink/signin";
public static final String SIGN_UP_ENCHANTED_LINK = "/v1/auth/enchantedlink/signup";
public static final String SIGN_UP_OR_IN_ENCHANTED_LINK = "/v1/auth/enchantedlink/signup-in";
public static final String VERIFY_ENCHANTED_LINK = "/v1/auth/enchantedlink/verify";
public static final String ENCHANTED_LINK_SESSION = "/v1/auth/enchantedlink/pending-session";
public static final String UPDATE_EMAIL_ENCHANTED_LINK = "/v1/auth/enchantedlink/update/email";

// TOTP
public static final String SIGN_UP_TOTP_LINK = "/auth/totp/signup";
public static final String UPDATE_USER_TOTP_LINK = "/auth/totp/update";
public static final String VERIFY_TOTP_LINK = "/auth/totp/verify";
public static final String SIGN_UP_TOTP_LINK = "/v1/auth/totp/signup";
public static final String UPDATE_USER_TOTP_LINK = "/v1/auth/totp/update";
public static final String VERIFY_TOTP_LINK = "/v1/auth/totp/verify";

// OAuth
public static final String COMPOSE_OAUTH_LINK = "/auth/oauth/authorize";
public static final String EXCHANGE_OAUTH_LINK = "/auth/oauth/exchange";
public static final String COMPOSE_OAUTH_LINK = "/v1/auth/oauth/authorize";
public static final String EXCHANGE_OAUTH_LINK = "/v1/auth/oauth/exchange";

// SAML
public static final String COMPOSE_SAML_START_LINK = "/auth/saml/authorize";
public static final String EXCHANGE_SAML_LINK = "/auth/saml/exchange";
public static final String COMPOSE_SAML_START_LINK = "/v1/auth/saml/authorize";
public static final String EXCHANGE_SAML_LINK = "/v1/auth/saml/exchange";

// Password
public static final String SIGN_UP_PASSWORD_LINK = "/auth/password/signup";
public static final String SIGN_IN_PASSWORD_LINK = "/auth/password/signin";
public static final String SEND_RESET_PASSWORD_LINK = "/auth/password/reset";
public static final String UPDATE_USER_PASSWORD_LINK = "/auth/password/update";
public static final String REPLACE_USER_PASSWORD_LINK = "/auth/password/replace";
public static final String PASSWORD_POLICY_LINK = "/auth/password/policy";

public static final String GET_KEYS_LINK = "/keys";
public static final String REFRESH_TOKEN_LINK = "/auth/refresh";
public static final String EXCHANGE_ACCESS_KEY_LINK = "/auth/accesskey/exchange";
public static final String SIGN_UP_PASSWORD_LINK = "/v1/auth/password/signup";
public static final String SIGN_IN_PASSWORD_LINK = "/v1/auth/password/signin";
public static final String SEND_RESET_PASSWORD_LINK = "/v1/auth/password/reset";
public static final String UPDATE_USER_PASSWORD_LINK = "/v1/auth/password/update";
public static final String REPLACE_USER_PASSWORD_LINK = "/v1/auth/password/replace";
public static final String PASSWORD_POLICY_LINK = "/v1/auth/password/policy";

public static final String GET_KEYS_LINK = "/v2/keys";
public static final String REFRESH_TOKEN_LINK = "/v1/auth/refresh";
public static final String EXCHANGE_ACCESS_KEY_LINK = "/v1/auth/accesskey/exchange";
}

@UtilityClass
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/descope/model/jwt/SigningKey.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.descope.model.jwt;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -9,6 +10,7 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@SuppressWarnings("checkstyle:MemberName")
public class SigningKey {
private String alg;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.descope.model.jwt.response;

import com.descope.model.jwt.SigningKey;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class SigningKeysResponse {
private List<SigningKey> keys;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.descope.model.user.request;

import java.net.URI;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -10,7 +9,8 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
@SuppressWarnings("checkstyle:MemberName")
public class EnchantedLinkTestUserRequest {
private TestUserRequest testUserRequest;
private URI uri;
private String loginId;
private String URI;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.descope.model.user.request;

import com.descope.enums.DeliveryMethod;
import java.net.URI;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -11,8 +10,9 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
@SuppressWarnings("checkstyle:MemberName")
public class MagicLinkTestUserRequest {
private TestUserRequest testUserRequest;
private String loginId;
private DeliveryMethod deliveryMethod;
private URI uri;
private String URI;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
@NoArgsConstructor
@AllArgsConstructor
public class OTPTestUserRequest {
private TestUserRequest testUserRequest;
private String loginId;
private DeliveryMethod deliveryMethod;
}
14 changes: 0 additions & 14 deletions src/main/java/com/descope/model/user/request/TestUserRequest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.descope.model.user.response;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class EnchantedLinkTestUserResponse {
private String pendingRef;
private String link;
private String loginId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.descope.model.user.response;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class MagicLinkTestUserResponse {
private String link;
private String loginId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.descope.model.user.response;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class OTPTestUserResponse {
private String code;
private String loginId;
}
20 changes: 20 additions & 0 deletions src/main/java/com/descope/proxy/impl/AbstractProxyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.descope.exception.ErrorCode;
import com.descope.exception.RateLimitExceededException;
import com.descope.exception.ServerCommonException;
import com.descope.model.client.SdkInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -27,6 +28,7 @@ abstract class AbstractProxyImpl {

private String authHeaderKey;
private Supplier<String> authHeaderSupplier; // supplies value of AUTHORIZATION header
private SdkInfo sdkInfo;

@SneakyThrows
private static <B> BodyPublisher getBodyPublisher(B body) {
Expand All @@ -45,6 +47,10 @@ protected void setAuthHeader(String authHeaderKey, Supplier<String> authHeaderSu
}
}

protected void setSdkInfo(SdkInfo sdkInfo) {
this.sdkInfo = sdkInfo;
}

@SneakyThrows
<B, R> R exchange(URI uri, String method, B body, Class<R> returnClz) {
Builder httpRequestBuilder = HttpRequest.newBuilder().uri(uri);
Expand All @@ -68,6 +74,20 @@ private void addHeaders(Builder httpRequestBuilder) {
String authHeaderVal = authHeaderSupplier.get();
httpRequestBuilder.header(authHeaderKey, authHeaderVal);
}
if (sdkInfo != null) {
if (StringUtils.isNotBlank(sdkInfo.getJavaVersion())) {
httpRequestBuilder.header("x-descope-sdk-java-version", sdkInfo.getJavaVersion());
}
if (StringUtils.isNotBlank(sdkInfo.getName())) {
httpRequestBuilder.header("x-descope-sdk-name", sdkInfo.getName());
}
if (StringUtils.isNotBlank(sdkInfo.getVersion())) {
httpRequestBuilder.header("x-descope-sdk-version", sdkInfo.getVersion());
}
if (StringUtils.isNotBlank(sdkInfo.getSha())) {
httpRequestBuilder.header("x-descope-sdk-sha", sdkInfo.getSha());
}
}
}

protected <B, R> R post(URI uri, B body, Class<R> returnClz) {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/descope/proxy/impl/ApiProxyBuilder.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.descope.proxy.impl;

import com.descope.model.client.SdkInfo;
import com.descope.proxy.ApiProxy;
import java.util.function.Supplier;
import lombok.experimental.UtilityClass;

@UtilityClass
public class ApiProxyBuilder {

public static ApiProxy buildProxy() {
return new ApiProxyImpl();
public static ApiProxy buildProxy(SdkInfo sdkInfo) {
return new ApiProxyImpl(sdkInfo);
}

public static ApiProxy buildProxy(Supplier<String> authHeaderSupplier) {
return new ApiProxyImpl(authHeaderSupplier);
public static ApiProxy buildProxy(Supplier<String> authHeaderSupplier, SdkInfo sdkInfo) {
return new ApiProxyImpl(authHeaderSupplier, sdkInfo);
}
}
8 changes: 6 additions & 2 deletions src/main/java/com/descope/proxy/impl/ApiProxyImpl.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.descope.proxy.impl;

import com.descope.model.client.SdkInfo;
import com.descope.proxy.ApiProxy;
import java.net.URI;
import java.util.function.Supplier;

class ApiProxyImpl extends AbstractProxyImpl implements ApiProxy {

public ApiProxyImpl() {}
public ApiProxyImpl(SdkInfo sdkInfo) {
setSdkInfo(sdkInfo);
}

public ApiProxyImpl(Supplier<String> authHeaderSupplier) {
public ApiProxyImpl(Supplier<String> authHeaderSupplier, SdkInfo sdkInfo) {
setAuthHeader("Authorization", authHeaderSupplier);
setSdkInfo(sdkInfo);
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/descope/sdk/auth/PasswordService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public interface PasswordService {

void sendPasswordReset(String loginId, String redirectURL) throws DescopeException;

void updateUserPassword(String loginId, String newPassword) throws DescopeException;
void updateUserPassword(String loginId, String newPassword, String refreshToken)
throws DescopeException;

void replaceUserPassword(String loginId, String oldPassword, String newPassword)
throws DescopeException;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/descope/sdk/auth/impl/AuthenticationsBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ abstract class AuthenticationsBase extends SdkServicesBase implements Authentica
ApiProxy getApiProxy() {
String projectId = authParams.getProjectId();
if (StringUtils.isNotBlank(projectId)) {
return ApiProxyBuilder.buildProxy(() -> "Bearer " + projectId);
return ApiProxyBuilder.buildProxy(() -> "Bearer " + projectId, client.getSdkInfo());
}
return ApiProxyBuilder.buildProxy();
return ApiProxyBuilder.buildProxy(client.getSdkInfo());
}

ApiProxy getApiProxy(String refreshToken) {
String projectId = authParams.getProjectId();
if (StringUtils.isBlank(refreshToken) || StringUtils.isNotBlank(projectId)) {
if (StringUtils.isBlank(refreshToken) || StringUtils.isBlank(projectId)) {
return getApiProxy();
}

String token = String.format("Bearer %s:%s", projectId, refreshToken);
return ApiProxyBuilder.buildProxy(() -> token);
return ApiProxyBuilder.buildProxy(() -> token, client.getSdkInfo());
}

@SneakyThrows
Expand All @@ -82,7 +82,7 @@ Key requestKeys() {
return provider.getProvidedKey();
}

var key = KeyProvider.getKey(authParams.getProjectId(), client.getUri());
var key = KeyProvider.getKey(authParams.getProjectId(), client.getUri(), client.getSdkInfo());
provider.setProvidedKey(key);
return key;
}
Expand Down
Loading