有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在Android中测试SAML RestAPI?

我用openid connect尝试了这个,它正在工作。我想让SAML做同样的事。仅供参考,我正在用KeyClope做演示。所以,我已经在KeyClope控制台/仪表板内部将协议从openid connet更改为SAML

代码:

@Override
    protected Boolean doInBackground(String... params) {
        try {
            OkHttpClient client = new OkHttpClient().newBuilder()
                    .build();
            MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
            
            /*For openid-connect*/
            //RequestBody body = RequestBody.create(mediaType, "client_id=lifetrenz-client-1&username=test&password=test@123&grant_type=password&client_secret=c89b1eed-136d-445f-bfb0-e7e2bdac89ee");


            /*For SAML*/
            RequestBody body = RequestBody.create(mediaType, "client_id=lifetrenz-client-1&username=test&password=test@123&grant_type=password");


            /*URL is changing manually accoridng to protocol*/
            Request request = new Request.Builder()
                    .url("http://10.0.2.2:8080/auth/realms/Lifetrenz/protocol/saml/token")
                    .method("POST", body)
                    .addHeader("Content-Type", "application/x-www-form-urlencoded")
                    .build();
            Response response = client.newCall(request).execute();
            data = "CODE: " + response.code() + "\n" + "MESSAGE: " + response.message() + "\n" + "BODY: " + response.body().string();
            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }

请引导我。请用Java而不是Kotlin回答


共 (1) 个答案

  1. # 1 楼答案

    您不能只是将协议更改为SAML,然后发送OpenID连接参数

    下面是一个SAML request的例子。参数完全不同

    您不能使用RESTAPI。SAML使用浏览器重定向

    不是KeyClope专家,但您的应用程序需要一个client-side SAML stack