Skip to content

Commit

Permalink
Add refresh token to TOTP update user (#120)
Browse files Browse the repository at this point in the history
* Add refresh toekn to TOTP update user

* Bump version
  • Loading branch information
orius123 authored Jun 5, 2024
1 parent 4735947 commit 0837681
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/management-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<dependency>
<groupId>com.descope</groupId>
<artifactId>java-sdk</artifactId>
<version>1.0.24</version>
<version>1.0.25</version>
</dependency>
<dependency>
<groupId>info.picocli</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.descope</groupId>
<artifactId>java-sdk</artifactId>
<modelVersion>4.0.0</modelVersion>
<version>1.0.24</version>
<version>1.0.25</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>Java library used to integrate with Descope.</description>
<url>https://github.com/descope/descope-java</url>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/descope/sdk/auth/TOTPService.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,16 @@ AuthenticationInfo signInCode(
*/
TOTPResponse updateUser(String loginId)
throws DescopeException;


/**
* Set a seed to an existing user, so the user can use an authenticator app.
*
* @param loginId - User login ID
* @param refreshToken - Refresh Token
* @return TOTPResponse
* @throws DescopeException - error upon failure
*/
TOTPResponse updateUser(String loginId, String refreshToken)
throws DescopeException;
}
12 changes: 11 additions & 1 deletion src/main/java/com/descope/sdk/auth/impl/TOTPServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,23 @@ public AuthenticationInfo signInCode(String loginId, String code, LoginOptions l

@Override
public TOTPResponse updateUser(String loginId) throws DescopeException {
return updateUser(loginId, null);
}

@Override
public TOTPResponse updateUser(String loginId, String refreshToken) throws DescopeException {
if (StringUtils.isBlank(loginId)) {
throw ServerCommonException.invalidArgument("loginId");
}

URI totpUpdateUser = composeUpdateTOTPURL();
TotpSignUpRequestBody signUpRequest = TotpSignUpRequestBody.builder().loginId(loginId).build();
ApiProxy apiProxy = getApiProxy();
ApiProxy apiProxy;
if (StringUtils.isBlank(refreshToken)) {
apiProxy = getApiProxy();
} else {
apiProxy = getApiProxy(refreshToken);
}
return apiProxy.post(totpUpdateUser, signUpRequest, TOTPResponse.class);
}

Expand Down

0 comments on commit 0837681

Please sign in to comment.