Question

I'm having a problem trying to call the identity server from an Android application. The problem is that I've searched for a way to call IdSrv from anything else other than a C# based app and only found an example of how to call it from JS. So, this is how the the call is made from 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);
                }
            };

And this is my translation into 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();

I'm using a custom HttpClient that accepts all types of certificates so the SSL shouldn't be a problem. The problem is that when the call is made an Http 400gets back to me which tells me that the request is malformed. My question is, does anyone know how exactly the call to the Identity Server should be made for it to accept it and return me the token?

Was it helpful?

Solution

You'd rather want to use an OAuth2 endpoint - most probably using the resource owner flow. Check the wiki for samples:

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

specifically:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top