从Android应用程序调用Thinktecture IdentiyServer

时间:2013-07-18 10:05:13

标签: android thinktecture-ident-server

我在尝试从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来接受它并将令牌返回给我?

1 个答案:

答案 0 :(得分:0)

您更愿意使用OAuth2端点 - 最有可能使用资源所有者流。检查维基以获取样本:

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

具体是:

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