ympd icon indicating copy to clipboard operation
ympd copied to clipboard

HTTP: Access Authentication

Open kapralVV opened this issue 10 years ago • 4 comments

Could you please add either "basic" or "digest" http authentication feature (rfc2617) As for me it's very necessary feature.

kapralVV avatar Nov 19 '14 11:11 kapralVV

Hi, I added this feature, quite easy as ympd uses Mongoose HTTP lib. I'll fork the code. But basically you jsut have to add those lines to the http event handler :

static int server_callback(struct mg_connection *c, enum mg_event ev) {

int result = MG_FALSE;
FILE *fp;

switch(ev) {
    case MG_CLOSE:
        mpd_close_handler(c);
        return MG_TRUE;
    case MG_REQUEST:
        if (c->is_websocket) {
            c->content[c->content_len] = '\0';
            if(c->content_len)
                return callback_mpd(c);
            else
                return MG_TRUE;
        } else
#ifdef WITH_DYNAMIC_ASSETS
            return MG_FALSE;
#else
            return callback_http(c);
#endif
    case MG_AUTH:
    if ((fp = fopen("/opt/ympd/secrets/.htpasswd", "r")) != NULL) {
        result = mg_authorize_digest(c, fp);
        fclose(fp);
    }
    return result;
    default:
        return MG_FALSE;
}
}

shazz avatar Mar 09 '15 12:03 shazz

would it be possible to add ssl to this too?

typhoon71 avatar Mar 26 '15 17:03 typhoon71

@shazz that shomehow didn't work for me, I ended up having a loop were my browser constantly asked for credentials :(

@typhoon71 adding SSL support just requires that ympd is compiled with SSL support, see PR #97

SuperBFG7 avatar Sep 26 '15 12:09 SuperBFG7

I figured it out and created pull request #101 For a version supporting both SSL and htdigest check out my fork: https://github.com/SuperBFG7/ympd

SuperBFG7 avatar Oct 06 '15 18:10 SuperBFG7