|
| 1 | +package com.auth0.client.mgmt; |
| 2 | + |
| 3 | +import com.auth0.json.mgmt.refreshtokens.RefreshToken; |
| 4 | +import com.auth0.net.BaseRequest; |
| 5 | +import com.auth0.net.Request; |
| 6 | +import com.auth0.net.VoidRequest; |
| 7 | +import com.auth0.net.client.Auth0HttpClient; |
| 8 | +import com.auth0.net.client.HttpMethod; |
| 9 | +import com.auth0.utils.Asserts; |
| 10 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 11 | +import okhttp3.HttpUrl; |
| 12 | + |
| 13 | +/** |
| 14 | + * 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> |
| 15 | + * <p> |
| 16 | + * This class is not thread-safe. |
| 17 | + * @see ManagementAPI |
| 18 | + */ |
| 19 | +@SuppressWarnings("WeakerAccess") |
| 20 | +public class RefreshTokensEntity extends BaseManagementEntity{ |
| 21 | + |
| 22 | + RefreshTokensEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) { |
| 23 | + super(client, baseUrl, tokenProvider); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Request the refresh token for a given refresh token ID. |
| 28 | + * A token with scope {@code read:refresh_tokens} is needed. |
| 29 | + * 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> |
| 30 | + * @param refreshTokenId the refresh token ID. |
| 31 | + * @return a Request to execute. |
| 32 | + */ |
| 33 | + public Request<RefreshToken> get(String refreshTokenId){ |
| 34 | + Asserts.assertNotNull(refreshTokenId, "refresh token ID"); |
| 35 | + |
| 36 | + String url = baseUrl |
| 37 | + .newBuilder() |
| 38 | + .addPathSegments("api/v2/refresh-tokens") |
| 39 | + .addPathSegment(refreshTokenId) |
| 40 | + .build() |
| 41 | + .toString(); |
| 42 | + |
| 43 | + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<RefreshToken>() { |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Delete the refresh token for a given refresh token ID. |
| 49 | + * * A token with scope {@code delete:refresh_tokens} is needed. |
| 50 | + * 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> |
| 51 | + * @param refreshTokenId the refresh token ID. |
| 52 | + * @return a Request to execute. |
| 53 | + */ |
| 54 | + public Request<Void> delete(String refreshTokenId){ |
| 55 | + Asserts.assertNotNull(refreshTokenId, "refresh token ID"); |
| 56 | + |
| 57 | + String url = baseUrl |
| 58 | + .newBuilder() |
| 59 | + .addPathSegments("api/v2/refresh-tokens") |
| 60 | + .addPathSegment(refreshTokenId) |
| 61 | + .build() |
| 62 | + .toString(); |
| 63 | + |
| 64 | + return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE); |
| 65 | + } |
| 66 | +} |
0 commit comments