【问题标题】:Call Thinktecture IdentiyServer from android app从安卓应用调用 Thinktecture IdentiyServer
【发布时间】:2013-07-20 01:03:01
【问题描述】:

我在尝试从 Android 应用程序调用身份服务器时遇到问题。问题是我已经搜索了一种从基于 C# 的应用程序以外的任何其他东西调用 IdSrv 的方法,并且只找到了一个如何从 JS 调用它的示例。所以,这就是从 JS 进行调用的方式:

function HttpBasicClient(uid, pwd) {
            this.scheme = "Basic";
            this.token = Base64.encode(uid + ":" + pwd);
        }
        HttpBasicClient.prototype.get = function (url) {
            var scheme = this.scheme;
            var token = this.token;
            var settings = {
                type: "GET",
                url: url,
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Authorization", scheme + " " + token);
                }
            };

这是我对 Android 的翻译:

HttpClient client = getCustomHttpClient();
        HttpResponse response;
        String scheme = "Basic";
        String token = Base64.encodeToString((username+":"+password).getBytes(), 0);
        try{
            HttpGet get = new HttpGet("https://url/issue/wstrust/mixed/username");
            get.setHeader("Authorization", scheme + " " + token);
            response = client.execute(get);
            StatusLine sLine = response.getStatusLine();
            int statusCode = sLine.getStatusCode();

我正在使用接受所有类型证书的自定义 HttpClient,因此 SSL 应该不是问题。问题是,当拨打电话时,Http 400会回复我,告诉我请求格式不正确。我的问题是,有谁知道应该如何准确调用 Identity Server 才能接受它并将令牌返回给我?

【问题讨论】:

  • 您确定要调用 WS-Trust 端点吗?
  • 是的,我确定。我还查看了进入服务器的流量(在 wireshark 中)。来自我的客户端的请求似乎没问题,但是当服务器尝试发回回复时,我总是得到 Header checksum: 0x0000 with Message: Bad checksum.
  • WS-trust 是一个肥皂端点。并且没有获得 + 授权标头。
  • 我明白了。好吧,这解释了我得到的 400。在这种情况下,您能否提供一个简短的示例来说明如何从 Android 进行调用?
  • 为什么要使用 WS-Trust。为什么不是为 Http 消费而设计的 OAuth2 端点?检查 github 上的 Idsrv wiki 以获取该示例(查找资源所有者流程)

标签: android thinktecture-ident-server


【解决方案1】:

您宁愿使用 OAuth2 端点 - 很可能使用资源所有者流程。查看 wiki 中的示例:

https://github.com/thinktecture/Thinktecture.IdentityServer.v2/wiki

具体来说:

http://leastprivilege.com/2012/11/01/oauth2-in-thinktecture-identityserver-v2-resource-owner-password-flow/

【讨论】:

  • 这可能会奏效。但是如果我没有配置任何 OAuth2 端点怎么办?在 Identity Server 的元文件中,只有 WS-Trust 端点。因此,如果我要使用 WS-Trust 端点调用 IdSrv,我需要以 SOAP 方式调用它吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-28
  • 1970-01-01
  • 1970-01-01
  • 2012-09-07
  • 1970-01-01
  • 2014-01-26
  • 2012-05-19
相关资源
最近更新 更多