public String getWWWAuthenticateHeader(String realm) throws IOException {
        StringBuilder into = new StringBuilder();
        String authScheme = null;

        if (realm != null) {
            into.append(" realm=\"").append(OAuth2.percentEncode(realm)).append('"');
        }
        beforeGetParameter();
        if (parameters != null) {
            for (Map.Entry parameter : parameters) {
                String name = toString(parameter.getKey());
                if (name.startsWith("error")) {
                    if (into.length() > 0) into.append(",");
                    into.append(" ");
                    into.append(OAuth2.percentEncode(name)).append("=\"");
                   into.append(OAuth2.percentEncode(toString(parameter.getValue()))).append('"');
                }else if(name.startsWith(AUTH_SCHEME)){
                    authScheme = toString(parameter.getValue());
                }

            }
        }

        if(authScheme == null){
            // TODO Throw exception
        }
        return authScheme + " " + into.toString();
    }