Sming icon indicating copy to clipboard operation
Sming copied to clipboard

Example with HttpRequestAuth

Open icodk opened this issue 7 years ago • 8 comments

While upgrading to Sming 3.3.0 my old basic authentication is not supported (ex. using response.authorizationRequired() ) Where can I find en example of how to use it in sming 3.3.0 ?

icodk avatar Oct 04 '17 11:10 icodk

my old basic authentication is not supported

@icodk Are you using basic authentication with HttpClient (to view protected pages) or with HttpServer ( to protect pages ) ?

slaff avatar Oct 11 '17 12:10 slaff

Yes exactly. As I described in #585

icodk avatar Oct 11 '17 12:10 icodk

Yes exactly

Which one - Server or Client?

If you use the client and want to send request to a page protected with basic auth you can do something like this

HttpClient client;
// ...
HttpRequest *request = new HttpRequest(URL(UPDATE_URL));
// ...
HttpBasicAuth* authAdapter = new HttpBasicAuth("username","passw0rd");
request->setAuth(authAdapter);
// ...

client.send(request);

slaff avatar Oct 11 '17 12:10 slaff

No,I want to protect a server page.

icodk avatar Oct 11 '17 13:10 icodk

Once version 3.4.0 is released I can think about refactoring the auth adapters to work for both http clients and servers.

slaff avatar Oct 11 '17 13:10 slaff

+1

icodk avatar Oct 11 '17 13:10 icodk

@icodk: i had the same problem with response.badRequest() I solved it by setting response.code = HTTP_STATUS_BAD_REQUEST as described for forbidden and notFound in HttpResponse.h You sould be fine by replacing "response.authorizationRequired()" by response.code = HTTP_STATUS_UNAUTHORIZED

jochenjagers avatar Oct 21 '17 21:10 jochenjagers

@jochenjagers Thanks Will try it out

icodk avatar Oct 22 '17 11:10 icodk