Skip to content

Commit 1952d9a

Browse files
authored
Added token management for outbound apps (#155)
* Added token management for outbound apps * style fixes * fix test * slight rename * slight rename II * slight rename III
1 parent a6ff3cf commit 1952d9a

13 files changed

+331
-2
lines changed

src/main/java/com/descope/literals/Routes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,10 @@ public static class ManagementEndPoints {
217217

218218
// Password settings
219219
public static final String MANAGEMENT_PASSWORD_SETTINGS = "/v1/mgmt/password/settings";
220+
221+
// Outbound
222+
public static final String MANAGEMENT_FETCH_OUTBOUND_APP_USER_TOKEN = "/v1/mgmt/outbound/app/user/token";
223+
public static final String MANAGEMENT_DELETE_OUTBOUND_APP_USER_TOKEN_BY_ID = "/v1/mgmt/outbound/token";
224+
public static final String MANAGEMENT_DELETE_OUTBOUND_APP_USER_TOKENS = "/v1/mgmt/outbound/tokens";
220225
}
221226
}

src/main/java/com/descope/model/mgmt/ManagementServices.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.descope.sdk.mgmt.FlowService;
77
import com.descope.sdk.mgmt.GroupService;
88
import com.descope.sdk.mgmt.JwtService;
9+
import com.descope.sdk.mgmt.OutboundAppsService;
910
import com.descope.sdk.mgmt.PasswordSettingsService;
1011
import com.descope.sdk.mgmt.PermissionService;
1112
import com.descope.sdk.mgmt.ProjectService;
@@ -34,4 +35,5 @@ public class ManagementServices {
3435
AuthzService authzService;
3536
ProjectService projectService;
3637
PasswordSettingsService passwordSettingsService;
38+
OutboundAppsService outboundAppsService;
3739
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.descope.model.outbound;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@Data
9+
@Builder
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
public class DeleteOutboundAppUserTokensRequest {
13+
private String appId;
14+
private String userId;
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.descope.model.outbound;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@Data
9+
@Builder
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
public class FetchOutboundAppTokenOptions {
13+
private Boolean withRefreshToken;
14+
private Boolean forceRefresh;
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.descope.model.outbound;
2+
3+
import java.util.List;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
@Data
10+
@Builder
11+
@NoArgsConstructor
12+
@AllArgsConstructor
13+
public class FetchOutboundAppUserTokenRequest {
14+
private String appId;
15+
private String userId;
16+
private List<String> scopes;
17+
private FetchOutboundAppTokenOptions options;
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.descope.model.outbound;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@Data
9+
@Builder
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
public class FetchOutboundAppUserTokenResponse {
13+
private OutboundAppToken token;
14+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.descope.model.outbound;
2+
3+
import com.descope.utils.InstantToMillisSerializer;
4+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
5+
import java.time.Instant;
6+
import java.util.List;
7+
import lombok.AllArgsConstructor;
8+
import lombok.Builder;
9+
import lombok.Data;
10+
import lombok.NoArgsConstructor;
11+
12+
@Data
13+
@Builder
14+
@NoArgsConstructor
15+
@AllArgsConstructor
16+
public class OutboundAppToken {
17+
private String id;
18+
private String appId;
19+
private String userId;
20+
private String tokenSub;
21+
private String accessToken;
22+
private String accessTokenType;
23+
@JsonSerialize(using = InstantToMillisSerializer.class)
24+
private Instant accessTokenExpiry;
25+
private boolean hasRefreshToken;
26+
private String refreshToken;
27+
@JsonSerialize(using = InstantToMillisSerializer.class)
28+
private Instant lastRefreshTime;
29+
private String lastRefreshError;
30+
private List<String> scopes;
31+
}

src/main/java/com/descope/model/user/request/UserSearchRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class UserSearchRequest {
2929
List<String> emails;
3030
List<String> phones;
3131
List<String> loginIds;
32+
List<String> userIds;
3233
List<String> ssoAppIds;
3334
/** Retrieve only users created after the given time. */
3435
@JsonSerialize(using = InstantToMillisSerializer.class)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.descope.sdk.mgmt;
2+
3+
import com.descope.exception.DescopeException;
4+
import com.descope.model.outbound.DeleteOutboundAppUserTokensRequest;
5+
import com.descope.model.outbound.FetchOutboundAppUserTokenRequest;
6+
import com.descope.model.outbound.FetchOutboundAppUserTokenResponse;
7+
8+
/** Provides functions for managing outbound application tokens for a user in a project. */
9+
public interface OutboundAppsService {
10+
11+
/**
12+
* Fetch the requested token (if exists) for the given user and outbound application.
13+
*
14+
* @param request The token details including the requested scopes
15+
* @return The requested token
16+
* @throws DescopeException in case of errors
17+
*/
18+
FetchOutboundAppUserTokenResponse fetchOutboundAppUserToken(FetchOutboundAppUserTokenRequest request)
19+
throws DescopeException;
20+
21+
/**
22+
* Delete the outbound application token for the given ID.
23+
*
24+
* @param id required token ID
25+
* @throws DescopeException in case of errors
26+
*/
27+
void deleteOutboundAppTokenById(String id) throws DescopeException;
28+
29+
/**
30+
* Delete all outbound application tokens for the given user.
31+
*
32+
* @param request required request containing user ID and app ID
33+
* @throws DescopeException in case of errors
34+
*/
35+
void deleteOutboundAppUserTokens(DeleteOutboundAppUserTokensRequest request) throws DescopeException;
36+
}

src/main/java/com/descope/sdk/mgmt/impl/ManagementServiceBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static ManagementServices buildServices(Client client) {
2222
.projectService(new ProjectServiceImpl(client))
2323
.passwordSettingsService(new PasswordSettingsServiceImpl(client))
2424
.ssoApplicationService(new SsoApplicationServiceImpl(client))
25+
.outboundAppsService(new OutboundAppsServiceImpl(client))
2526
.build();
2627
}
2728
}

0 commit comments

Comments
 (0)