Question

I am trying to use javascript to login to identity server in OAuths Client. I can login and return to the return webpage successful. I met a problem is why the Thinktecture identity sevrer always return '#' not '?' before parameters in querystring ,is that a bug?

the other question is how can I get the uses claims when I have access_token?

Was it helpful?

Solution

Implicit flow uses a hash fragment not a query string - that is not a bug (check the OAuth2 spec).

The client does not consume the access token in OAuth2 - it is opaque to the client - the access token is meant to be used by the backend.

OTHER TIPS

I write a javascript function with regular expression to extract the "access_token" parameter as below:

    var _access_token = getParameterByName('access_token');        
    function getParameterByName(name) {
        var str = location.hash.substring(1);
        var patt1 = new RegExp(name + "\\s*=\\s*([^&]+)", "g");
        var result = patt1.exec(str);;
        if (result == null)
            return "";
        else
            return result[1];
    }

then I try to use base64 to decode the access_token to get to extract the claims:

    var Claims = base64decode(access_token) 
    function base64decode(input) {
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;

    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

    while (i < input.length) {

        enc1 = this._keyStr.indexOf(input.charAt(i++));
        enc2 = this._keyStr.indexOf(input.charAt(i++));
        enc3 = this._keyStr.indexOf(input.charAt(i++));
        enc4 = this._keyStr.indexOf(input.charAt(i++));

        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;

        output = output + String.fromCharCode(chr1);

        if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
        }
        if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
        }

    }

    output = Base64._utf8_decode(output);

    return output;

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