Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource server #77

Merged
merged 4 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/com/auth0/client/mgmt/ManagementAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,8 @@ public TenantsEntity tenants() {
public TicketsEntity tickets() {
return new TicketsEntity(client, baseUrl, apiToken);
}

public ResourceServerEntity resourceServers(){
return new ResourceServerEntity(client, baseUrl, apiToken);
}
}
137 changes: 137 additions & 0 deletions src/main/java/com/auth0/client/mgmt/ResourceServerEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.auth0.client.mgmt;

import java.util.List;

import com.auth0.json.mgmt.ResourceServer;
import com.auth0.net.CustomRequest;
import com.auth0.net.Request;
import com.auth0.net.VoidRequest;
import com.auth0.utils.Asserts;
import com.fasterxml.jackson.core.type.TypeReference;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;

public class ResourceServerEntity {
private OkHttpClient client;
private HttpUrl baseUrl;
private String apiToken;

ResourceServerEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
this.client = client;
this.baseUrl = baseUrl;
this.apiToken = apiToken;
}

/**
* Creates request to fetch all resource servers.
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/get_resource_servers>API documentation</a>
*
* @return request to execute
*/
public Request<List<ResourceServer>> list() {

HttpUrl.Builder builder = baseUrl
.newBuilder()
.addPathSegments("api/v2/resource-servers");

String url = builder.build().toString();
CustomRequest<List<ResourceServer>> request = new CustomRequest<>(client, url, "GET",
new TypeReference<List<ResourceServer>>() {
});
request.addHeader("Authorization", "Bearer " + apiToken);
return request;
}

/**
* Cretes request for fetching single resource server by it's ID.
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/get_resource_servers_by_id>API documentation</a>
*
* @param resourceServerIdOrIdentifier {@link ResourceServer#id} or {@link ResourceServer#identifier} (audience) field
* @return request to execute
*/
public Request<ResourceServer> get(String resourceServerIdOrIdentifier) {
Asserts.assertNotNull(resourceServerIdOrIdentifier, "Resource server ID");

HttpUrl.Builder builder = baseUrl
.newBuilder()
.addPathSegments("api/v2/resource-servers")
.addPathSegment(resourceServerIdOrIdentifier);

String url = builder.build().toString();
CustomRequest<ResourceServer> request = new CustomRequest<>(client, url, "GET",
new TypeReference<ResourceServer>() {
});
request.addHeader("Authorization", "Bearer " + apiToken);
return request;
}

/**
* Cretes request for creation resource server
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/post_resource_servers>API documentation</a>
*
* @param resourceServer resource server body
* @return request to execute
*/
public Request<ResourceServer> create(ResourceServer resourceServer) {
Asserts.assertNotNull(resourceServer, "Resource server");

HttpUrl.Builder builder = baseUrl
.newBuilder()
.addPathSegments("api/v2/resource-servers");

String url = builder.build().toString();
CustomRequest<ResourceServer> request = new CustomRequest<>(client, url, "POST",
new TypeReference<ResourceServer>() {
});
request.addHeader("Authorization", "Bearer " + apiToken);
request.setBody(resourceServer);
return request;
}

/**
* Creates request for delete resource server by it's ID
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/delete_resource_servers_by_id>API documentation</a>
*
* @param resourceServerId {@link ResourceServer#id} field
* @return request to execute
*/
public Request<Void> delete(String resourceServerId) {
Asserts.assertNotNull(resourceServerId, "Resource server ID");

HttpUrl.Builder builder = baseUrl
.newBuilder()
.addPathSegments("api/v2/resource-servers")
.addPathSegment(resourceServerId);

String url = builder.build().toString();
VoidRequest request = new VoidRequest(client, url, "DELETE");
request.addHeader("Authorization", "Bearer " + apiToken);
return request;
}

/**
* Creates request for partial update of resource server. All null fields stay not changed.
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/patch_resource_servers_by_id>API documentation</a>
*
* @param resourceServerId {@link ResourceServer#id} field
* @param resourceServer {@link ResourceServer} body
* @return request to execute
*/
public Request<ResourceServer> update(String resourceServerId, ResourceServer resourceServer) {
Asserts.assertNotNull(resourceServerId, "resourceServerId");
Asserts.assertNotNull(resourceServer, "resourceServer");

HttpUrl.Builder builder = baseUrl
.newBuilder()
.addPathSegments("api/v2/resource-servers")
.addPathSegment(resourceServerId);

String url = builder.build().toString();
CustomRequest<ResourceServer> request = new CustomRequest<ResourceServer>(client, url, "PATCH",
new TypeReference<ResourceServer>() {
});
request.addHeader("Authorization", "Bearer " + apiToken);
request.setBody(resourceServer);
return request;
}
}
157 changes: 157 additions & 0 deletions src/main/java/com/auth0/json/mgmt/ResourceServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package com.auth0.json.mgmt;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

@SuppressWarnings({"WeakerAccess", "unused"})
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResourceServer {
@JsonProperty("id")
private String id;
@JsonProperty("name")
private String name;
@JsonProperty("identifier")
private String identifier;
@JsonProperty("scopes")
private List<Scope> scopes;
@JsonProperty("signing_alg")
private String signingAlgorithm;
@JsonProperty("signing_secret")
private String signingSecret;
@JsonProperty("allow_offline_access")
private Boolean allowOfflineAccess;
@JsonProperty("skip_consent_for_verifiable_first_party_clients")
private Boolean skipConsentForVerifiableFirstPartyClients;
@JsonProperty("token_lifetime")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's missing the "token_lifetime_for_web" property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

private Integer tokenLifetime;
@JsonProperty("token_lifetime_for_web")
private Integer tokenLifetimeForWeb;
@JsonProperty("verification_location")
private String verificationLocation;
@JsonProperty("is_system")
private Boolean isSystem;

@JsonCreator
public ResourceServer(@JsonProperty("identifier") String identifier) {
this.identifier = identifier;
}

public ResourceServer() {
}

@JsonProperty("id")
public String getId() {
return id;
}

@JsonProperty("id")
public void setId(String id) {
this.id = id;
}

@JsonProperty("name")
public String getName() {
return name;
}

@JsonProperty("name")
public void setName(String name) {
this.name = name;
}

@JsonProperty("is_system")
public Boolean isSystem() {
return isSystem;
}

@JsonProperty("identifier")
public String getIdentifier() {
return identifier;
}

@JsonProperty("scopes")
public List<Scope> getScopes() {
return scopes;
}

@JsonProperty("scopes")
public void setScopes(List<Scope> scopes) {
this.scopes = scopes;
}

@JsonProperty("signing_alg")
public String getSigningAlgorithm() {
return signingAlgorithm;
}

@JsonProperty("signing_alg")
public void setSigningAlgorithm(String signingAlgorithm) {
this.signingAlgorithm = signingAlgorithm;
}

@JsonProperty("signing_secret")
public String getSigningSecret() {
return signingSecret;
}

@JsonProperty("signing_secret")
public void setSigningSecret(String signingSecret) {
this.signingSecret = signingSecret;
}

@JsonProperty("allow_offline_access")
public Boolean getAllowOfflineAccess() {
return allowOfflineAccess;
}

@JsonProperty("allow_offline_access")
public void setAllowOfflineAccess(Boolean allowOfflineAccess) {
this.allowOfflineAccess = allowOfflineAccess;
}

@JsonProperty("skip_consent_for_verifiable_first_party_clients")
public Boolean getSkipConsentForVerifiableFirstPartyClients() {
return skipConsentForVerifiableFirstPartyClients;
}

@JsonProperty("skip_consent_for_verifiable_first_party_clients")
public void setSkipConsentForVerifiableFirstPartyClients(Boolean skipConsentForVerifiableFirstPartyClients) {
this.skipConsentForVerifiableFirstPartyClients = skipConsentForVerifiableFirstPartyClients;
}

@JsonProperty("token_lifetime")
public Integer getTokenLifetime() {
return tokenLifetime;
}

@JsonProperty("token_lifetime")
public void setTokenLifetime(Integer tokenLifetime) {
this.tokenLifetime = tokenLifetime;
}

@JsonProperty("verification_location")
public String getVerificationLocation() {
return verificationLocation;
}

@JsonProperty("verification_location")
public void setVerificationLocation(String verificationLocation) {
this.verificationLocation = verificationLocation;
}

@JsonProperty("token_lifetime_for_web")
public Integer getTokenLifetimeForWeb() {
return tokenLifetimeForWeb;
}

@JsonProperty("token_lifetime_for_web")
public void setTokenLifetimeForWeb(Integer tokenLifetimeForWeb) {
this.tokenLifetimeForWeb = tokenLifetimeForWeb;
}

}
41 changes: 41 additions & 0 deletions src/main/java/com/auth0/json/mgmt/Scope.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.auth0.json.mgmt;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

@SuppressWarnings({"WeakerAccess", "unused"})
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Scope {
@JsonProperty("description")
private String description;
@JsonProperty("value")
private String value;

@JsonCreator
public Scope(@JsonProperty("value") String value) {
this.value = value;
}

@JsonProperty("description")
public String getDescription() {
return description;
}

@JsonProperty("description")
public void setDescription(String description) {
this.description = description;
}

@JsonProperty("value")
public String getValue() {
return value;
}

@JsonProperty("value")
public void setValue(String value) {
this.value = value;
}
}
Loading