-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http authentication in esp_http_server (IDFGH-2757) #4823
Conversation
@jaghatei Thanks for your contribution. |
|
is this ready? What is missing to implement? |
From my point this is ready for merge. But this needs to be done by "authorized" users... |
I get the error: implicit declaration of function 'mbedtls_base64_decode'
You must have ......
in "httpd_uri.c" |
Further, if you do not specify following in the configuration & mcu panics & restarts !
|
@jaghatei thanks for the contribution and sorry for the late reply. Can you have a look at our contribution guidelines and make appropriate changes. A couple of key points are:
I will provide other comments on the actual code separately. |
@shahpiyushv: will look into these points |
@jaghatei : Any progress yet? |
The http_auth_basic in components/esp_http_client/lib/include/http_auth.h Suggest to move http_auth_basic out of PRIV_INCLUDE_DIRS. |
@AxelLin You can configure the information as follows when call
or change it by
|
The thing is to use http_auth_basic() for httpd application, not for http client. |
@AxelLin I still suggest you reference the code #5646 (comment) for httpd application. |
I have no problem to implement it by myself. |
@AxelLin Thanks for your understanding, I suggest it because of if we make HTTP client API public then "HTTP server application" will create additional dependency on "HTTP client" component, which does not look very good. Of course, we will do it if we have a component which share some common utilities between HTTP client and server applications. |
Hi, The "suggestion code" from @jaghatei seems very interesting to me. Why hasn't it been implemented yet ? There are some problems too. Don't forget to consider authentication for websocket(WS) and websocket secure(WSS) too. I opened a feature request here: Thank's. |
Hi, Could someone suggest the best way to store users and passwords in flash memory ? Fat Fs ? Thank's. |
@jaghatei Thanks for your contribution, but I suggest handle it by application itself. |
This pull provides http authentication to the esp_http_server.
Function for basic auth is included. Other auth functions can be provided by user.
Normal URI handler will only be called in case authentication is disabled or a valid user id is found and authorized.
Authentication is disabled if: AuthType HTTP_AUTH_NONE or UserPassFn == NULL.
AuthType HTTP_AUTH_BASIC uses internal auth function.
AuthType HTTP_AUTH_USER uses user provided function if reference is provided in field UserAuthFn.
Configuration is handled via uri config:
static const httpd_uri_t favicon = {
.uri = "/favicon.ico",
.method = HTTP_GET,
.handler = favicon_get_handler,
.user_ctx = NULL,
.UserPassFn = myPassFn,
.UserAuthFn = NULL,
.AuthType = HTTP_AUTH_BASIC,
.auth_realm = "yourhttprealm"
};
handler function can check result of authentication in req->auth_user_id.
-1: auth disabled
values > = 0: id of authenticated user
Results -2 ( no auth provided by client) and -3 (no user authenticated) of internal basic auth will close request and not call handler function.
Your own UserAuthFn may react different here but needs to provide return values >=-1 then.