Getting status code 404 and service connection error while calling api using Pipe (Aerogear)

668 views Asked by At

I am implementing Keycloak for user and api authentication and successfully authenticate with Keyclaok server but getting error while calling API .

I am using aerogear pipe library and sample project to call server 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();
    }

Please suggest possible way to resolved this issue.

1

There are 1 answers

0
R_K On BEST ANSWER
        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();
    }

Than call simple http request with auth token in header.when server sending json response.

Headers:Bearer +" auth token", Content-Type : application/json, Accept : application/json