package io.vertx.ext.auth.oauth2;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.auth.authentication.CredentialValidationException;
import io.vertx.ext.auth.authentication.Credentials;
import java.util.Map;
@DataObject
public class Oauth2Credentials implements Credentials {
private String code;
private String redirectUri;
private JsonObject ;
public Oauth2Credentials() {
}
public Oauth2Credentials(JsonObject jsonObject) {
for (Map.Entry<String, Object> member : jsonObject) {
switch (member.getKey()) {
case "code":
if (member.getValue() instanceof String) {
setCode((String) member.getValue());
}
break;
case "redirect_uri":
if (member.getValue() instanceof String) {
setRedirectUri((String) member.getValue());
}
break;
default:
if (extra == null) {
extra = new JsonObject();
}
extra.put(member.getKey(), member.getValue());
}
}
}
public String getCode() {
return code;
}
public Oauth2Credentials setCode(String code) {
this.code = code;
return this;
}
public String getRedirectUri() {
return redirectUri;
}
public Oauth2Credentials setRedirectUri(String redirectUri) {
this.redirectUri = redirectUri;
return this;
}
public JsonObject () {
return extra;
}
public Oauth2Credentials (JsonObject extra) {
this.extra = extra;
return this;
}
public JsonObject toJson() {
JsonObject json = new JsonObject();
if (getCode() != null) {
json.put("code", getCode());
}
if (getRedirectUri() != null) {
json.put("redirect_uri", getRedirectUri());
}
if (extra != null) {
json.mergeIn(extra);
}
return json;
}
@Override
public <V> void checkValid(V arg) throws CredentialValidationException {
OAuth2FlowType flow = (OAuth2FlowType) arg;
switch (flow) {
case AUTH_CODE:
if (code == null || code.length() == 0) {
throw new CredentialValidationException("code cannot be null or empty");
}
if (redirectUri != null && redirectUri.length() == 0) {
throw new CredentialValidationException("redirectUri cannot be empty");
}
break;
}
}
@Override
public String toString() {
return toJson().encode();
}
}