【问题标题】:Communicating with Google OpenID server returns a 400与 Google OpenID 服务器通信返回 400
【发布时间】:2013-03-21 18:55:36
【问题描述】:

我正在尝试在 Android 上实现 OpenId 并不断收到 400 错误。我猜我的参数格式不正确。

我将参数基于此浏览器行,它可以正确地将我带到服务器:

https://www.google.com/accounts/o8/ud
?openid.ns=http://specs.openid.net/auth/2.0
&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select
&openid.identity=http://specs.openid.net/auth/2.0/identifier_select
&openid.return_to=http://www.example.com/checkauth
&openid.realm=http://www.example.com/
&openid.assoc_handle=ABSmpf6DNMw
&openid.mode=checkid_setup

这是代码

            try {

         HttpsURLConnection con; 

         URL url2 = new URL("https://www.google.com/accounts/o8/ud");
         con = (HttpsURLConnection) url2.openConnection();
         con.setDoInput(true);
         con.setDoOutput(true);

         con.setRequestMethod("GET");

         List<NameValuePair> params = new ArrayList<NameValuePair>();
         params.add(new BasicNameValuePair("openid.ns", "http://specs.openid.net/auth/2.0"));
         params.add(new BasicNameValuePair("openid.claimed_id", "http://specs.openid.net/auth/2.0/identifier_select"));
         params.add(new BasicNameValuePair("openid.identity", "http://specs.openid.net/auth/2.0/identifier_select"));
         params.add(new BasicNameValuePair("openid.return_to", "http://www.example.com/checkauth"));
         params.add(new BasicNameValuePair("openid.realm", "http://www.example.com/"));
         params.add(new BasicNameValuePair("openid.assoc_handle", "ABSmpf6DNMw"));
         params.add(new BasicNameValuePair("openid.mode", "checkid_setup"));

         String content = AuthUtils.getRequestParams(params);
         con.setFixedLengthStreamingMode(content.getBytes("UTF-8").length);

         OutputStream out = con.getOutputStream();
         BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
         writer.write(content);
         writer.close();
         out.close();            

         Log.d(TAG, "response code = " + con.getResponseCode());

         BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));

         String input;

         while ((input = br.readLine()) != null){
             System.out.println(input);
         }
         br.close();             


        } catch (MalformedURLException e) {
             Log.e(TAG, e.toString());
            e.printStackTrace();
        } catch (IOException e) {
             Log.e(TAG, e.toString());
         e.printStackTrace();
        } catch (Exception e) {
             Log.e(TAG, e.toString());
             e.printStackTrace();
        }

【问题讨论】:

    标签: java android authentication openid single-sign-on


    【解决方案1】:

    来自谷歌的documentation

    如果提供的域不是由 Google 托管,Google 的端点将在端点 (2) 上返回 400。因此,对于想要迎合 Google Apps 客户的 RP,一种可能的策略是首先尝试端点(2),如果返回 400,则尝试端点(1),如果没有产生任何结果,则放弃。其他策略(例如,并行获取两个端点)也是可能的。

    More infos here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-13
      • 2016-02-04
      • 1970-01-01
      • 2012-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多