我们基本上试图将改造用作oauth的休息客户 .
同样,我们试图获得客户端凭据授权 .
所以我们对令牌 endpoints 进行休息调用,传递所有url编码的参数 .
呼叫成功,因为我们在响应代码中得到200 . Okhttp loggin拦截器显示响应主体包含access_token和其他字段 .
但是,改进响应无法解析accessestoken模型 . 令牌空白 .
log.info("Passing input as Body in x-www-form-urlencoded");
//log.info("config.getApiKey() && config.getApiSecret()=="+config.getApiKey()+" "+ config.getApiSecret());
inputBody.put(GRANT_TYPE, CLIENT_CREDENTIALS);
inputBody.put(CLIENT_ID, "abcd");
inputBody.put(CLIENT_SECRET, "d=");
inputBody.put(RESOURCE, HTTPS_GRfgeAPH_WINDOWS_NET);
log.info("inputBody=="+inputBody.get(CLIENT_ID));
/*if(handleResponse(azureLoginTokenService.getToken(inputBody).execute())!=null){
log.info("inside if");
tokenOutput.setAzureLoginTokenModel(handleResponse(azureLoginTokenService.getToken(inputBody).execute()));
clientCredentialGrantToken = tokenOutput.getAzureLoginTokenModel().getAccessToken();
isTokenExpired = false;
return clientCredentialGrantToken;
}
else{
log.info ("Could not fetch azure token!!!!!");
return null;
}
- / log.info("inside if"); // AzureLoginTokenModel azureToken = handleResponse(azureLoginTokenService.getToken(inputBody).execute()); AzureLoginTokenModel azureToken = azureLoginTokenService.getToken(inputBody).execute() . body(); log.info(“ Token Model ”azureToken.getAccessToken());
@JsonInclude(JsonInclude.Include.NON_NULL)@JsonPropertyOrder({“token_type”,“expires_in”,“ext_expires_in”,“expires_on”,“not_before”,“resource”,“access_token”})公共类AzureLoginTokenModel {
@JsonProperty("token_type")
private String tokenType;
@JsonProperty("expires_in")
private String expiresIn;
@JsonProperty("ext_expires_in")
private String extExpiresIn;
@JsonProperty("expires_on")
private String expiresOn;
@JsonProperty("not_before")
private String notBefore;
@JsonProperty("resource")
private String resource;
@JsonProperty("access_token")
private String accessToken;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
@JsonProperty("token_type")
public String getTokenType() {
return tokenType;
}
@JsonProperty("token_type")
public void setTokenType(String tokenType) {
this.tokenType = tokenType;
}
@JsonProperty("expires_in")
public String getExpiresIn() {
return expiresIn;
}
@JsonProperty("expires_in")
public void setExpiresIn(String expiresIn) {
this.expiresIn = expiresIn;
}
@JsonProperty("ext_expires_in")
public String getExtExpiresIn() {
return extExpiresIn;
}
@JsonProperty("ext_expires_in")
public void setExtExpiresIn(String extExpiresIn) {
this.extExpiresIn = extExpiresIn;
}
@JsonProperty("expires_on")
public String getExpiresOn() {
return expiresOn;
}
@JsonProperty("expires_on")
public void setExpiresOn(String expiresOn) {
this.expiresOn = expiresOn;
}
@JsonProperty("not_before")
public String getNotBefore() {
return notBefore;
}
@JsonProperty("not_before")
public void setNotBefore(String notBefore) {
this.notBefore = notBefore;
}
@JsonProperty("resource")
public String getResource() {
return resource;
}
@JsonProperty("resource")
public void setResource(String resource) {
this.resource = resource;
}
@JsonProperty("access_token")
public String getAccessToken() {
return accessToken;
}
@JsonProperty("access_token")
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
身体被解析......
{"token_type":"Bearer","expires_in":"3600","ext_expires_in":"0","expires_on":"1519203625","not_before":"1519199725","resource": “https://graph.windows.net ", "的access_token ": " eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlNTUWRoSTFjS3ZoUUVEU0p4RTJnR1lzNDBRMCIsImtpZCI6IlNTUWRoSTFjS3ZoUUVEU0p4RTJnR1lzNDBRMCJ9.eyJhdWQiOiJodHRwczovL2dyYXB”}
即使是response.raw >>>也没有改造响应