diff --git a/src/main/java/com/auth0/client/mgmt/ManagementAPI.java b/src/main/java/com/auth0/client/mgmt/ManagementAPI.java index cf7ec088..acffaeb3 100644 --- a/src/main/java/com/auth0/client/mgmt/ManagementAPI.java +++ b/src/main/java/com/auth0/client/mgmt/ManagementAPI.java @@ -364,6 +364,22 @@ public KeysEntity keys() { return new KeysEntity(client, baseUrl, tokenProvider); } + /** + * Getter for the RefreshTokens Entity + * @return the RefreshTokens Entity + */ + public RefreshTokensEntity refreshTokens() { + return new RefreshTokensEntity(client, baseUrl, tokenProvider); + } + + /** + * Getter for the Sessions Entity + * @return the Sessions Entity + */ + public SessionsEntity sessions() { + return new SessionsEntity(client, baseUrl, tokenProvider); + } + /** * Builder for {@link ManagementAPI} API client instances. */ diff --git a/src/main/java/com/auth0/client/mgmt/RefreshTokensEntity.java b/src/main/java/com/auth0/client/mgmt/RefreshTokensEntity.java new file mode 100644 index 00000000..6911aef2 --- /dev/null +++ b/src/main/java/com/auth0/client/mgmt/RefreshTokensEntity.java @@ -0,0 +1,66 @@ +package com.auth0.client.mgmt; + +import com.auth0.json.mgmt.refreshtokens.RefreshToken; +import com.auth0.net.BaseRequest; +import com.auth0.net.Request; +import com.auth0.net.VoidRequest; +import com.auth0.net.client.Auth0HttpClient; +import com.auth0.net.client.HttpMethod; +import com.auth0.utils.Asserts; +import com.fasterxml.jackson.core.type.TypeReference; +import okhttp3.HttpUrl; + +/** + * Class that provides an implementation of the Refresh Tokens methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Refresh_Tokens + *

+ * This class is not thread-safe. + * @see ManagementAPI + */ +@SuppressWarnings("WeakerAccess") +public class RefreshTokensEntity extends BaseManagementEntity{ + + RefreshTokensEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) { + super(client, baseUrl, tokenProvider); + } + + /** + * Request the refresh token for a given refresh token ID. + * A token with scope {@code read:refresh_tokens} is needed. + * See https://auth0.com/docs/api/management/v2/refresh-tokens/get-refresh-token + * @param refreshTokenId the refresh token ID. + * @return a Request to execute. + */ + public Request get(String refreshTokenId){ + Asserts.assertNotNull(refreshTokenId, "refresh token ID"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/refresh-tokens") + .addPathSegment(refreshTokenId) + .build() + .toString(); + + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { + }); + } + + /** + * Delete the refresh token for a given refresh token ID. + * * A token with scope {@code delete:refresh_tokens} is needed. + * See https://auth0.com/docs/api/management/v2/refresh-tokens/delete-refresh-token + * @param refreshTokenId the refresh token ID. + * @return a Request to execute. + */ + public Request delete(String refreshTokenId){ + Asserts.assertNotNull(refreshTokenId, "refresh token ID"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/refresh-tokens") + .addPathSegment(refreshTokenId) + .build() + .toString(); + + return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE); + } +} diff --git a/src/main/java/com/auth0/client/mgmt/SessionsEntity.java b/src/main/java/com/auth0/client/mgmt/SessionsEntity.java new file mode 100644 index 00000000..6ed853ee --- /dev/null +++ b/src/main/java/com/auth0/client/mgmt/SessionsEntity.java @@ -0,0 +1,67 @@ +package com.auth0.client.mgmt; + +import com.auth0.json.mgmt.sessions.Session; +import com.auth0.net.BaseRequest; +import com.auth0.net.Request; +import com.auth0.net.VoidRequest; +import com.auth0.net.client.Auth0HttpClient; +import com.auth0.net.client.HttpMethod; +import com.auth0.utils.Asserts; +import com.fasterxml.jackson.core.type.TypeReference; +import okhttp3.HttpUrl; + + +/** + * Class that provides an implementation of the Sessions methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Sessions + *

+ * This class is not thread-safe. + * @see ManagementAPI + */ +@SuppressWarnings("WeakerAccess") +public class SessionsEntity extends BaseManagementEntity{ + + SessionsEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) { + super(client, baseUrl, tokenProvider); + } + + /** + * Request the session for a given session ID. + * A token with scope {@code read:sessions} is needed. + * See https://auth0.com/docs/api/management/v2/sessions/get-session + * @param sessionId the session ID. + * @return a Request to execute. + */ + public Request get(String sessionId){ + Asserts.assertNotNull(sessionId, "session ID"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/sessions") + .addPathSegment(sessionId) + .build() + .toString(); + + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { + }); + } + + /** + * Delete the session for a given session ID. + * A token with scope {@code delete:sessions} is needed. + * See https://auth0.com/docs/api/management/v2/sessions/delete-session + * @param sessionId the session ID. + * @return a Request to execute. + */ + public Request delete(String sessionId){ + Asserts.assertNotNull(sessionId, "session ID"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/sessions") + .addPathSegment(sessionId) + .build() + .toString(); + + return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE); + } +} diff --git a/src/main/java/com/auth0/client/mgmt/UsersEntity.java b/src/main/java/com/auth0/client/mgmt/UsersEntity.java index 6d06a3b6..ac3e3548 100644 --- a/src/main/java/com/auth0/client/mgmt/UsersEntity.java +++ b/src/main/java/com/auth0/client/mgmt/UsersEntity.java @@ -13,6 +13,8 @@ import com.auth0.json.mgmt.users.RecoveryCode; import com.auth0.json.mgmt.users.User; import com.auth0.json.mgmt.users.UsersPage; +import com.auth0.json.mgmt.refreshtokens.RefreshTokensPage; +import com.auth0.json.mgmt.sessions.SessionsPage; import com.auth0.net.EmptyBodyRequest; import com.auth0.net.BaseRequest; import com.auth0.net.Request; @@ -787,6 +789,103 @@ public Request updateAuthenticationMethodById(String userI return request; } + /** + * Get refresh tokens for a user + * A token with {@code read:refresh_tokens} is needed. + * See https://auth0.com/docs/api/management/v2/users/get-refresh-tokens-for-user + * + * @param userId the role id + * @param filter an optional pagination filter + * @return a Request to execute + */ + public Request listRefreshTokens(String userId, PageFilter filter) { + Asserts.assertNotNull(userId, "user ID"); + HttpUrl.Builder builder = baseUrl + .newBuilder() + .addPathSegments("api/v2/users") + .addPathSegment(userId) + .addPathSegment("refresh-tokens"); + if (filter != null) { + for (Map.Entry e : filter.getAsMap().entrySet()) { + builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue())); + } + } + String url = builder.build().toString(); + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { + }); + } + + /** + * Delete all refresh tokens for a user. + * A token with scope {@code delete:refresh_tokens} is needed. + * See https://auth0.com/docs/api/management/v2/users/delete-refresh-tokens-for-user + * + * @param userId the user to delete the refresh tokens for + * @return a Request to execute. + */ + public Request deleteRefreshTokens(String userId) { + Asserts.assertNotNull(userId, "user ID"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/users") + .addPathSegment(userId) + .addPathSegment("refresh-tokens") + .build() + .toString(); + + return new VoidRequest(this.client, tokenProvider, url, HttpMethod.DELETE); + } + + + /** + * Get sessions for user + * A token with {@code read:sessions} is needed. + * See https://auth0.com/docs/api/management/v2/users/get-sessions-for-user + * + * @param userId the role id + * @param filter an optional pagination filter + * @return a Request to execute + */ + public Request listSessions(String userId, PageFilter filter) { + Asserts.assertNotNull(userId, "user ID"); + HttpUrl.Builder builder = baseUrl + .newBuilder() + .addPathSegments("api/v2/users") + .addPathSegment(userId) + .addPathSegment("sessions"); + if (filter != null) { + for (Map.Entry e : filter.getAsMap().entrySet()) { + builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue())); + } + } + String url = builder.build().toString(); + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { + }); + } + + /** + * Delete sessions for user + * A token with scope {@code delete:sessions} is needed. + * See https://auth0.com/docs/api/management/v2/users/delete-sessions-for-user + * + * @param userId the user to delete the sessions for + * @return a Request to execute. + */ + public Request deleteSessions(String userId) { + Asserts.assertNotNull(userId, "user ID"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/users") + .addPathSegment(userId) + .addPathSegment("sessions") + .build() + .toString(); + + return new VoidRequest(this.client, tokenProvider, url, HttpMethod.DELETE); + } + private static void encodeAndAddQueryParam(HttpUrl.Builder builder, BaseFilter filter) { if (filter != null) { for (Map.Entry e : filter.getAsMap().entrySet()) { diff --git a/src/main/java/com/auth0/json/mgmt/refreshtokens/Device.java b/src/main/java/com/auth0/json/mgmt/refreshtokens/Device.java new file mode 100644 index 00000000..e83e6133 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/refreshtokens/Device.java @@ -0,0 +1,64 @@ +package com.auth0.json.mgmt.refreshtokens; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Device { + @JsonProperty("initial_ip") + private String initialIp; + @JsonProperty("initial_asn") + private String initialAsn; + @JsonProperty("initial_user_agent") + private String initialUserAgent; + @JsonProperty("last_ip") + private String lastIp; + @JsonProperty("last_asn") + private String lastAsn; + @JsonProperty("last_user_agent") + private String lastUserAgent; + + /** + * @return First IP address associated with this session + */ + public String getInitialIp() { + return initialIp; + } + + /** + * @return First autonomous system number associated with this session + */ + public String getInitialAsn() { + return initialAsn; + } + + /** + * @return First user agent associated with this session + */ + public String getInitialUserAgent() { + return initialUserAgent; + } + + /** + * @return Last IP address from which this user logged in + */ + public String getLastIp() { + return lastIp; + } + + /** + * @return Last autonomous system number from which this user logged in + */ + public String getLastAsn() { + return lastAsn; + } + + /** + * @return Last user agent of the device from which this user logged in + */ + public String getLastUserAgent() { + return lastUserAgent; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/refreshtokens/RefreshToken.java b/src/main/java/com/auth0/json/mgmt/refreshtokens/RefreshToken.java new file mode 100644 index 00000000..2efc36b0 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/refreshtokens/RefreshToken.java @@ -0,0 +1,115 @@ +package com.auth0.json.mgmt.refreshtokens; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Date; +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class RefreshToken { + @JsonProperty("id") + private String id; + @JsonProperty("user_id") + private String userId; + @JsonProperty("created_at") + private Date createdAt; + @JsonProperty("idle_expires_at") + private Date idleExpiresAt; + @JsonProperty("expires_at") + private Date expiresAt; + @JsonProperty("device") + private Device device; + @JsonProperty("client_id") + private String clientId; + @JsonProperty("session_id") + private String sessionId; + @JsonProperty("rotating") + private Boolean rotating; + @JsonProperty("resource_servers") + private List resourceServers; + @JsonProperty("last_exchanged_at") + private Date lastExchangedAt; + + /** + * @return The ID of the refresh token + */ + public String getId() { + return id; + } + + /** + * @return ID of the user which can be used when interacting with other APIs. + */ + public String getUserId() { + return userId; + } + + /** + * @return The date and time when the refresh token was created + */ + public Date getCreatedAt() { + return createdAt; + } + + /** + * + * @return The date and time when the refresh token will expire if idle + */ + public Date getIdleExpiresAt() { + return idleExpiresAt; + } + + /** + * + * @return The date and time when the refresh token will expire + */ + public Date getExpiresAt() { + return expiresAt; + } + + /** + * @return Device information + */ + public Device getDevice() { + return device; + } + + /** + * @return ID of the client application granted with this refresh token + */ + public String getClientId() { + return clientId; + } + + /** + * + * @return ID of the authenticated session used to obtain this refresh-token + */ + public String getSessionId() { + return sessionId; + } + + /** + * @return True if the token is a rotating refresh token + */ + public Boolean isRotating() { + return rotating; + } + + /** + * @return A list of the resource server IDs associated to this refresh-token and their granted scopes + */ + public List getResourceServers() { + return resourceServers; + } + + /** + * @return The date and time when the refresh token was last exchanged + */ + public Date getLastExchangedAt() { + return lastExchangedAt; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/refreshtokens/RefreshTokensPage.java b/src/main/java/com/auth0/json/mgmt/refreshtokens/RefreshTokensPage.java new file mode 100644 index 00000000..9aea796c --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/refreshtokens/RefreshTokensPage.java @@ -0,0 +1,44 @@ +package com.auth0.json.mgmt.refreshtokens; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/** + * Class that represents a page of Refresh Tokens. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class RefreshTokensPage { + @JsonProperty("total") + private Integer total; + + @JsonProperty("next") + private String next; + + @JsonProperty("tokens") + private List tokens; + + /** + * @return the total number of refresh tokens. This is only present when `include_totals` is passed as a query parameter. + */ + public Integer getTotal() { + return total; + } + + /** + * @return the token ID from which to start selection for a new page + */ + public String getNext() { + return next; + } + + /** + * @return the list of Tokens + */ + public List getTokens() { + return tokens; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/refreshtokens/ResourceServer.java b/src/main/java/com/auth0/json/mgmt/refreshtokens/ResourceServer.java new file mode 100644 index 00000000..748b2e1d --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/refreshtokens/ResourceServer.java @@ -0,0 +1,30 @@ +package com.auth0.json.mgmt.refreshtokens; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ResourceServer { + @JsonProperty("audience") + private String audience; + @JsonProperty("scopes") + private List scopes; + + /** + * @return Resource server ID + */ + public String getAudience() { + return audience; + } + + /** + * @return List of scopes for the refresh token + */ + public List getScopes() { + return scopes; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/sessions/Authentication.java b/src/main/java/com/auth0/json/mgmt/sessions/Authentication.java new file mode 100644 index 00000000..177c1469 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/sessions/Authentication.java @@ -0,0 +1,21 @@ +package com.auth0.json.mgmt.sessions; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Authentication { + @JsonProperty("methods") + private List methods; + + /** + * @return Contains the authentication methods a user has completed during their session + */ + public List getMethods() { + return methods; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/sessions/AuthenticationMethod.java b/src/main/java/com/auth0/json/mgmt/sessions/AuthenticationMethod.java new file mode 100644 index 00000000..012a29d6 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/sessions/AuthenticationMethod.java @@ -0,0 +1,39 @@ +package com.auth0.json.mgmt.sessions; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Date; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class AuthenticationMethod { + @JsonProperty("name") + private String name; + @JsonProperty("timestamp") + private Date timestamp; + @JsonProperty("type") + private String type; + + /** + * @return One of: "federated", "passkey", "pwd", "sms", "email", "mfa", "mock" or a custom method denoted by a URL + */ + public String getName() { + return name; + } + + /** + * @return Timestamp of when the signal was received + */ + public Date getTimestamp() { + return timestamp; + } + + /** + * @return A specific MFA factor. Only present when "name" is set to "mfa" + */ + public String getType() { + return type; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/sessions/Client.java b/src/main/java/com/auth0/json/mgmt/sessions/Client.java new file mode 100644 index 00000000..7ac383e6 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/sessions/Client.java @@ -0,0 +1,19 @@ +package com.auth0.json.mgmt.sessions; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Client { + @JsonProperty("client_id") + private String clientId; + + /** + * @return ID of client for the session + */ + public String getClientId() { + return clientId; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/sessions/Device.java b/src/main/java/com/auth0/json/mgmt/sessions/Device.java new file mode 100644 index 00000000..cf3fe395 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/sessions/Device.java @@ -0,0 +1,64 @@ +package com.auth0.json.mgmt.sessions; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Device { + @JsonProperty("initial_user_agent") + private String initialUserAgent; + @JsonProperty("initial_ip") + private String initialIP; + @JsonProperty("initial_asn") + private String initialASN; + @JsonProperty("last_user_agent") + private String lastUserAgent; + @JsonProperty("last_ip") + private String lastIP; + @JsonProperty("last_asn") + private String lastASN; + + /** + * @return First user agent associated with this session + */ + public String getInitialUserAgent() { + return initialUserAgent; + } + + /** + * @return First IP address associated with this session + */ + public String getInitialIP() { + return initialIP; + } + + /** + * @return First autonomous system number associated with this session + */ + public String getInitialASN() { + return initialASN; + } + + /** + * @return Last user agent of the device from which this user logged in + */ + public String getLastUserAgent() { + return lastUserAgent; + } + + /** + * @return Last IP address from which this user logged in + */ + public String getLastIP() { + return lastIP; + } + + /** + * @return Last autonomous system number from which this user logged in + */ + public String getLastASN() { + return lastASN; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/sessions/Session.java b/src/main/java/com/auth0/json/mgmt/sessions/Session.java new file mode 100644 index 00000000..c231770e --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/sessions/Session.java @@ -0,0 +1,106 @@ +package com.auth0.json.mgmt.sessions; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Date; +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Session { + @JsonProperty("id") + private String id; + @JsonProperty("user_id") + private String userId; + @JsonProperty("created_at") + private Date createdAt; + @JsonProperty("updated_at") + private Date updatedAt; + @JsonProperty("authenticated_at") + private Date authenticatedAt; + @JsonProperty("idle_expires_at") + private Date idleExpiresAt; + @JsonProperty("expires_at") + private Date expiresAt; + @JsonProperty("last_interacted_at") + private Date lastInteractedAt; + @JsonProperty("device") + private Device device; + @JsonProperty("clients") + private List clients; + @JsonProperty("authentication") + private Authentication authentication; + + /** + * @return The ID of the session + */ + public String getId() { + return id; + } + + /** + * @return ID of the user which can be used when interacting with other APIs. + */ + public String getUserId() { + return userId; + } + + /** + * + * @return The date and time when the session was created + */ + public Date getCreatedAt() { + return createdAt; + } + + /** + * @return The date and time when the session was last updated + */ + public Date getUpdatedAt() { + return updatedAt; + } + + /** + * @return The date and time when the session was last authenticated + */ + public Date getAuthenticatedAt() { + return authenticatedAt; + } + + /** + * @return The date and time when the session will expire if idle + */ + public Date getIdleExpiresAt() { + return idleExpiresAt; + } + + /** + * @return The date and time when the session will expire + */ + public Date getExpiresAt() { + return expiresAt; + } + + /** + * @return Metadata related to the device used in the session + */ + public Device getDevice() { + return device; + } + + /** + * @return List of client details for the session + */ + public List getClients() { + return clients; + } + + /** + * @return Details about authentication signals obtained during the login flow + */ + public Authentication getAuthentication() { + return authentication; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/sessions/SessionsPage.java b/src/main/java/com/auth0/json/mgmt/sessions/SessionsPage.java new file mode 100644 index 00000000..10d58e9d --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/sessions/SessionsPage.java @@ -0,0 +1,44 @@ +package com.auth0.json.mgmt.sessions; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/** + * Class that represents a given Page of Sessions. Related to the {@link com.auth0.client.mgmt.UsersEntity} entity. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class SessionsPage { + @JsonProperty("total") + private Integer total; + + @JsonProperty("next") + private String next; + + @JsonProperty("sessions") + private List sessions; + + /** + * @return the total number of refresh tokens. This is only present when `include_totals` is passed as a query parameter. + */ + public Integer getTotal() { + return total; + } + + /** + * @return the token ID from which to start selection for a new page + */ + public String getNext() { + return next; + } + + /** + * @return the list of Sessions + */ + public List getSessions() { + return sessions; + } +} diff --git a/src/test/java/com/auth0/client/MockServer.java b/src/test/java/com/auth0/client/MockServer.java index 9df874b2..f8ee2189 100644 --- a/src/test/java/com/auth0/client/MockServer.java +++ b/src/test/java/com/auth0/client/MockServer.java @@ -78,6 +78,10 @@ public class MockServer { public static final String MGMT_USERS_PAGED_LIST = "src/test/resources/mgmt/users_paged_list.json"; public static final String MGMT_USER_PERMISSIONS_PAGED_LIST = "src/test/resources/mgmt/user_permissions_paged_list.json"; public static final String MGMT_USER_ROLES_PAGED_LIST = "src/test/resources/mgmt/user_roles_paged_list.json"; + public static final String MGMT_REFRESH_TOKEN = "src/test/resources/mgmt/refresh_token.json"; + public static final String MGMT_SESSION = "src/test/resources/mgmt/session.json"; + public static final String MGMT_USER_REFRESH_TOKENS = "src/test/resources/mgmt/user_refresh_tokens.json"; + public static final String MGMT_USER_SESSIONS = "src/test/resources/mgmt/user_sessions.json"; public static final String MGMT_USER = "src/test/resources/mgmt/user.json"; public static final String MGMT_RECOVERY_CODE = "src/test/resources/mgmt/recovery_code.json"; public static final String MGMT_IDENTITIES_LIST = "src/test/resources/mgmt/identities_list.json"; diff --git a/src/test/java/com/auth0/client/mgmt/RefreshTokensEntityTest.java b/src/test/java/com/auth0/client/mgmt/RefreshTokensEntityTest.java new file mode 100644 index 00000000..69ef2684 --- /dev/null +++ b/src/test/java/com/auth0/client/mgmt/RefreshTokensEntityTest.java @@ -0,0 +1,61 @@ +package com.auth0.client.mgmt; + +import com.auth0.json.mgmt.refreshtokens.RefreshToken; +import com.auth0.net.Request; +import com.auth0.net.client.HttpMethod; +import okhttp3.mockwebserver.RecordedRequest; +import org.junit.jupiter.api.Test; + +import static com.auth0.AssertsUtil.verifyThrows; +import static com.auth0.client.MockServer.MGMT_REFRESH_TOKEN; +import static com.auth0.client.RecordedRequestMatcher.hasHeader; +import static com.auth0.client.RecordedRequestMatcher.hasMethodAndPath; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +public class RefreshTokensEntityTest extends BaseMgmtEntityTest{ + + @Test + public void shouldThrowOnGetWithNullRefreshTokenId() { + verifyThrows(IllegalArgumentException.class, + () -> api.refreshTokens().get(null), + "'refresh token ID' cannot be null!"); + } + + @Test + public void shouldGetRefreshToken() throws Exception { + Request request = api.refreshTokens().get("refresh_token_ID"); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_REFRESH_TOKEN, 200); + RefreshToken response =request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/refresh-tokens/refresh_token_ID")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + assertThat(response, is(notNullValue())); + } + + @Test + public void shouldThrowOnDeleteWithNullRefreshTokenId() { + verifyThrows(IllegalArgumentException.class, + () -> api.refreshTokens().delete(null), + "'refresh token ID' cannot be null!"); + } + + @Test + public void shouldDeleteRefreshToken() throws Exception { + Request request = api.refreshTokens().delete("refresh_token_ID"); + assertThat(request, is(notNullValue())); + + server.noContentResponse(); + request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.DELETE, "/api/v2/refresh-tokens/refresh_token_ID")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + } +} diff --git a/src/test/java/com/auth0/client/mgmt/SessionsEntityTest.java b/src/test/java/com/auth0/client/mgmt/SessionsEntityTest.java new file mode 100644 index 00000000..a1e847ff --- /dev/null +++ b/src/test/java/com/auth0/client/mgmt/SessionsEntityTest.java @@ -0,0 +1,61 @@ +package com.auth0.client.mgmt; + +import com.auth0.json.mgmt.sessions.Session; +import com.auth0.net.Request; +import com.auth0.net.client.HttpMethod; +import okhttp3.mockwebserver.RecordedRequest; +import org.junit.jupiter.api.Test; + +import static com.auth0.AssertsUtil.verifyThrows; +import static com.auth0.client.MockServer.MGMT_SESSION; +import static com.auth0.client.RecordedRequestMatcher.hasHeader; +import static com.auth0.client.RecordedRequestMatcher.hasMethodAndPath; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +public class SessionsEntityTest extends BaseMgmtEntityTest{ + @Test + public void getSessionShouldThrowOnNullSessionId() { + verifyThrows(IllegalArgumentException.class, + () -> api.sessions().get(null), + "'session ID' cannot be null!"); + } + + @Test + public void shouldGetSession() throws Exception { + Request request = api.sessions().get("session_ID"); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_SESSION, 200); + Session response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/sessions/session_ID")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + assertThat(response, is(notNullValue())); + } + + @Test + public void deleteSessionShouldThrowOnNullSessionId() { + verifyThrows(IllegalArgumentException.class, + () -> api.sessions().delete(null), + "'session ID' cannot be null!"); + } + + @Test + public void shouldDeleteSession() throws Exception { + Request request = api.sessions().delete("session_ID"); + assertThat(request, is(notNullValue())); + + server.noContentResponse(); + request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.DELETE, "/api/v2/sessions/session_ID")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + } + +} diff --git a/src/test/java/com/auth0/client/mgmt/UsersEntityTest.java b/src/test/java/com/auth0/client/mgmt/UsersEntityTest.java index 61f519c9..59da2b86 100644 --- a/src/test/java/com/auth0/client/mgmt/UsersEntityTest.java +++ b/src/test/java/com/auth0/client/mgmt/UsersEntityTest.java @@ -17,6 +17,8 @@ import com.auth0.json.mgmt.users.UsersPage; import com.auth0.json.mgmt.users.authenticationmethods.AuthenticationMethod; import com.auth0.json.mgmt.users.authenticationmethods.AuthenticationMethodsPage; +import com.auth0.json.mgmt.refreshtokens.RefreshTokensPage; +import com.auth0.json.mgmt.sessions.SessionsPage; import com.auth0.net.Request; import com.auth0.net.client.HttpMethod; import okhttp3.mockwebserver.RecordedRequest; @@ -1348,4 +1350,158 @@ public void shouldInvalidateRememberedBrowsers() throws Exception { assertThat(recordedRequest, hasMethodAndPath(HttpMethod.POST, "/api/v2/users/userId/multifactor/actions/invalidate-remember-browser")); assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); } + + @Test + public void shouldListRefreshTokensWithoutFilter() throws Exception { + Request request = api.users().listRefreshTokens("1", null); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_USER_REFRESH_TOKENS, 200); + RefreshTokensPage response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/users/1/refresh-tokens")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + assertThat(response, is(notNullValue())); + assertThat(response.getTokens(), hasSize(2)); + } + + @Test + public void shouldListRefreshTokensWithPage() throws Exception { + PageFilter filter = new PageFilter().withFrom("tokenId2").withTake(5); + Request request = api.users().listRefreshTokens("1", filter); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_USER_REFRESH_TOKENS, 200); + RefreshTokensPage response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/users/1/refresh-tokens")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + assertThat(recordedRequest, hasQueryParameter("from", "tokenId2")); + assertThat(recordedRequest, hasQueryParameter("take", "5")); + + assertThat(response, is(notNullValue())); + assertThat(response.getTokens(), hasSize(2)); + } + + @Test + public void shouldListRefreshTokensWithTotal() throws Exception { + PageFilter filter = new PageFilter().withTotals(true); + Request request = api.users().listRefreshTokens("1", filter); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_USER_REFRESH_TOKENS, 200); + RefreshTokensPage response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/users/1/refresh-tokens")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + assertThat(recordedRequest, hasQueryParameter("include_totals", "true")); + + assertThat(response, is(notNullValue())); + assertThat(response.getTokens(), hasSize(2)); + assertThat(response.getTotal(), is(11)); + } + + @Test + public void shouldNotDeleteRefreshTokensWithNullUserId() { + verifyThrows(IllegalArgumentException.class, + () -> api.users().deleteRefreshTokens(null), + "'user ID' cannot be null!"); + } + + @Test + public void shouldDeleteRefreshTokens() throws Exception { + Request request = api.users().deleteRefreshTokens("1"); + assertThat(request, is(notNullValue())); + + server.noContentResponse(); + request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.DELETE, "/api/v2/users/1/refresh-tokens")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + } + + @Test + public void shouldListSessionsWithoutFilter() throws Exception { + Request request = api.users().listSessions("1", null); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_USER_SESSIONS, 200); + SessionsPage response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/users/1/sessions")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + assertThat(response, is(notNullValue())); + assertThat(response.getSessions(), hasSize(1)); + } + + @Test + public void shouldListSessionsWithPage() throws Exception { + PageFilter filter = new PageFilter().withFrom("sessionId3").withTake(9); + Request request = api.users().listSessions("1", filter); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_USER_SESSIONS, 200); + SessionsPage response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/users/1/sessions")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + assertThat(recordedRequest, hasQueryParameter("from", "sessionId3")); + assertThat(recordedRequest, hasQueryParameter("take", "9")); + + assertThat(response, is(notNullValue())); + assertThat(response.getSessions(), hasSize(1)); + } + + @Test + public void shouldListSessionsWithTotal() throws Exception { + PageFilter filter = new PageFilter().withTotals(true); + Request request = api.users().listSessions("1", filter); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_USER_SESSIONS, 200); + SessionsPage response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/users/1/sessions")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + assertThat(recordedRequest, hasQueryParameter("include_totals", "true")); + + assertThat(response, is(notNullValue())); + assertThat(response.getSessions(), hasSize(1)); + assertThat(response.getTotal(), is(9)); + } + + @Test + public void shouldNotDeleteSessionsWithNullUserId() { + verifyThrows(IllegalArgumentException.class, + () -> api.users().deleteRefreshTokens(null), + "'user ID' cannot be null!"); + } + + @Test + public void shouldDeleteSessions() throws Exception { + Request request = api.users().deleteSessions("1"); + assertThat(request, is(notNullValue())); + + server.noContentResponse(); + request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.DELETE, "/api/v2/users/1/sessions")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + } } diff --git a/src/test/java/com/auth0/json/mgmt/refreshtokens/RefreshTokenTest.java b/src/test/java/com/auth0/json/mgmt/refreshtokens/RefreshTokenTest.java new file mode 100644 index 00000000..35e7d700 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/refreshtokens/RefreshTokenTest.java @@ -0,0 +1,86 @@ +package com.auth0.json.mgmt.refreshtokens; + +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +public class RefreshTokenTest extends JsonTest { + + private static final String json = "{\n" + + " \"id\": \"tokenId1\",\n" + + " \"user_id\": \"userId1\",\n" + + " \"created_at\": \"2024-06-26T09:10:26.643Z\",\n" + + " \"idle_expires_at\": \"2024-06-26T09:10:27.131Z\",\n" + + " \"expires_at\": \"2024-07-03T09:10:26.643Z\",\n" + + " \"device\": {\n" + + " \"initial_asn\": \"1234\",\n" + + " \"initial_ip\": \"203.0.113.1\",\n" + + " \"initial_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\n" + + " \"last_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\n" + + " \"last_ip\": \"203.0.113.1\",\n" + + " \"last_asn\": \"1234\"\n" + + " },\n" + + " \"client_id\": \"clientId1\",\n" + + " \"session_id\": \"sessionId1\",\n" + + " \"rotating\": false,\n" + + " \"resource_servers\": [\n" + + " {\n" + + " \"audience\": \"https://api.example.com\",\n" + + " \"scopes\": [\n" + + " \"read:examples\",\n" + + " \"write:examples\"\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"last_exchanged_at\": \"2024-07-03T09:10:26.643Z\"\n" + + "}"; + + private static final String readOnlyJson = "{\n" + + " \"user_id\": \"userId1\",\n" + + " \"client_id\": \"clientId1\",\n" + + " \"session_id\": \"sessionId1\"\n" + + "}"; + + @Test + public void shouldDeserialize() throws Exception { + RefreshToken refreshToken = fromJSON(json, RefreshToken.class); + assertThat(refreshToken, is(notNullValue())); + + assertThat(refreshToken.getId(), is("tokenId1")); + assertThat(refreshToken.getUserId(), is("userId1")); + assertThat(refreshToken.getCreatedAt(), is(parseJSONDate("2024-06-26T09:10:26.643Z"))); + assertThat(refreshToken.getIdleExpiresAt(), is(parseJSONDate("2024-06-26T09:10:27.131Z"))); + assertThat(refreshToken.getExpiresAt(), is(parseJSONDate("2024-07-03T09:10:26.643Z"))); + + assertThat(refreshToken.getDevice(), is(notNullValue())); + assertThat(refreshToken.getDevice().getInitialAsn(), is("1234")); + assertThat(refreshToken.getDevice().getInitialIp(), is("203.0.113.1")); + assertThat(refreshToken.getDevice().getInitialUserAgent(), is("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36")); + assertThat(refreshToken.getDevice().getLastUserAgent(), is("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36")); + assertThat(refreshToken.getDevice().getLastIp(), is("203.0.113.1")); + assertThat(refreshToken.getDevice().getLastAsn(), is("1234")); + + assertThat(refreshToken.getClientId(), is("clientId1")); + assertThat(refreshToken.getSessionId(), is("sessionId1")); + assertThat(refreshToken.isRotating(), is(false)); + + assertThat(refreshToken.getResourceServers(), is(notNullValue())); + assertThat(refreshToken.getResourceServers().get(0).getAudience(), is("https://api.example.com")); + assertThat(refreshToken.getResourceServers().get(0).getScopes(), is(notNullValue())); + assertThat(refreshToken.getResourceServers().get(0).getScopes().get(0), is("read:examples")); + assertThat(refreshToken.getResourceServers().get(0).getScopes().get(1), is("write:examples")); + + assertThat(refreshToken.getLastExchangedAt(), is(parseJSONDate("2024-07-03T09:10:26.643Z"))); + } + + @Test + public void shouldIncludeReadOnlyValuesOnDeserialize() throws Exception { + RefreshToken refreshToken = fromJSON(readOnlyJson, RefreshToken.class); + assertThat(refreshToken, is(notNullValue())); + assertThat(refreshToken.getUserId(), is("userId1")); + assertThat(refreshToken.getClientId(), is("clientId1")); + assertThat(refreshToken.getSessionId(), is("sessionId1")); + } +} diff --git a/src/test/java/com/auth0/json/mgmt/refreshtokens/RefreshTokensPageTest.java b/src/test/java/com/auth0/json/mgmt/refreshtokens/RefreshTokensPageTest.java new file mode 100644 index 00000000..f86c7df7 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/refreshtokens/RefreshTokensPageTest.java @@ -0,0 +1,175 @@ +package com.auth0.json.mgmt.refreshtokens; + +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +public class RefreshTokensPageTest extends JsonTest { + private static final String json = "{\n" + + " \"tokens\": [\n" + + " {\n" + + " \"id\": \"tokenId1\",\n" + + " \"user_id\": \"userId1\",\n" + + " \"created_at\": \"2024-06-26T09:10:26.643Z\",\n" + + " \"updated_at\": \"2024-06-26T09:10:27.131Z\",\n" + + " \"expires_at\": \"2024-07-03T09:10:26.643Z\",\n" + + " \"device\": {\n" + + " \"initial_asn\": \"1234\",\n" + + " \"initial_ip\": \"203.0.113.1\",\n" + + " \"initial_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\n" + + " \"last_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\n" + + " \"last_ip\": \"203.0.113.1\",\n" + + " \"last_asn\": \"1234\"\n" + + " },\n" + + " \"client_id\": \"clientId1\",\n" + + " \"session_id\": \"sessionId1\",\n" + + " \"rotating\": false,\n" + + " \"resource_servers\": [\n" + + " {\n" + + " \"audience\": \"https://api.example.com\",\n" + + " \"scopes\": [\n" + + " \"read:examples\",\n" + + " \"write:examples\"\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"last_exchanged_at\": \"2024-07-03T09:10:26.643Z\"\n" + + " },\n" + + " {\n" + + " \"id\": \"tokenId2\",\n" + + " \"user_id\": \"userId1\",\n" + + " \"created_at\": \"2024-06-26T09:10:26.643Z\",\n" + + " \"updated_at\": \"2024-06-26T09:10:27.131Z\",\n" + + " \"expires_at\": \"2024-07-03T09:10:26.643Z\",\n" + + " \"device\": {\n" + + " \"initial_asn\": \"1234\",\n" + + " \"initial_ip\": \"203.0.113.1\",\n" + + " \"initial_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\n" + + " \"last_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\n" + + " \"last_ip\": \"203.0.113.1\",\n" + + " \"last_asn\": \"1234\"\n" + + " },\n" + + " \"client_id\": \"clientId2\",\n" + + " \"session_id\": \"sessionId2\",\n" + + " \"rotating\": true,\n" + + " \"resource_servers\": [\n" + + " {\n" + + " \"audience\": \"https://api.example.com\",\n" + + " \"scopes\": [\n" + + " \"read:examples\",\n" + + " \"write:examples\"\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"last_exchanged_at\": \"2024-07-03T09:10:26.643Z\"\n" + + " }\n" + + " ],\n" + + " \"next\": \"token1\"\n" + + "}"; + + private static final String jsonWithTotal = "{\n" + + " \"tokens\": [\n" + + " {\n" + + " \"id\": \"tokenId1\",\n" + + " \"user_id\": \"userId1\",\n" + + " \"created_at\": \"2024-06-26T09:10:26.643Z\",\n" + + " \"updated_at\": \"2024-06-26T09:10:27.131Z\",\n" + + " \"expires_at\": \"2024-07-03T09:10:26.643Z\",\n" + + " \"device\": {\n" + + " \"initial_asn\": \"1234\",\n" + + " \"initial_ip\": \"203.0.113.1\",\n" + + " \"initial_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\n" + + " \"last_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\n" + + " \"last_ip\": \"203.0.113.1\",\n" + + " \"last_asn\": \"1234\"\n" + + " },\n" + + " \"client_id\": \"clientId1\",\n" + + " \"session_id\": \"sessionId1\",\n" + + " \"rotating\": false,\n" + + " \"resource_servers\": [\n" + + " {\n" + + " \"audience\": \"https://api.example.com\",\n" + + " \"scopes\": [\n" + + " \"read:examples\",\n" + + " \"write:examples\"\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"last_exchanged_at\": \"2024-07-03T09:10:26.643Z\"\n" + + " },\n" + + " {\n" + + " \"id\": \"tokenId2\",\n" + + " \"user_id\": \"userId1\",\n" + + " \"created_at\": \"2024-06-26T09:10:26.643Z\",\n" + + " \"updated_at\": \"2024-06-26T09:10:27.131Z\",\n" + + " \"expires_at\": \"2024-07-03T09:10:26.643Z\",\n" + + " \"device\": {\n" + + " \"initial_asn\": \"1234\",\n" + + " \"initial_ip\": \"203.0.113.1\",\n" + + " \"initial_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\n" + + " \"last_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\n" + + " \"last_ip\": \"203.0.113.1\",\n" + + " \"last_asn\": \"1234\"\n" + + " },\n" + + " \"client_id\": \"clientId2\",\n" + + " \"session_id\": \"sessionId2\",\n" + + " \"rotating\": true,\n" + + " \"resource_servers\": [\n" + + " {\n" + + " \"audience\": \"https://api.example.com\",\n" + + " \"scopes\": [\n" + + " \"read:examples\",\n" + + " \"write:examples\"\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"last_exchanged_at\": \"2024-07-03T09:10:26.643Z\"\n" + + " }\n" + + " ],\n" + + " \"next\": \"token1\",\n" + + " \"total\": 11\n" + + "}"; + @Test + public void shouldDeserialize() throws Exception { + RefreshTokensPage page = fromJSON(json, RefreshTokensPage.class); + + assertThat(page.getTotal(), is(nullValue())); + assertThat(page.getNext(), is("token1")); + + assertThat(page.getTokens().size(), is(2)); + assertThat(page.getTokens().get(0).getId(), is("tokenId1")); + assertThat(page.getTokens().get(0).getUserId(), is("userId1")); + assertThat(page.getTokens().get(0).getCreatedAt(), is(parseJSONDate("2024-06-26T09:10:26.643Z"))); + assertThat(page.getTokens().get(0).getIdleExpiresAt(), is(nullValue())); + assertThat(page.getTokens().get(0).getExpiresAt(), is(parseJSONDate("2024-07-03T09:10:26.643Z"))); + + assertThat(page.getTokens().get(0).getDevice().getInitialIp(), is("203.0.113.1")); + assertThat(page.getTokens().get(0).getDevice().getInitialAsn(), is("1234")); + assertThat(page.getTokens().get(0).getDevice().getInitialUserAgent(), is("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36")); + assertThat(page.getTokens().get(0).getDevice().getLastIp(), is("203.0.113.1")); + assertThat(page.getTokens().get(0).getDevice().getLastAsn(), is("1234")); + assertThat(page.getTokens().get(0).getDevice().getLastUserAgent(), is("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36")); + + assertThat(page.getTokens().get(0).getClientId(), is("clientId1")); + assertThat(page.getTokens().get(0).getSessionId(), is("sessionId1")); + assertThat(page.getTokens().get(0).isRotating(), is(false)); + + assertThat(page.getTokens().get(0).getResourceServers().size(), is(1)); + assertThat(page.getTokens().get(0).getResourceServers().get(0).getAudience(), is("https://api.example.com")); + assertThat(page.getTokens().get(0).getResourceServers().get(0).getScopes().size(), is(2)); + assertThat(page.getTokens().get(0).getResourceServers().get(0).getScopes().get(0), is("read:examples")); + assertThat(page.getTokens().get(0).getResourceServers().get(0).getScopes().get(1), is("write:examples")); + + assertThat(page.getTokens().get(0).getLastExchangedAt(), is(parseJSONDate("2024-07-03T09:10:26.643Z"))); + } + + @Test + public void shouldDeserializeWithTotal() throws Exception { + RefreshTokensPage page = fromJSON(jsonWithTotal, RefreshTokensPage.class); + + assertThat(page.getTotal(), is(11)); + } +} diff --git a/src/test/java/com/auth0/json/mgmt/sessions/SessionTest.java b/src/test/java/com/auth0/json/mgmt/sessions/SessionTest.java new file mode 100644 index 00000000..8ed3d2c2 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/sessions/SessionTest.java @@ -0,0 +1,91 @@ +package com.auth0.json.mgmt.sessions; + +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +public class SessionTest extends JsonTest { + + private static final String json = "{\n" + + " \"id\": \"sessionId1\",\n" + + " \"user_id\": \"userId1\",\n" + + " \"created_at\": \"2024-09-04T06:41:46.145Z\",\n" + + " \"updated_at\": \"2024-09-04T06:41:46.621Z\",\n" + + " \"authenticated_at\": \"2024-09-04T06:41:46.145Z\",\n" + + " \"authentication\": {\n" + + " \"methods\": [\n" + + " {\n" + + " \"name\": \"federated\",\n" + + " \"timestamp\": \"2024-09-04T06:41:46.145Z\"\n" + + " }\n" + + " ]\n" + + " },\n" + + " \"idle_expires_at\": \"2024-09-07T06:41:46.622Z\",\n" + + " \"expires_at\": \"2024-09-11T06:41:46.145Z\",\n" + + " \"device\": {\n" + + " \"initial_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36\",\n" + + " \"initial_asn\": \"1234\",\n" + + " \"initial_ip\": \"134.1.15.0\",\n" + + " \"last_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36\",\n" + + " \"last_ip\": \"134.1.15.0\",\n" + + " \"last_asn\": \"1234\"\n" + + " },\n" + + " \"clients\": [\n" + + " {\n" + + " \"client_id\": \"clientId1\"\n" + + " }\n" + + " ]\n" + + "}"; + + private static final String readOnlyJson = "{\n" + + " \"user_id\": \"userId1\",\n" + + " \"clients\": [\n" + + " {\n" + + " \"client_id\": \"clientId1\"\n" + + " }\n" + + " ]\n" + + "}"; + + @Test + public void shouldDeserialize() throws Exception { + Session session = fromJSON(json, Session.class); + + assertThat(session, is(notNullValue())); + assertThat(session.getId(), is("sessionId1")); + assertThat(session.getUserId(), is("userId1")); + assertThat(session.getCreatedAt(), is(parseJSONDate("2024-09-04T06:41:46.145Z"))); + assertThat(session.getUpdatedAt(), is(parseJSONDate("2024-09-04T06:41:46.621Z"))); + assertThat(session.getAuthenticatedAt(), is(parseJSONDate("2024-09-04T06:41:46.145Z"))); + + assertThat(session.getAuthentication().getMethods(), is(notNullValue())); + assertThat(session.getAuthentication().getMethods().get(0).getName(), is("federated")); + assertThat(session.getAuthentication().getMethods().get(0).getTimestamp(), is(parseJSONDate("2024-09-04T06:41:46.145Z"))); + + assertThat(session.getIdleExpiresAt(), is(parseJSONDate("2024-09-07T06:41:46.622Z"))); + assertThat(session.getExpiresAt(), is(parseJSONDate("2024-09-11T06:41:46.145Z"))); + + assertThat(session.getDevice(), is(notNullValue())); + assertThat(session.getDevice().getInitialASN(), is("1234")); + assertThat(session.getDevice().getInitialIP(), is("134.1.15.0")); + assertThat(session.getDevice().getInitialUserAgent(), is("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36")); + assertThat(session.getDevice().getLastASN(), is("1234")); + assertThat(session.getDevice().getLastIP(), is("134.1.15.0")); + assertThat(session.getDevice().getLastUserAgent(), is("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36")); + + assertThat(session.getClients(), is(notNullValue())); + assertThat(session.getClients().get(0).getClientId(), is("clientId1")); + } + + @Test + public void shouldIncludeReadOnlyValuesOnDeserialize() throws Exception { + Session session = fromJSON(readOnlyJson, Session.class); + assertThat(session, is(notNullValue())); + assertThat(session.getUserId(), is("userId1")); + assertThat(session.getClients().get(0).getClientId(), is("clientId1")); + } + + +} diff --git a/src/test/java/com/auth0/json/mgmt/sessions/SessionsPageTest.java b/src/test/java/com/auth0/json/mgmt/sessions/SessionsPageTest.java new file mode 100644 index 00000000..12d28899 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/sessions/SessionsPageTest.java @@ -0,0 +1,121 @@ +package com.auth0.json.mgmt.sessions; + +import com.auth0.json.JsonTest; +import com.auth0.json.mgmt.sessions.SessionsPage; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +public class SessionsPageTest extends JsonTest { + private static final String json = "{\n" + + " \"sessions\": [\n" + + " {\n" + + " \"id\": \"sessionId1\",\n" + + " \"user_id\": \"userId1\",\n" + + " \"created_at\": \"2024-06-26T09:10:26.643Z\",\n" + + " \"updated_at\": \"2024-06-26T09:10:27.131Z\",\n" + + " \"authenticated_at\": \"2024-06-26T09:10:26.643Z\",\n" + + " \"authentication\": {\n" + + " \"methods\": [\n" + + " {\n" + + " \"name\": \"pwd\",\n" + + " \"timestamp\": \"2024-06-26T09:10:26.643Z\"\n" + + " }\n" + + " ]\n" + + " },\n" + + " \"idle_expires_at\": \"2024-06-26T09:40:27.131Z\",\n" + + " \"expires_at\": \"2024-07-03T09:10:26.643Z\",\n" + + " \"device\": {\n" + + " \"initial_asn\": \"1234\",\n" + + " \"initial_ip\": \"203.0.113.1\",\n" + + " \"initial_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\n" + + " \"last_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\n" + + " \"last_ip\": \"203.0.113.1\",\n" + + " \"last_asn\": \"1234\"\n" + + " },\n" + + " \"clients\": [\n" + + " {\n" + + " \"client_id\": \"clientId1\"\n" + + " }\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"next\": \"sessionId1\"\n" + + "}"; + private static final String jsonWithTotals = "{\n" + + " \"sessions\": [\n" + + " {\n" + + " \"id\": \"sessionId1\",\n" + + " \"user_id\": \"userId1\",\n" + + " \"created_at\": \"2024-06-26T09:10:26.643Z\",\n" + + " \"updated_at\": \"2024-06-26T09:10:27.131Z\",\n" + + " \"authenticated_at\": \"2024-06-26T09:10:26.643Z\",\n" + + " \"authentication\": {\n" + + " \"methods\": [\n" + + " {\n" + + " \"name\": \"pwd\",\n" + + " \"timestamp\": \"2024-06-26T09:10:26.643Z\"\n" + + " }\n" + + " ]\n" + + " },\n" + + " \"idle_expires_at\": \"2024-06-26T09:40:27.131Z\",\n" + + " \"expires_at\": \"2024-07-03T09:10:26.643Z\",\n" + + " \"device\": {\n" + + " \"initial_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36\",\n" + + " \"initial_asn\": \"1234\",\n" + + " \"initial_ip\": \"203.0.113.1\",\n" + + " \"last_user_agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\n" + + " \"last_ip\": \"203.0.113.1\",\n" + + " \"last_asn\": \"1234\"\n" + + " },\n" + + " \"clients\": [\n" + + " {\n" + + " \"client_id\": \"clientId1\"\n" + + " }\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"next\": \"sessionId1\",\n" + + " \"total\": 11\n" + + "}"; + + @Test + public void shouldDeserialize() throws Exception { + SessionsPage page = fromJSON(json, SessionsPage.class); + + assertThat(page.getTotal(), is(nullValue())); + assertThat(page.getNext(), is("sessionId1")); + assertThat(page.getSessions().size(), is(1)); + assertThat(page.getSessions().get(0).getId(), is("sessionId1")); + assertThat(page.getSessions().get(0).getUserId(), is("userId1")); + assertThat(page.getSessions().get(0).getCreatedAt(), is(parseJSONDate("2024-06-26T09:10:26.643Z"))); + assertThat(page.getSessions().get(0).getUpdatedAt(), is(parseJSONDate("2024-06-26T09:10:27.131Z"))); + assertThat(page.getSessions().get(0).getAuthenticatedAt(), is(parseJSONDate("2024-06-26T09:10:26.643Z"))); + assertThat(page.getSessions().get(0).getIdleExpiresAt(), is(parseJSONDate("2024-06-26T09:40:27.131Z"))); + assertThat(page.getSessions().get(0).getExpiresAt(), is(parseJSONDate("2024-07-03T09:10:26.643Z"))); + + assertThat(page.getSessions().get(0).getDevice().getInitialASN(), is("1234")); + assertThat(page.getSessions().get(0).getDevice().getInitialIP(), is("203.0.113.1")); + assertThat(page.getSessions().get(0).getDevice().getLastUserAgent(), is("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36")); + assertThat(page.getSessions().get(0).getDevice().getLastIP(), is("203.0.113.1")); + assertThat(page.getSessions().get(0).getDevice().getLastASN(), is("1234")); + assertThat(page.getSessions().get(0).getDevice().getLastUserAgent(), is("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36")); + + assertThat(page.getSessions().get(0).getClients().size(), is(1)); + assertThat(page.getSessions().get(0).getClients().get(0).getClientId(), is("clientId1")); + + assertThat(page.getSessions().get(0).getAuthentication().getMethods().size(), is(1)); + assertThat(page.getSessions().get(0).getAuthentication().getMethods().get(0).getName(), is("pwd")); + assertThat(page.getSessions().get(0).getAuthentication().getMethods().get(0).getTimestamp(), is(parseJSONDate("2024-06-26T09:10:26.643Z"))); + assertThat(page.getSessions().get(0).getAuthentication().getMethods().get(0).getType(), is(nullValue())); + } + + @Test + public void shouldDeserializeWithTotals() throws Exception { + SessionsPage page = fromJSON(jsonWithTotals, SessionsPage.class); + + assertThat(page.getTotal(), is(11)); + } +} diff --git a/src/test/resources/mgmt/refresh_token.json b/src/test/resources/mgmt/refresh_token.json new file mode 100644 index 00000000..8ea37353 --- /dev/null +++ b/src/test/resources/mgmt/refresh_token.json @@ -0,0 +1,28 @@ +{ + "id": "tokenId1", + "user_id": "userId1", + "created_at": "2024-06-26T09:10:26.643Z", + "idle_expires_at": "2024-06-26T09:10:27.131Z", + "expires_at": "2024-07-03T09:10:26.643Z", + "device": { + "initial_asn": "1234", + "initial_ip": "203.0.113.1", + "initial_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", + "last_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", + "last_ip": "203.0.113.1", + "last_asn": "1234" + }, + "client_id": "clientId1", + "session_id": "sessionId1", + "rotating": false, + "resource_servers": [ + { + "audience": "https://api.example.com", + "scopes": [ + "read:examples", + "write:examples" + ] + } + ], + "last_exchanged_at": "2024-07-03T09:10:26.643Z" +} diff --git a/src/test/resources/mgmt/session.json b/src/test/resources/mgmt/session.json new file mode 100644 index 00000000..07251c3c --- /dev/null +++ b/src/test/resources/mgmt/session.json @@ -0,0 +1,30 @@ +{ + "id": "sessionId1", + "user_id": "userId1", + "created_at": "2024-09-04T06:41:46.145Z", + "updated_at": "2024-09-04T06:41:46.621Z", + "authenticated_at": "2024-09-04T06:41:46.145Z", + "authentication": { + "methods": [ + { + "name": "federated", + "timestamp": "2024-09-04T06:41:46.145Z" + } + ] + }, + "idle_expires_at": "2024-09-07T06:41:46.622Z", + "expires_at": "2024-09-11T06:41:46.145Z", + "device": { + "initial_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36", + "initial_asn": "1234", + "initial_ip": "134.1.15.0", + "last_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36", + "last_ip": "134.1.15.0", + "last_asn": "1234" + }, + "clients": [ + { + "client_id": "clientId1" + } + ] +} diff --git a/src/test/resources/mgmt/user_refresh_tokens.json b/src/test/resources/mgmt/user_refresh_tokens.json new file mode 100644 index 00000000..18c77eb6 --- /dev/null +++ b/src/test/resources/mgmt/user_refresh_tokens.json @@ -0,0 +1,63 @@ +{ + "tokens": [ + { + "id": "tokenId1", + "user_id": "userId1", + "created_at": "2024-06-26T09:10:26.643Z", + "idle_expires_at": "2024-06-26T09:10:27.131Z", + "expires_at": "2024-07-03T09:10:26.643Z", + "device": { + "initial_asn": "1234", + "initial_ip": "203.0.113.1", + "initial_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", + "last_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", + "last_ip": "203.0.113.1", + "last_asn": "1234" + }, + "client_id": "clientId1", + "session_id": "sessionId1", + "rotating": false, + "resource_servers": [ + { + "audience": "https://api.example.com", + "scopes": [ + "read:examples", + "write:examples" + ] + } + ], + "last_exchanged_at": "2024-07-03T09:10:26.643Z" + }, + { + "id": "tokenId2", + "user_id": "userId1", + "created_at": "2024-06-26T09:10:26.643Z", + "updated_at": "2024-06-26T09:10:27.131Z", + "idle_expires_at": "2024-06-26T09:10:27.131Z", + "expires_at": "2024-07-03T09:10:26.643Z", + "device": { + "initial_asn": "1234", + "initial_ip": "203.0.113.1", + "initial_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", + "last_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", + "last_ip": "203.0.113.1", + "last_asn": "1234" + }, + "client_id": "clientId2", + "session_id": "sessionId2", + "rotating": true, + "resource_servers": [ + { + "audience": "https://api.example.com", + "scopes": [ + "read:examples", + "write:examples" + ] + } + ], + "last_exchanged_at": "2024-07-03T09:10:26.643Z" + } + ], + "next": "token1", + "total": 11 +} diff --git a/src/test/resources/mgmt/user_sessions.json b/src/test/resources/mgmt/user_sessions.json new file mode 100644 index 00000000..71c9b754 --- /dev/null +++ b/src/test/resources/mgmt/user_sessions.json @@ -0,0 +1,36 @@ +{ + "sessions": [ + { + "id": "sessionId1", + "user_id": "userId1", + "created_at": "2024-06-26T09:10:26.643Z", + "updated_at": "2024-06-26T09:10:27.131Z", + "authenticated_at": "2024-06-26T09:10:26.643Z", + "authentication": { + "methods": [ + { + "name": "pwd", + "timestamp": "2024-06-26T09:10:26.643Z" + } + ] + }, + "idle_expires_at": "2024-06-26T09:40:27.131Z", + "expires_at": "2024-07-03T09:10:26.643Z", + "device": { + "initial_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36", + "initial_asn": "1234", + "initial_ip": "203.0.113.1", + "last_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", + "last_ip": "203.0.113.1", + "last_asn": "1234" + }, + "clients": [ + { + "client_id": "clientId1" + } + ] + } + ], + "next": "sessionId1", + "total": 9 +}