mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
feature: enabled authentication
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "webfuse/provider/impl/client_config.h"
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
#include "webfuse/provider/impl/credentials.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/message.h"
|
||||
#include "webfuse/core/message_queue.h"
|
||||
@@ -67,14 +68,14 @@ static void wfp_impl_client_protocol_process(
|
||||
}
|
||||
|
||||
static void
|
||||
wfp_impl_client_protocol_on_authenticate_finished(
|
||||
wfp_impl_client_protocol_on_add_filesystem_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * WF_UNUSED_PARAM(error))
|
||||
{
|
||||
struct wfp_client_protocol * protocol = user_data;
|
||||
if (NULL == protocol->wsi) { return; }
|
||||
|
||||
|
||||
if (NULL != result)
|
||||
{
|
||||
protocol->is_connected = true;
|
||||
@@ -92,13 +93,69 @@ static void wfp_impl_client_protocol_add_filesystem(
|
||||
{
|
||||
jsonrpc_proxy_invoke(
|
||||
protocol->proxy,
|
||||
&wfp_impl_client_protocol_on_authenticate_finished,
|
||||
&wfp_impl_client_protocol_on_add_filesystem_finished,
|
||||
protocol,
|
||||
"add_filesystem",
|
||||
"s",
|
||||
"cprovider");
|
||||
}
|
||||
|
||||
static void
|
||||
wfp_impl_client_protocol_on_authenticate_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * WF_UNUSED_PARAM(error))
|
||||
{
|
||||
struct wfp_client_protocol * protocol = user_data;
|
||||
if (NULL == protocol->wsi) { return; }
|
||||
|
||||
if (NULL != result)
|
||||
{
|
||||
wfp_impl_client_protocol_add_filesystem(protocol);
|
||||
}
|
||||
else
|
||||
{
|
||||
protocol->is_shutdown_requested = true;
|
||||
lws_callback_on_writable(protocol->wsi);
|
||||
}
|
||||
}
|
||||
|
||||
static void wfp_impl_client_protocol_authenticate(
|
||||
struct wfp_client_protocol * protocol)
|
||||
{
|
||||
struct wfp_credentials credentials;
|
||||
wfp_impl_credentials_init(&credentials);
|
||||
|
||||
protocol->provider.get_credentials(&credentials, protocol->user_data);
|
||||
|
||||
char const * cred_type = wfp_impl_credentials_get_type(&credentials);
|
||||
json_t * creds = wfp_impl_credentials_get(&credentials);
|
||||
json_incref(creds);
|
||||
|
||||
jsonrpc_proxy_invoke(
|
||||
protocol->proxy,
|
||||
&wfp_impl_client_protocol_on_authenticate_finished,
|
||||
protocol,
|
||||
"authenticate",
|
||||
"sj",
|
||||
cred_type, creds);
|
||||
|
||||
wfp_impl_credentials_cleanup(&credentials);
|
||||
}
|
||||
|
||||
static void wfp_impl_client_protocol_handshake(
|
||||
struct wfp_client_protocol * protocol)
|
||||
{
|
||||
if (wfp_impl_provider_is_authentication_enabled(&protocol->provider))
|
||||
{
|
||||
wfp_impl_client_protocol_authenticate(protocol);
|
||||
}
|
||||
else
|
||||
{
|
||||
wfp_impl_client_protocol_add_filesystem(protocol);
|
||||
}
|
||||
}
|
||||
|
||||
static int wfp_impl_client_protocol_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
@@ -117,7 +174,7 @@ static int wfp_impl_client_protocol_callback(
|
||||
switch (reason)
|
||||
{
|
||||
case LWS_CALLBACK_CLIENT_ESTABLISHED:
|
||||
wfp_impl_client_protocol_add_filesystem(protocol);
|
||||
wfp_impl_client_protocol_handshake(protocol);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
|
||||
protocol->is_connected = false;
|
||||
|
||||
@@ -32,3 +32,15 @@ void wfp_impl_credentials_add(
|
||||
{
|
||||
json_object_set_new(credentials->contents, key, json_string(value));
|
||||
}
|
||||
|
||||
char const * wfp_impl_credentials_get_type(
|
||||
struct wfp_credentials * credentials)
|
||||
{
|
||||
return credentials->type;
|
||||
}
|
||||
|
||||
json_t * wfp_impl_credentials_get(
|
||||
struct wfp_credentials * credentials)
|
||||
{
|
||||
return credentials->contents;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,11 @@ extern void wfp_impl_credentials_add(
|
||||
char const * key,
|
||||
char const * value);
|
||||
|
||||
extern char const * wfp_impl_credentials_get_type(
|
||||
struct wfp_credentials * credentials);
|
||||
|
||||
extern json_t * wfp_impl_credentials_get(
|
||||
struct wfp_credentials * credentials);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -126,4 +126,11 @@ void wfp_impl_ontimer_default(
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
||||
}
|
||||
|
||||
bool wfp_impl_provider_is_authentication_enabled(
|
||||
struct wfp_provider * provider)
|
||||
{
|
||||
return (NULL != provider->get_credentials);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
#ifndef WF_PROVIDER_IMPL_PROVIDER_H
|
||||
#define WF_PROVIDER_IMPL_PROVIDER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/provider/client_config.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
@@ -42,6 +47,9 @@ extern void wfp_impl_provider_invoke(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * request);
|
||||
|
||||
extern bool wfp_impl_provider_is_authentication_enabled(
|
||||
struct wfp_provider * provider);
|
||||
|
||||
extern void wfp_impl_connected_default(
|
||||
void * user_data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user