-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sessions and refresh tokens to Users Management API (#661)
- Loading branch information
Showing
26 changed files
with
1,706 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/com/auth0/client/mgmt/RefreshTokensEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <a href="https://auth0.com/docs/api/management/v2#!/Refresh_Tokens">https://auth0.com/docs/api/management/v2#!/Refresh_Tokens</a> | ||
* <p> | ||
* 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 <a href="https://auth0.com/docs/api/management/v2/refresh-tokens/get-refresh-token">https://auth0.com/docs/api/management/v2/refresh-tokens/get-refresh-token</a> | ||
* @param refreshTokenId the refresh token ID. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<RefreshToken> 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<RefreshToken>() { | ||
}); | ||
} | ||
|
||
/** | ||
* Delete the refresh token for a given refresh token ID. | ||
* * A token with scope {@code delete:refresh_tokens} is needed. | ||
* See <a href="https://auth0.com/docs/api/management/v2/refresh-tokens/delete-refresh-token">https://auth0.com/docs/api/management/v2/refresh-tokens/delete-refresh-token</a> | ||
* @param refreshTokenId the refresh token ID. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<Void> 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
* <p> | ||
* 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 <a href="https://auth0.com/docs/api/management/v2/sessions/get-session">https://auth0.com/docs/api/management/v2/sessions/get-session</a> | ||
* @param sessionId the session ID. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<Session> 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<Session>() { | ||
}); | ||
} | ||
|
||
/** | ||
* Delete the session for a given session ID. | ||
* A token with scope {@code delete:sessions} is needed. | ||
* See <a href="https://auth0.com/docs/api/management/v2/sessions/delete-session">https://auth0.com/docs/api/management/v2/sessions/delete-session</a> | ||
* @param sessionId the session ID. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<Void> 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/com/auth0/json/mgmt/refreshtokens/Device.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.