使用 Pipe (Aerogear) 调用 api 时获取状态代码 404 和服务连接错误
Getting status code 404 and service connection error while calling api using Pipe (Aerogear)
我正在为用户实施 Keycloak 和 api 身份验证,并成功通过 Keyclaok 服务器进行身份验证,但在调用 API 时出现错误。
我正在使用 aerogear 管道库和示例项目来调用服务器 API。
https://github.com/aerogear/aerogear-android-pipe
try{
AuthzModule authzModule = AuthorizationManager.config("keycloak", OAuth2AuthorizationConfiguration.class)
.setBaseURL(new URL("URL:8080/auth"))
.setAuthzEndpoint("/realms/appname/tokens/login")
.setAccessTokenEndpoint("/realms/appname/tokens/access/codes")
.setAccountId("keycloak-token")
.setClientId("app_id")
.setClientSecret("1b9a1376-bc6e-41d2-b3e5-cee754305a1f")
.setRedirectURL("Callback")
.setScopes(Arrays.asList("user"))
.addAdditionalAuthorizationParam((Pair.create("access_type", "confidential")))
.asModule();
authzModule.requestAccess(this, new Callback<String>() {
@Override
public void onSuccess(String o) {
System.out.println("Server Response" + o);
retrieveFiles(authzModule);
}
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
});
PipeManager.config("GetFile", RestfulPipeConfiguration.class)
.withUrl(new URL("Server_URL"))
.module(authzModule)
.forClass(String.class);
Pipe<Object> documentsPipe = PipeManager.getPipe("GetFile", this);
documentsPipe.read(new Callback<List<Object>>() {
@Override
public void onSuccess(final List<Object> fileses) {
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}catch (Exception ex){
Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}
请提出解决此问题的可行方法。
try{
AuthzModule authzModule = AuthorizationManager.config("keycloak", OAuth2AuthorizationConfiguration.class)
.setBaseURL(new URL("URL:8080/auth"))
.setAuthzEndpoint("/realms/appname/tokens/login")
.setAccessTokenEndpoint("/realms/appname/tokens/access/codes")
.setAccountId("keycloak-token")
.setClientId("app_id")
.setClientSecret("1b9a1376-bc6e-41d2-b3e5-cee754305a1f")
.setRedirectURL("Callback")
.setScopes(Arrays.asList("user"))
.addAdditionalAuthorizationParam((Pair.create("access_type", "confidential")))
.asModule();
authzModule.requestAccess(this, new Callback<String>() {
@Override
public void onSuccess(String o) {
System.out.println("Server Response" + o);
retrieveFiles(authzModule);
}
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}catch (Exception ex){
Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}
然后在 header.when 服务器发送 json 响应中使用身份验证令牌调用简单的 http 请求。
Headers:Bearer +"auth token",
Content-Type : application/json,
接受:application/json
我正在为用户实施 Keycloak 和 api 身份验证,并成功通过 Keyclaok 服务器进行身份验证,但在调用 API 时出现错误。
我正在使用 aerogear 管道库和示例项目来调用服务器 API。 https://github.com/aerogear/aerogear-android-pipe
try{
AuthzModule authzModule = AuthorizationManager.config("keycloak", OAuth2AuthorizationConfiguration.class)
.setBaseURL(new URL("URL:8080/auth"))
.setAuthzEndpoint("/realms/appname/tokens/login")
.setAccessTokenEndpoint("/realms/appname/tokens/access/codes")
.setAccountId("keycloak-token")
.setClientId("app_id")
.setClientSecret("1b9a1376-bc6e-41d2-b3e5-cee754305a1f")
.setRedirectURL("Callback")
.setScopes(Arrays.asList("user"))
.addAdditionalAuthorizationParam((Pair.create("access_type", "confidential")))
.asModule();
authzModule.requestAccess(this, new Callback<String>() {
@Override
public void onSuccess(String o) {
System.out.println("Server Response" + o);
retrieveFiles(authzModule);
}
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
});
PipeManager.config("GetFile", RestfulPipeConfiguration.class)
.withUrl(new URL("Server_URL"))
.module(authzModule)
.forClass(String.class);
Pipe<Object> documentsPipe = PipeManager.getPipe("GetFile", this);
documentsPipe.read(new Callback<List<Object>>() {
@Override
public void onSuccess(final List<Object> fileses) {
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}catch (Exception ex){
Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}
请提出解决此问题的可行方法。
try{
AuthzModule authzModule = AuthorizationManager.config("keycloak", OAuth2AuthorizationConfiguration.class)
.setBaseURL(new URL("URL:8080/auth"))
.setAuthzEndpoint("/realms/appname/tokens/login")
.setAccessTokenEndpoint("/realms/appname/tokens/access/codes")
.setAccountId("keycloak-token")
.setClientId("app_id")
.setClientSecret("1b9a1376-bc6e-41d2-b3e5-cee754305a1f")
.setRedirectURL("Callback")
.setScopes(Arrays.asList("user"))
.addAdditionalAuthorizationParam((Pair.create("access_type", "confidential")))
.asModule();
authzModule.requestAccess(this, new Callback<String>() {
@Override
public void onSuccess(String o) {
System.out.println("Server Response" + o);
retrieveFiles(authzModule);
}
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}catch (Exception ex){
Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}
然后在 header.when 服务器发送 json 响应中使用身份验证令牌调用简单的 http 请求。
Headers:Bearer +"auth token", Content-Type : application/json, 接受:application/json